Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@decorator
def deco(call):
try:
attempt_auth(call.request)
except PermissionDenied as e:
return json(status, detail=str(e))
# Check test
if test(call.request.user):
return call()
else:
return json(status, detail=message)
@decorator
def name_all_calls(function):
print('function name:' + function._func.__name__)
return function()
@decorator
def validate(call, form=None):
# request.content_type is new in Django 1.10
if hasattr(call.request, 'content_type'):
content_type = call.request.content_type
else:
content_type, _ = cgi.parse_header(call.request.META.get('CONTENT_TYPE', ''))
# Parse JSON or fallback to urlencoded
if content_type == 'application/json':
try:
data = _json.loads(call.request.body)
except ValueError:
return json(400, detail="Failed parsing JSON")
else:
data = call.request.POST
aform = form(data)
@decorator
def configurable_middleware(call):
prefix = call._func.__name__ + '__'
overwrites = {cut_prefix(name, prefix): value
for name, value in SETTINGS.get().items() if name.startswith(prefix)}
return call(**overwrites)
@decorator
def _wrap_pydrive_retriable(call):
from apiclient import errors
from pydrive.files import ApiRequestError
try:
result = call()
except (ApiRequestError, errors.HttpError) as exception:
retry_codes = ["403", "500", "502", "503", "504"]
if any(
"HttpError {}".format(code) in str(exception)
for code in retry_codes
):
raise GDriveRetriableError(msg="Google API request failed")
raise
return result
@decorator
def without(call, *keys):
"""Return dictionary without the given keys"""
return select_keys(lambda k: k not in keys, call())
@decorator
def ftp_retry(call):
tries = 50
for attempt in range(tries):
try:
try:
return call()
except ftplib.all_errors:
# Connection could be in inconsistent state, close and forget
shared.conn.close()
del shared.conn
raise
except (ftplib.Error, socket.error, EOFError) as e:
if error_persistent(e):
raise
# Reraise error on last attempt
elif attempt + 1 == tries:
@decorator
def cache_in_disk(function):
cache_path = '/.rol/cache/'
# create a name based on the module and function name
name = __name__ + '.' + function._func.__name__
# create a the path name for the file to cache
path = os.path.expanduser("~") + cache_path + name + '.cache'
if os.path.isfile(path):
# if file exists just load it
return dill.load(open(path, "rb"))
else:
# otherwise run function
data = function()
@decorator
def adhoc_session(call):
return with_session(call())
@decorator
def queue_when_in_transaction(call):
if transaction_states[call.using]:
transaction_states[call.using].push((call, (), {}))
else:
return call()