-
Notifications
You must be signed in to change notification settings - Fork 3
/
diagrequests.py
55 lines (48 loc) · 1.33 KB
/
diagrequests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import pprint
import requests
import os
pp = pprint.PrettyPrinter(indent=4)
save = None
def all(mname, args, kargs, verbose=False):
global save
if "JETLAG_DEBUG" in os.environ or verbose:
print()
print("="*50)
print("requests => ",mname,"(*args, **kargs)")
print(" where ")
print("args:")
pp.pprint(args)
print("kargs:")
k = 'Authorization'
h = kargs.get("auth",None)
if h is not None and type(h) == tuple:
kargs["auth"] = (h[0],"[hidden]")
h = kargs.get('headers',None)
if h is not None:
auth = h.get(k, None)
if auth is not None:
h[k] = "[hidden]"
else:
auth = None
pp.pprint(kargs)
if auth is not None:
h[k] = auth
print("="*50)
print()
else:
save = (mname, args, kargs)
def show():
if save is not None:
all(save[0], save[1], save[2], True)
def get(*args,**kargs):
all("get",args,kargs)
return requests.get(*args,**kargs)
def post(*args,**kargs):
all("post",args,kargs)
return requests.post(*args,**kargs)
def delete(*args,**kargs):
all("delete",args,kargs)
return requests.delete(*args,**kargs)
def put(*args,**kargs):
all("put",args,kargs)
return requests.put(*args,**kargs)