Textualize / rich

Rich is a Python library for rich text and beautiful formatting in the terminal.
https://rich.readthedocs.io/en/latest/
MIT License
49.73k stars 1.73k forks source link

[REQUEST] format `requests.structures.CaseInsensitiveDict` #3098

Open nschloe opened 1 year ago

nschloe commented 1 year ago

Rich pretty-prints dictionaries, but not yet requests's requests.structures.CaseInsensitiveDict. Given the ubiquity of the package, perhaps it's worthwhile including it.

MWE:

import requests
from rich import print

res = requests.get("https://google.com/")

print(type(res.headers))
print()
print(res.headers)
<class 'requests.structures.CaseInsensitiveDict'>

{'Date': 'Wed, 23 Aug 2023 16:08:49 GMT', 'Expires': '-1', 'Cache-Control': 'private, 
max-age=0', 'Content-Type': 'text/html; charset=ISO-8859-1', 
'Content-Security-Policy-Report-Only': "object-src 'none';base-uri 'self';script-src 
'nonce-Did538OvR0ktCtCDMziyVw' 'strict-dynamic' 'report-sample' 'unsafe-eval' 
'unsafe-inline' https: http:;report-uri https://csp.withgoogle.com/csp/gws/other-hp", 
'P3P': 'CP="This is not a P3P policy! See g.co/p3phelp for more info."', 
'Content-Encoding': 'gzip', 'Server': 'gws', 'X-XSS-Protection': '0', 
'X-Frame-Options': 'SAMEORIGIN', 'Set-Cookie': 'SOCS=CAAaBgiAmJWnBg; expires=Sat, 
21-Sep-2024 16:08:49 GMT; path=/; domain=.google.com; Secure; SameSite=lax, 
AEC=Ad49MVFl3w4DY94CQi-gf_PVObGt9elybIiZtxypp0YtY72ry6fqk7BabQ; expires=Mon, 
19-Feb-2024 16:08:49 GMT; path=/; domain=.google.com; Secure; HttpOnly; SameSite=lax, 
__Secure-ENID=14.SE=KWbL5XujSea1jqO5SxWtrQ8ehy_TqnwI3oYhaXpykAA_RoguQQvQTvsrorgGd-A5_h
rdqgz4KknqtKyo_9kMFrTmtKY0BMw9tCcPYRAVc9B9dyp8rafr_Wh4KmqpIY3Y0eVuTNxUGi7gaMUv_LZfvmgL
eJacYTmmz80cb4_d-Cc; expires=Sun, 22-Sep-2024 08:27:07 GMT; path=/; 
domain=.google.com; Secure; HttpOnly; SameSite=lax', 'Alt-Svc': 'h3=":443"; 
ma=2592000,h3-29=":443"; ma=2592000', 'Transfer-Encoding': 'chunked'}
github-actions[bot] commented 1 year ago

Thank you for your issue. Give us a little time to review it.

PS. You might want to check the FAQ if you haven't done so already.

This is an automated reply, generated by FAQtory

willmcgugan commented 1 year ago

It would probably be easier to add a __rich_repr__ method to the object in requests.

This might give nicer output:

print(dict(res.headers))