35 lines
847 B
Python
Executable File
35 lines
847 B
Python
Executable File
import textwrap
|
|
import random
|
|
import string
|
|
|
|
|
|
def print_roundtrip(response, *args, **kwargs):
|
|
def format_headers(d): return '\n'.join(f'{k}: {v}' for k, v in d.items())
|
|
print(textwrap.dedent('''
|
|
---------------- request ----------------
|
|
{req.method} {req.url}
|
|
{reqhdrs}
|
|
|
|
{req.body}
|
|
---------------- response ----------------
|
|
{res.status_code} {res.reason} {res.url}
|
|
{reshdrs}
|
|
|
|
{res.text}
|
|
''').format(
|
|
req=response.request,
|
|
res=response,
|
|
reqhdrs=format_headers(response.request.headers),
|
|
reshdrs=format_headers(response.headers),
|
|
))
|
|
|
|
|
|
def ranstr(num):
|
|
salt = ''.join(random.sample(string.ascii_lowercase + string.digits, num))
|
|
return salt
|
|
|
|
|
|
def rannum(num):
|
|
salt = ''.join(random.sample(string.digits, num))
|
|
return salt
|