1
0
mirror of https://github.com/django/django.git synced 2025-10-30 09:06:13 +00:00

Fixed #18013 -- Use the new 'as' syntax for exceptions.

Thanks Clueless for the initial patch.
Note that unittest has been purposely left out (external package only used by Python 2.6).
This commit is contained in:
Claude Paroz
2012-04-28 18:09:37 +02:00
parent eefb00f301
commit 3904b74a3f
107 changed files with 306 additions and 354 deletions

View File

@@ -265,7 +265,7 @@ class Parser(object):
self.invalid_block_tag(token, command, parse_until)
try:
compiled_result = compile_func(self, token)
except TemplateSyntaxError, e:
except TemplateSyntaxError as e:
if not self.compile_function_error(token, e):
raise
self.extend_nodelist(nodelist, compiled_result, token)
@@ -774,7 +774,7 @@ class Variable(object):
# GOTCHA: This will also catch any TypeError
# raised in the function itself.
current = settings.TEMPLATE_STRING_IF_INVALID # invalid method call
except Exception, e:
except Exception as e:
if getattr(e, 'silent_variable_failure', False):
current = settings.TEMPLATE_STRING_IF_INVALID
else:
@@ -1237,7 +1237,7 @@ def import_library(taglib_module):
"""
try:
mod = import_module(taglib_module)
except ImportError, e:
except ImportError as e:
# If the ImportError is because the taglib submodule does not exist,
# that's not an error that should be raised. If the submodule exists
# and raised an ImportError on the attempt to load it, that we want

View File

@@ -150,7 +150,7 @@ def get_standard_processors():
module, attr = path[:i], path[i+1:]
try:
mod = import_module(module)
except ImportError, e:
except ImportError as e:
raise ImproperlyConfigured('Error importing request processor module %s: "%s"' % (module, e))
try:
func = getattr(mod, attr)

View File

@@ -72,7 +72,7 @@ class DebugNodeList(NodeList):
def render_node(self, node, context):
try:
return node.render(context)
except Exception, e:
except Exception as e:
if not hasattr(e, 'django_template_source'):
e.django_template_source = node.source
raise
@@ -87,7 +87,7 @@ class DebugVariableNode(VariableNode):
output = force_unicode(output)
except UnicodeDecodeError:
return ''
except Exception, e:
except Exception as e:
if not hasattr(e, 'django_template_source'):
e.django_template_source = self.source
raise

View File

@@ -892,5 +892,5 @@ def pprint(value):
"""A wrapper around pprint.pprint -- for debugging, really."""
try:
return pformat(value)
except Exception, e:
except Exception as e:
return u"Error in formatting: %s" % force_unicode(e, errors="replace")

View File

@@ -183,7 +183,7 @@ class ForNode(Node):
for node in self.nodelist_loop:
try:
nodelist.append(node.render(context))
except Exception, e:
except Exception as e:
if not hasattr(e, 'django_template_source'):
e.django_template_source = node.source
raise
@@ -337,7 +337,7 @@ class SsiNode(Node):
try:
t = Template(output, name=filepath)
return t.render(context)
except TemplateSyntaxError, e:
except TemplateSyntaxError as e:
if settings.DEBUG:
return "[Included template had syntax error: %s]" % e
else:
@@ -403,7 +403,7 @@ class URLNode(Node):
url = ''
try:
url = reverse(view_name, args=args, kwargs=kwargs, current_app=context.current_app)
except NoReverseMatch, e:
except NoReverseMatch as e:
if settings.SETTINGS_MODULE:
project_name = settings.SETTINGS_MODULE.split('.')[0]
try:
@@ -1005,7 +1005,7 @@ def load(parser, token):
try:
taglib = bits[-1]
lib = get_library(taglib)
except InvalidTemplateLibrary, e:
except InvalidTemplateLibrary as e:
raise TemplateSyntaxError("'%s' is not a valid tag library: %s" %
(taglib, e))
else:
@@ -1028,7 +1028,7 @@ def load(parser, token):
try:
lib = get_library(taglib)
parser.add_library(lib)
except InvalidTemplateLibrary, e:
except InvalidTemplateLibrary as e:
raise TemplateSyntaxError("'%s' is not a valid tag library: %s" %
(taglib, e))
return LoadNode()

View File

@@ -93,11 +93,11 @@ def find_template_loader(loader):
module, attr = loader.rsplit('.', 1)
try:
mod = import_module(module)
except ImportError, e:
except ImportError as e:
raise ImproperlyConfigured('Error importing template source loader %s: "%s"' % (loader, e))
try:
TemplateLoader = getattr(mod, attr)
except AttributeError, e:
except AttributeError as e:
raise ImproperlyConfigured('Error importing template source loader %s: "%s"' % (loader, e))
if hasattr(TemplateLoader, 'load_template_source'):
@@ -185,7 +185,7 @@ def select_template(template_name_list):
for template_name in template_name_list:
try:
return get_template(template_name)
except TemplateDoesNotExist, e:
except TemplateDoesNotExist as e:
if e.args[0] not in not_found:
not_found.append(e.args[0])
continue

View File

@@ -19,7 +19,7 @@ app_template_dirs = []
for app in settings.INSTALLED_APPS:
try:
mod = import_module(app)
except ImportError, e:
except ImportError as e:
raise ImproperlyConfigured('ImportError %s: %s' % (app, e.args[0]))
template_dir = os.path.join(os.path.dirname(mod.__file__), 'templates')
if os.path.isdir(template_dir):