-
Notifications
You must be signed in to change notification settings - Fork 2
/
utils.py
35 lines (33 loc) · 1.21 KB
/
utils.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
from functools import wraps
from requests.exceptions import ConnectionError, InvalidSchema
import re, SteamExceptions, time
def ignoreConnectionErrors(*fun,**opts):
def wrapper_decorator(f):
@wraps(f)
def wrapper(*args,**kwargs):
while True:
try:
f(*args,**kwargs)
break
except ConnectionError as e:
if opts.get('echo',False):
print e
time.sleep(1)
return wrapper
if len(fun) == 1:
if callable(fun[0]):
return wrapper_decorator(fun[0])
else:
raise TypeError("argument 1 to @ignoreConnectionErrors has to be callable")
if fun:
raise TypeError("@ignoreConnectionErrors takes 1 argument, {0} given".format(sum([len(fun),len(opts)])))
return wrapper_decorator
def raiseLostAuth(f):
@wraps(f)
def lost_auth_wrapper(*args,**kwargs):
try:
f(args,**kwargs)
except InvalidSchema as e:
if re.search(r'steammobile://lostauth',e.message) is not None:
raise SteamExceptions.LostAuthException("Login was lost, relog again")
return lost_auth_wrapper