(request: http.Request)
| 44 | |
| 45 | |
| 46 | def request_content_for_console(request: http.Request) -> str: |
| 47 | try: |
| 48 | text = request.get_text(strict=True) |
| 49 | assert text |
| 50 | except ValueError: |
| 51 | # shlex.quote doesn't support a bytes object |
| 52 | # see https://github.com/python/cpython/pull/10871 |
| 53 | raise exceptions.CommandError("Request content must be valid unicode") |
| 54 | escape_control_chars = {chr(i): f"\\x{i:02x}" for i in range(32)} |
| 55 | escaped_text = "".join(escape_control_chars.get(x, x) for x in text) |
| 56 | if any(char in escape_control_chars for char in text): |
| 57 | # Escaped chars need to be unescaped by the shell to be properly inperpreted by curl and httpie |
| 58 | return f'"$(printf {shlex.quote(escaped_text)})"' |
| 59 | |
| 60 | return shlex.quote(escaped_text) |
| 61 | |
| 62 | |
| 63 | def curl_command(f: flow.Flow) -> str: |
no test coverage detected
searching dependent graphs…