From 3904b74a3f2f92fefe1d39281ed683c52f2fef03 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Sat, 28 Apr 2012 18:09:37 +0200 Subject: 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). --- django/forms/fields.py | 4 ++-- django/forms/forms.py | 4 ++-- django/forms/formsets.py | 2 +- django/forms/models.py | 6 +++--- django/forms/util.py | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) (limited to 'django/forms') diff --git a/django/forms/fields.py b/django/forms/fields.py index 3cf730e152..39f8f9c846 100644 --- a/django/forms/fields.py +++ b/django/forms/fields.py @@ -132,7 +132,7 @@ class Field(object): for v in self.validators: try: v(value) - except ValidationError, e: + except ValidationError as e: if hasattr(e, 'code') and e.code in self.error_messages: message = self.error_messages[e.code] if e.params: @@ -884,7 +884,7 @@ class MultiValueField(Field): raise ValidationError(self.error_messages['required']) try: clean_data.append(field.clean(field_value)) - except ValidationError, e: + except ValidationError as e: # Collect all validation errors in a single list, which we'll # raise at the end of clean(), rather than raising a single # exception for the first error we encounter. diff --git a/django/forms/forms.py b/django/forms/forms.py index 94eb22dd9e..09663d173c 100644 --- a/django/forms/forms.py +++ b/django/forms/forms.py @@ -289,7 +289,7 @@ class BaseForm(StrAndUnicode): if hasattr(self, 'clean_%s' % name): value = getattr(self, 'clean_%s' % name)() self.cleaned_data[name] = value - except ValidationError, e: + except ValidationError as e: self._errors[name] = self.error_class(e.messages) if name in self.cleaned_data: del self.cleaned_data[name] @@ -297,7 +297,7 @@ class BaseForm(StrAndUnicode): def _clean_form(self): try: self.cleaned_data = self.clean() - except ValidationError, e: + except ValidationError as e: self._errors[NON_FIELD_ERRORS] = self.error_class(e.messages) def _post_clean(self): diff --git a/django/forms/formsets.py b/django/forms/formsets.py index dcd2f017e7..739a9d44e3 100644 --- a/django/forms/formsets.py +++ b/django/forms/formsets.py @@ -291,7 +291,7 @@ class BaseFormSet(StrAndUnicode): # Give self.clean() a chance to do cross-form validation. try: self.clean() - except ValidationError, e: + except ValidationError as e: self._non_form_errors = self.error_class(e.messages) def clean(self): diff --git a/django/forms/models.py b/django/forms/models.py index cd8f027070..ea80f8d855 100644 --- a/django/forms/models.py +++ b/django/forms/models.py @@ -324,13 +324,13 @@ class BaseModelForm(BaseForm): # Clean the model instance's fields. try: self.instance.clean_fields(exclude=exclude) - except ValidationError, e: + except ValidationError as e: self._update_errors(e.message_dict) # Call the model instance's clean method. try: self.instance.clean() - except ValidationError, e: + except ValidationError as e: self._update_errors({NON_FIELD_ERRORS: e.messages}) # Validate uniqueness if needed. @@ -345,7 +345,7 @@ class BaseModelForm(BaseForm): exclude = self._get_validation_exclusions() try: self.instance.validate_unique(exclude=exclude) - except ValidationError, e: + except ValidationError as e: self._update_errors(e.message_dict) def save(self, commit=True): diff --git a/django/forms/util.py b/django/forms/util.py index 886f08e581..6690442534 100644 --- a/django/forms/util.py +++ b/django/forms/util.py @@ -66,7 +66,7 @@ def from_current_timezone(value): current_timezone = timezone.get_current_timezone() try: return timezone.make_aware(value, current_timezone) - except Exception, e: + except Exception: raise ValidationError(_('%(datetime)s couldn\'t be interpreted ' 'in time zone %(current_timezone)s; it ' 'may be ambiguous or it may not exist.') -- cgit v1.3