def render(self, resp: requests.models.Response) -> Textarea: "Return a somewhat prettified JSON string." obj = resp.json() self.data = obj layout = Layout(width='100%', height='100%') ta = Textarea(layout=layout) value = json.dumps(obj, indent=2) ta.value = value num_lines = value.count('\n') ta.rows = min(10, num_lines + 1) return ta
def render(self, resp: requests.models.Response) -> Optional[Widget]: "Return some rendered raw 'view' of the response or None." obj = resp.content self.data = obj layout = Layout(width='100%', height='100%') ta = Textarea(layout=layout) try: ta.value = str(resp.content.decode(resp.encoding)) \ if resp.encoding else str(resp.content) except UnicodeDecodeError: ta.value = str(resp.content) num_lines = ta.value.count('\n') ta.rows = min(10, num_lines + 1) return ta