Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.type = urltype
name = name.replace('-', '_')
if not hasattr(self, name):
if proxy:
return self.open_unknown_proxy(proxy, fullurl, data)
else:
return self.open_unknown(fullurl, data)
try:
if data is None:
return getattr(self, name)(url)
else:
return getattr(self, name)(url, data)
except HTTPError:
raise
except socket.error as msg:
raise_with_traceback(IOError('socket error', msg))
failed function call once more.
"""
if not self._Duct__connected:
self.connect()
try:
return f(self, *args, **kwargs)
except Exception as e:
# Check to see if it is possible that we failed due to connection issues.
# If so, try again once more. If we fail again, raise.
# TODO: Explore adding a DuctConnectionError class and filter this
# handling to errors of that class.
if not self.is_connected():
self.connect()
return f(self, *args, **kwargs)
raise_with_traceback(e)
start_key, end_key, shard, nshards, callback_on_progress
)
except Exception as e:
first_exception = e
log.exception("Failed to clean directories.")
try:
self._clean_expired_metrics(
max_age, start_key, end_key, shard, nshards, callback_on_progress
)
except Exception as e:
first_exception = e
log.exception("Failed to clean metrics.")
if first_exception is not None:
raise_with_traceback(first_exception)
def str_param(obj, param_name):
if not _is_str(obj):
raise_with_traceback(_param_type_mismatch_exception(obj, str, param_name))
return obj
def inner(*args, **kwargs):
"""Wraps specified exceptions"""
try:
return a_func(*args, **kwargs)
# pylint: disable=catching-non-exception
except tuple(to_catch) as exception:
utils.raise_with_traceback(
gax.errors.create_error('RPC failed', cause=exception))
for attr in attrs:
attr, value = splitvalue(attr)
if attr.lower() == 'type' and \
value in ('a', 'A', 'i', 'I', 'd', 'D'):
type = value.upper()
(fp, retrlen) = self.ftpcache[key].retrfile(file, type)
mtype = mimetypes.guess_type("ftp:" + url)[0]
headers = ""
if mtype:
headers += "Content-Type: %s\n" % mtype
if retrlen is not None and retrlen >= 0:
headers += "Content-Length: %d\n" % retrlen
headers = email.message_from_string(headers)
return addinfourl(fp, headers, "ftp:" + url)
except ftperrors() as exp:
raise_with_traceback(URLError('ftp error %r' % exp))
while True:
try:
return fun(*args, **kwargs)
except Exception as exn: # pylint: disable=broad-except
if not retry_filter(exn):
raise
# Get the traceback object for the current exception. The
# sys.exc_info() function returns a tuple with three elements:
# exception type, exception value, and exception traceback.
exn_traceback = sys.exc_info()[2]
try:
try:
sleep_interval = next(retry_intervals)
except StopIteration:
# Re-raise the original exception since we finished the retries.
raise_with_traceback(exn, exn_traceback)
logger(
'Retry with exponential backoff: waiting for %s seconds before '
'retrying %s because we caught exception: %s '
'Traceback for above exception (most recent call last):\n%s',
sleep_interval,
getattr(fun, '__name__', str(fun)),
''.join(traceback.format_exception_only(exn.__class__, exn)),
''.join(traceback.format_tb(exn_traceback)))
clock.sleep(sleep_interval)
finally:
# Traceback objects in locals can cause reference cycles that will
# prevent garbage collection. Clear it now since we do not need
# it anymore.
exn_traceback = None
def validate_response(response):
"""
Handle the received response to make sure that we
will only process valid requests.
"""
content = response.content
if response.status_code == 409:
raise_with_traceback(ProxyExists(content))
elif response.status_code == 404:
raise_with_traceback(NotFound(content))
elif response.status_code == 400:
raise_with_traceback(InvalidToxic(content))
return response
longitude = json_value[0]
latitude = json_value[1]
try:
geopoints = [decimal.Decimal(longitude),
decimal.Decimal(latitude)]
self._check_latitude_longtiude_range(geopoints)
return geopoints
except decimal.DecimalException as e:
raise_with_traceback(exceptions.InvalidGeoPointType(e))
else:
raise exceptions.InvalidGeoPointType(
'{0}: point is not of length 2'.format(value)
)
except (TypeError, ValueError) as e:
raise_with_traceback(exceptions.InvalidGeoPointType(e))
def opt_numeric_param(obj, param_name):
if obj is not None and not isinstance(obj, (int, float)):
raise_with_traceback(_param_type_mismatch_exception(obj, (int, float), param_name))
return obj