mirror of
https://github.com/ansible/awx.git
synced 2026-01-12 18:40:01 -03:30
Converted except T,e expressions to except T as e
This commit is contained in:
parent
7839db0c23
commit
b57739a800
@ -58,7 +58,7 @@ class TypeFilterBackend(BaseFilterBackend):
|
||||
else:
|
||||
queryset = queryset.none()
|
||||
return queryset
|
||||
except FieldError, e:
|
||||
except FieldError as e:
|
||||
# Return a 400 for invalid field names.
|
||||
raise ParseError(*e.args)
|
||||
|
||||
@ -139,7 +139,7 @@ class FieldLookupBackend(BaseFilterBackend):
|
||||
elif new_lookup.endswith('__regex') or new_lookup.endswith('__iregex'):
|
||||
try:
|
||||
re.compile(value)
|
||||
except re.error, e:
|
||||
except re.error as e:
|
||||
raise ValueError(e.args[0])
|
||||
else:
|
||||
value = self.value_to_python_for_field(field, value)
|
||||
@ -221,9 +221,9 @@ class FieldLookupBackend(BaseFilterBackend):
|
||||
queryset = queryset.filter(q)
|
||||
queryset = queryset.filter(*args).distinct()
|
||||
return queryset
|
||||
except (FieldError, FieldDoesNotExist, ValueError), e:
|
||||
except (FieldError, FieldDoesNotExist, ValueError) as e:
|
||||
raise ParseError(e.args[0])
|
||||
except ValidationError, e:
|
||||
except ValidationError as e:
|
||||
raise ParseError(e.messages)
|
||||
|
||||
class OrderByBackend(BaseFilterBackend):
|
||||
@ -261,6 +261,6 @@ class OrderByBackend(BaseFilterBackend):
|
||||
new_order_by.append(field)
|
||||
queryset = queryset.order_by(*new_order_by)
|
||||
return queryset
|
||||
except FieldError, e:
|
||||
except FieldError as e:
|
||||
# Return a 400 for invalid field names.
|
||||
raise ParseError(*e.args)
|
||||
|
||||
@ -127,7 +127,7 @@ class ModelAccessPermission(permissions.BasePermission):
|
||||
view.__class__.__name__, obj)
|
||||
try:
|
||||
response = self.check_permissions(request, view, obj)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
logger.debug('has_permission raised %r', e, exc_info=True)
|
||||
raise
|
||||
else:
|
||||
|
||||
@ -277,7 +277,7 @@ class ApiV1ConfigView(APIView):
|
||||
for fname in (TEMPORARY_TASK_FILE, TASK_FILE):
|
||||
try:
|
||||
os.remove(fname)
|
||||
except OSError, e:
|
||||
except OSError as e:
|
||||
if e.errno != errno.ENOENT:
|
||||
has_error = e.errno
|
||||
break
|
||||
@ -3449,7 +3449,7 @@ class UnifiedJobStdout(RetrieveAPIView):
|
||||
response = HttpResponse(FileWrapper(content_fd), content_type='text/plain')
|
||||
response["Content-Disposition"] = 'attachment; filename="job_%s.txt"' % str(unified_job.id)
|
||||
return response
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
return Response({"error": "Error generating stdout download file: %s" % str(e)}, status=status.HTTP_400_BAD_REQUEST)
|
||||
elif request.accepted_renderer.format == 'txt':
|
||||
return Response(unified_job.result_stdout)
|
||||
|
||||
@ -78,7 +78,7 @@ class MemObject(object):
|
||||
v = yaml.safe_load(file(path, 'r').read())
|
||||
if hasattr(v, 'items'): # is a dict
|
||||
all_vars.update(v)
|
||||
except yaml.YAMLError, e:
|
||||
except yaml.YAMLError as e:
|
||||
if hasattr(e, 'problem_mark'):
|
||||
logger.error('Invalid YAML in %s:%s col %s', path,
|
||||
e.problem_mark.line + 1,
|
||||
@ -1329,7 +1329,7 @@ class Command(NoArgsCommand):
|
||||
self.logger.warning('Inventory import required %d queries '
|
||||
'taking %0.3fs', len(queries_this_import),
|
||||
sqltime)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
if isinstance(e, KeyboardInterrupt):
|
||||
status = 'canceled'
|
||||
exc = e
|
||||
|
||||
@ -173,7 +173,7 @@ class CallbackReceiver(object):
|
||||
# If for any reason there's a problem, just use 0.
|
||||
try:
|
||||
verbose = Job.objects.get(id=data['job_id']).verbosity
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
verbose = 0
|
||||
|
||||
# Convert the datetime for the job event's creation appropriately,
|
||||
@ -191,7 +191,7 @@ class CallbackReceiver(object):
|
||||
|
||||
# Print the data to stdout if we're in DEBUG mode.
|
||||
if settings.DEBUG:
|
||||
print data
|
||||
print(data)
|
||||
|
||||
# Sanity check: Don't honor keys that we don't recognize.
|
||||
for key in data.keys():
|
||||
@ -234,7 +234,7 @@ class CallbackReceiver(object):
|
||||
# If for any reason there's a problem, just use 0.
|
||||
try:
|
||||
verbose = AdHocCommand.objects.get(id=data['ad_hoc_command_id']).verbosity
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
verbose = 0
|
||||
|
||||
# Convert the datetime for the job event's creation appropriately,
|
||||
@ -252,7 +252,7 @@ class CallbackReceiver(object):
|
||||
|
||||
# Print the data to stdout if we're in DEBUG mode.
|
||||
if settings.DEBUG:
|
||||
print data
|
||||
print(data)
|
||||
|
||||
# Sanity check: Don't honor keys that we don't recognize.
|
||||
for key in data.keys():
|
||||
@ -288,7 +288,7 @@ class CallbackReceiver(object):
|
||||
message = queue_actual.get(block=True, timeout=1)
|
||||
except QueueEmpty:
|
||||
continue
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
logger.error("Exception on listen socket, restarting: " + str(e))
|
||||
break
|
||||
self.process_job_event(message)
|
||||
|
||||
@ -59,7 +59,7 @@ class FactCacheReceiver(object):
|
||||
except Fact.MultipleObjectsReturned:
|
||||
logger.warn('Database inconsistent. Multiple Hosts found for <hostname, inventory_id> <%s, %s>.' % (hostname, inventory_id))
|
||||
return None
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
logger.error("Exception communicating with Fact Cache Database: %s" % str(e))
|
||||
return None
|
||||
|
||||
|
||||
@ -96,7 +96,7 @@ class SocketController(object):
|
||||
if socket_session and socket_session.is_valid():
|
||||
try:
|
||||
socket.send_packet(packet)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
logger.error("Error sending client packet to %s: %s" % (str(session_id), str(packet)))
|
||||
logger.error("Error was: " + str(e))
|
||||
|
||||
@ -116,7 +116,7 @@ class SocketController(object):
|
||||
if socket:
|
||||
try:
|
||||
socket.send_packet(packet)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
logger.error("Error sending client packet to %s: %s" % (str(socket_session.session_id), str(packet)))
|
||||
logger.error("Error was: " + str(e))
|
||||
|
||||
@ -129,18 +129,18 @@ socketController = SocketController(SocketSessionManager())
|
||||
#
|
||||
# Socket session is attached to self.session['socket_session']
|
||||
# self.session and self.socket.session point to the same dict
|
||||
#
|
||||
#
|
||||
class TowerBaseNamespace(BaseNamespace):
|
||||
|
||||
def get_allowed_methods(self):
|
||||
return ['recv_disconnect']
|
||||
|
||||
|
||||
def get_initial_acl(self):
|
||||
request_token = self._get_request_token()
|
||||
if request_token:
|
||||
# (1) This is the first time the socket has been seen (first
|
||||
# (1) This is the first time the socket has been seen (first
|
||||
# namespace joined).
|
||||
# (2) This socket has already been seen (already joined and maybe
|
||||
# (2) This socket has already been seen (already joined and maybe
|
||||
# left a namespace)
|
||||
#
|
||||
# Note: Assume that the user token is valid if the session is found
|
||||
@ -168,7 +168,7 @@ class TowerBaseNamespace(BaseNamespace):
|
||||
if k == "Token":
|
||||
token_actual = urllib.unquote_plus(v).decode().replace("\"","")
|
||||
return token_actual
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
logger.error("Exception validating user: " + str(e))
|
||||
return False
|
||||
return False
|
||||
|
||||
@ -137,7 +137,7 @@ class BaseModel(models.Model):
|
||||
errors = {}
|
||||
try:
|
||||
super(BaseModel, self).clean_fields(exclude)
|
||||
except ValidationError, e:
|
||||
except ValidationError as e:
|
||||
errors = e.update_error_dict(errors)
|
||||
for f in self._meta.fields:
|
||||
if f.name in exclude:
|
||||
@ -145,7 +145,7 @@ class BaseModel(models.Model):
|
||||
if hasattr(self, 'clean_%s' % f.name):
|
||||
try:
|
||||
setattr(self, f.name, getattr(self, 'clean_%s' % f.name)())
|
||||
except ValidationError, e:
|
||||
except ValidationError as e:
|
||||
errors[f.name] = e.messages
|
||||
if errors:
|
||||
raise ValidationError(errors)
|
||||
|
||||
@ -701,7 +701,7 @@ class Job(UnifiedJob, JobOptions):
|
||||
return
|
||||
try:
|
||||
extra_vars = json.loads(extra_data)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
logger.warn("Exception deserializing extra vars: " + str(e))
|
||||
evars = self.extra_vars_dict
|
||||
evars.update(extra_vars)
|
||||
@ -1316,7 +1316,7 @@ class SystemJob(UnifiedJob, SystemJobOptions):
|
||||
return
|
||||
try:
|
||||
extra_vars = json.loads(extra_data)
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
logger.warn("Exception deserializing extra vars: " + str(e))
|
||||
evars = self.extra_vars_dict
|
||||
evars.update(extra_vars)
|
||||
|
||||
@ -115,7 +115,7 @@ class ProjectOptions(models.Model):
|
||||
try:
|
||||
scm_url = update_scm_url(self.scm_type, scm_url,
|
||||
check_special_cases=False)
|
||||
except ValueError, e:
|
||||
except ValueError as e:
|
||||
raise ValidationError((e.args or ('Invalid SCM URL.',))[0])
|
||||
scm_url_parts = urlparse.urlsplit(scm_url)
|
||||
if self.scm_type and not any(scm_url_parts):
|
||||
@ -142,7 +142,7 @@ class ProjectOptions(models.Model):
|
||||
try:
|
||||
update_scm_url(self.scm_type, self.scm_url, scm_username,
|
||||
scm_password)
|
||||
except ValueError, e:
|
||||
except ValueError as e:
|
||||
raise ValidationError((e.args or ('Invalid credential.',))[0])
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
@ -77,7 +77,7 @@ def celery_startup(conf=None, **kwargs):
|
||||
try:
|
||||
sch.update_computed_fields()
|
||||
sch.save()
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
logger.error("Failed to rebuild schedule {}: {}".format(sch, e))
|
||||
|
||||
@task()
|
||||
@ -1722,7 +1722,7 @@ class RunSystemJob(BaseTask):
|
||||
args.extend(['--older_than', str(json_vars['older_than'])])
|
||||
if 'granularity' in json_vars:
|
||||
args.extend(['--granularity', str(json_vars['granularity'])])
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
logger.error("Failed to parse system job: " + str(e))
|
||||
return args
|
||||
|
||||
|
||||
@ -1058,7 +1058,7 @@ class JobTransactionTest(BaseJobTestMixin, django.test.LiveServerTestCase):
|
||||
data = json.loads(response.content)
|
||||
if data.get('status', '') not in ('new', 'pending', 'running'):
|
||||
break
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
errors.append(e)
|
||||
break
|
||||
|
||||
|
||||
@ -44,9 +44,9 @@ def get_object_or_400(klass, *args, **kwargs):
|
||||
queryset = _get_queryset(klass)
|
||||
try:
|
||||
return queryset.get(*args, **kwargs)
|
||||
except queryset.model.DoesNotExist, e:
|
||||
except queryset.model.DoesNotExist as e:
|
||||
raise ParseError(*e.args)
|
||||
except queryset.model.MultipleObjectsReturned, e:
|
||||
except queryset.model.MultipleObjectsReturned as e:
|
||||
raise ParseError(*e.args)
|
||||
|
||||
|
||||
@ -59,9 +59,9 @@ def get_object_or_403(klass, *args, **kwargs):
|
||||
queryset = _get_queryset(klass)
|
||||
try:
|
||||
return queryset.get(*args, **kwargs)
|
||||
except queryset.model.DoesNotExist, e:
|
||||
except queryset.model.DoesNotExist as e:
|
||||
raise PermissionDenied(*e.args)
|
||||
except queryset.model.MultipleObjectsReturned, e:
|
||||
except queryset.model.MultipleObjectsReturned as e:
|
||||
raise PermissionDenied(*e.args)
|
||||
|
||||
def to_python_boolean(value, allow_none=False):
|
||||
|
||||
@ -127,7 +127,7 @@ except IOError:
|
||||
try:
|
||||
e = None
|
||||
open(settings_file)
|
||||
except IOError, e:
|
||||
except IOError as e:
|
||||
pass
|
||||
if e and e.errno == errno.EACCES:
|
||||
SECRET_KEY = 'permission-denied'
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user