(response: Response)
| 168 | |
| 169 | |
| 170 | def print_response(response: Response) -> None: |
| 171 | console = rich.console.Console() |
| 172 | lexer_name = get_lexer_for_response(response) |
| 173 | if lexer_name: |
| 174 | if lexer_name.lower() == "json": |
| 175 | try: |
| 176 | data = response.json() |
| 177 | text = json.dumps(data, indent=4) |
| 178 | except ValueError: # pragma: no cover |
| 179 | text = response.text |
| 180 | else: |
| 181 | text = response.text |
| 182 | |
| 183 | syntax = rich.syntax.Syntax(text, lexer_name, theme="ansi_dark", word_wrap=True) |
| 184 | console.print(syntax) |
| 185 | else: |
| 186 | console.print(f"<{len(response.content)} bytes of binary data>") |
| 187 | |
| 188 | |
| 189 | _PCTRTT = typing.Tuple[typing.Tuple[str, str], ...] |
no test coverage detected