-
diff --git a/django/conf/__init__.py b/django/conf/__init__.py
index a3f7ee0..8439f0f 100644
a
|
b
|
class Settings(BaseSettings):
|
91 | 91 | |
92 | 92 | try: |
93 | 93 | mod = importlib.import_module(self.SETTINGS_MODULE) |
94 | | except ImportError, e: |
| 94 | except ImportError as e: |
95 | 95 | raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e)) |
96 | 96 | |
97 | 97 | # Settings that should be converted into tuples if they're mistakenly entered |
-
diff --git a/django/contrib/admin/tests.py b/django/contrib/admin/tests.py
index 2491fc6..59fa9ba 100644
a
|
b
|
class AdminSeleniumWebDriverTestCase(LiveServerTestCase):
|
18 | 18 | mod = import_module(module) |
19 | 19 | WebDriver = getattr(mod, attr) |
20 | 20 | cls.selenium = WebDriver() |
21 | | except Exception, e: |
| 21 | except Exception as e: |
22 | 22 | raise SkipTest('Selenium webdriver "%s" not installed or not ' |
23 | 23 | 'operational: %s' % (cls.webdriver_class, str(e))) |
24 | 24 | super(AdminSeleniumWebDriverTestCase, cls).setUpClass() |
-
diff --git a/django/contrib/admin/util.py b/django/contrib/admin/util.py
index 61182a6..b1670cb 100644
a
|
b
|
class NestedObjects(Collector):
|
153 | 153 | self.add_edge(None, obj) |
154 | 154 | try: |
155 | 155 | return super(NestedObjects, self).collect(objs, source_attr=source_attr, **kwargs) |
156 | | except models.ProtectedError, e: |
| 156 | except models.ProtectedError as e: |
157 | 157 | self.protected.update(e.protected_objects) |
158 | 158 | |
159 | 159 | def related_objects(self, related, objs): |
-
diff --git a/django/contrib/admin/views/main.py b/django/contrib/admin/views/main.py
index b11f9d5..a250315 100644
a
|
b
|
class ChangeList(object):
|
139 | 139 | use_distinct = (use_distinct or |
140 | 140 | lookup_needs_distinct(self.lookup_opts, key)) |
141 | 141 | return filter_specs, bool(filter_specs), lookup_params, use_distinct |
142 | | except FieldDoesNotExist, e: |
| 142 | except FieldDoesNotExist as e: |
143 | 143 | raise IncorrectLookupParameters(e) |
144 | 144 | |
145 | 145 | def get_query_string(self, new_params=None, remove=None): |
… |
… |
class ChangeList(object):
|
316 | 316 | # Allow certain types of errors to be re-raised as-is so that the |
317 | 317 | # caller can treat them in a special way. |
318 | 318 | raise |
319 | | except Exception, e: |
| 319 | except Exception as e: |
320 | 320 | # Every other error is caught with a naked except, because we don't |
321 | 321 | # have any other way of validating lookup parameters. They might be |
322 | 322 | # invalid if the keyword arguments are incorrect, or if the values |
-
diff --git a/django/contrib/admindocs/views.py b/django/contrib/admindocs/views.py
index 33d9a7d..c3405a7 100644
a
|
b
|
def load_all_installed_template_libraries():
|
318 | 318 | for library_name in libraries: |
319 | 319 | try: |
320 | 320 | lib = template.get_library(library_name) |
321 | | except template.InvalidTemplateLibrary, e: |
| 321 | except template.InvalidTemplateLibrary as e: |
322 | 322 | pass |
323 | 323 | |
324 | 324 | def get_return_data_type(func_name): |
-
diff --git a/django/contrib/auth/__init__.py b/django/contrib/auth/__init__.py
index 3495e16..93fd441 100644
a
|
b
|
def load_backend(path):
|
12 | 12 | module, attr = path[:i], path[i+1:] |
13 | 13 | try: |
14 | 14 | mod = import_module(module) |
15 | | except ImportError, e: |
| 15 | except ImportError as e: |
16 | 16 | raise ImproperlyConfigured('Error importing authentication backend %s: "%s"' % (path, e)) |
17 | | except ValueError, e: |
| 17 | except ValueError as e: |
18 | 18 | raise ImproperlyConfigured('Error importing authentication backends. Is AUTHENTICATION_BACKENDS a correctly defined list or tuple?') |
19 | 19 | try: |
20 | 20 | cls = getattr(mod, attr) |
-
diff --git a/django/contrib/comments/views/comments.py b/django/contrib/comments/views/comments.py
index 5772016..c9a1160 100644
a
|
b
|
def post_comment(request, next=None, using=None):
|
66 | 66 | return CommentPostBadRequest( |
67 | 67 | "No object matching content-type %r and object PK %r exists." % \ |
68 | 68 | (escape(ctype), escape(object_pk))) |
69 | | except (ValueError, ValidationError), e: |
| 69 | except (ValueError, ValidationError) as e: |
70 | 70 | return CommentPostBadRequest( |
71 | 71 | "Attempting go get content-type %r and object PK %r exists raised %s" % \ |
72 | 72 | (escape(ctype), escape(object_pk), e.__class__.__name__)) |
-
diff --git a/django/contrib/formtools/wizard/storage/__init__.py b/django/contrib/formtools/wizard/storage/__init__.py
index b88ccc7..f2293c9 100644
a
|
b
|
def get_storage(path, *args, **kwargs):
|
10 | 10 | module, attr = path[:i], path[i+1:] |
11 | 11 | try: |
12 | 12 | mod = import_module(module) |
13 | | except ImportError, e: |
| 13 | except ImportError as e: |
14 | 14 | raise MissingStorageModule( |
15 | 15 | 'Error loading storage %s: "%s"' % (module, e)) |
16 | 16 | try: |
-
diff --git a/django/contrib/gis/db/backends/base.py b/django/contrib/gis/db/backends/base.py
index c8bb3d2..26e9762 100644
a
|
b
|
class SpatialRefSysMixin(object):
|
164 | 164 | try: |
165 | 165 | self._srs = gdal.SpatialReference(self.wkt) |
166 | 166 | return self.srs |
167 | | except Exception, msg: |
| 167 | except Exception as msg: |
168 | 168 | pass |
169 | 169 | |
170 | 170 | try: |
171 | 171 | self._srs = gdal.SpatialReference(self.proj4text) |
172 | 172 | return self.srs |
173 | | except Exception, msg: |
| 173 | except Exception as msg: |
174 | 174 | pass |
175 | 175 | |
176 | 176 | raise Exception('Could not get OSR SpatialReference from WKT: %s\nError:\n%s' % (self.wkt, msg)) |
-
diff --git a/django/contrib/gis/db/backends/oracle/introspection.py b/django/contrib/gis/db/backends/oracle/introspection.py
index 58dd3f3..716f318 100644
a
|
b
|
class OracleIntrospection(DatabaseIntrospection):
|
16 | 16 | cursor.execute('SELECT "DIMINFO", "SRID" FROM "USER_SDO_GEOM_METADATA" WHERE "TABLE_NAME"=%s AND "COLUMN_NAME"=%s', |
17 | 17 | (table_name.upper(), geo_col.upper())) |
18 | 18 | row = cursor.fetchone() |
19 | | except Exception, msg: |
| 19 | except Exception as msg: |
20 | 20 | raise Exception('Could not find entry in USER_SDO_GEOM_METADATA corresponding to "%s"."%s"\n' |
21 | 21 | 'Error message: %s.' % (table_name, geo_col, msg)) |
22 | 22 | |
-
diff --git a/django/contrib/gis/db/backends/postgis/operations.py b/django/contrib/gis/db/backends/postgis/operations.py
index 3286748..9dcfe4c 100644
a
|
b
|
class PostGISOperations(DatabaseOperations, BaseSpatialOperations):
|
107 | 107 | 'Was the database created from a spatial database ' |
108 | 108 | 'template?' % self.connection.settings_dict['NAME'] |
109 | 109 | ) |
110 | | except Exception, e: |
| 110 | except Exception as e: |
111 | 111 | # TODO: Raise helpful exceptions as they become known. |
112 | 112 | raise |
113 | 113 | |
-
diff --git a/django/contrib/gis/db/backends/spatialite/base.py b/django/contrib/gis/db/backends/spatialite/base.py
index aea52f5..b447d1d 100644
a
|
b
|
class DatabaseWrapper(SQLiteDatabaseWrapper):
|
56 | 56 | cur = self.connection.cursor(factory=SQLiteCursorWrapper) |
57 | 57 | try: |
58 | 58 | cur.execute("SELECT load_extension(%s)", (self.spatialite_lib,)) |
59 | | except Exception, msg: |
| 59 | except Exception as msg: |
60 | 60 | raise ImproperlyConfigured('Unable to load the SpatiaLite library extension ' |
61 | 61 | '"%s" because: %s' % (self.spatialite_lib, msg)) |
62 | 62 | return cur |
-
diff --git a/django/contrib/gis/db/backends/spatialite/operations.py b/django/contrib/gis/db/backends/spatialite/operations.py
index a0efb99..6adcdc5 100644
a
|
b
|
class SpatiaLiteOperations(DatabaseOperations, BaseSpatialOperations):
|
122 | 122 | self.spatial_version = version |
123 | 123 | except ImproperlyConfigured: |
124 | 124 | raise |
125 | | except Exception, msg: |
| 125 | except Exception as msg: |
126 | 126 | raise ImproperlyConfigured('Cannot determine the SpatiaLite version for the "%s" ' |
127 | 127 | 'database (error was "%s"). Was the SpatiaLite initialization ' |
128 | 128 | 'SQL loaded on this database?' % |
-
diff --git a/django/contrib/gis/geometry/backend/__init__.py b/django/contrib/gis/geometry/backend/__init__.py
index d79a556..2e2495d 100644
a
|
b
|
geom_backend = getattr(settings, 'GEOMETRY_BACKEND', 'geos')
|
6 | 6 | |
7 | 7 | try: |
8 | 8 | module = import_module('.%s' % geom_backend, 'django.contrib.gis.geometry.backend') |
9 | | except ImportError, e: |
| 9 | except ImportError as e: |
10 | 10 | try: |
11 | 11 | module = import_module(geom_backend) |
12 | | except ImportError, e_user: |
| 12 | except ImportError as e_user: |
13 | 13 | raise ImproperlyConfigured('Could not import user-defined GEOMETRY_BACKEND ' |
14 | 14 | '"%s".' % geom_backend) |
15 | 15 | |
-
diff --git a/django/contrib/gis/management/commands/ogrinspect.py b/django/contrib/gis/management/commands/ogrinspect.py
index fbc6f53..6037cc7 100644
a
|
b
|
class Command(LabelCommand):
|
87 | 87 | # Getting the OGR DataSource from the string parameter. |
88 | 88 | try: |
89 | 89 | ds = gdal.DataSource(data_source) |
90 | | except gdal.OGRException, msg: |
| 90 | except gdal.OGRException as msg: |
91 | 91 | raise CommandError(msg) |
92 | 92 | |
93 | 93 | # Whether the user wants to generate the LayerMapping dictionary as well. |
-
diff --git a/django/contrib/gis/tests/test_measure.py b/django/contrib/gis/tests/test_measure.py
index 8ca6be1..6792569 100644
a
|
b
|
class DistanceTest(unittest.TestCase):
|
64 | 64 | |
65 | 65 | try: |
66 | 66 | d5 = d1 + 1 |
67 | | except TypeError, e: |
| 67 | except TypeError as e: |
68 | 68 | pass |
69 | 69 | else: |
70 | 70 | self.fail('Distance + number should raise TypeError') |
71 | 71 | |
72 | 72 | try: |
73 | 73 | d5 = d1 - 1 |
74 | | except TypeError, e: |
| 74 | except TypeError as e: |
75 | 75 | pass |
76 | 76 | else: |
77 | 77 | self.fail('Distance - number should raise TypeError') |
78 | 78 | |
79 | 79 | try: |
80 | 80 | d1 += 1 |
81 | | except TypeError, e: |
| 81 | except TypeError as e: |
82 | 82 | pass |
83 | 83 | else: |
84 | 84 | self.fail('Distance += number should raise TypeError') |
85 | 85 | |
86 | 86 | try: |
87 | 87 | d1 -= 1 |
88 | | except TypeError, e: |
| 88 | except TypeError as e: |
89 | 89 | pass |
90 | 90 | else: |
91 | 91 | self.fail('Distance -= number should raise TypeError') |
… |
… |
class DistanceTest(unittest.TestCase):
|
112 | 112 | |
113 | 113 | try: |
114 | 114 | d1 *= D(m=1) |
115 | | except TypeError, e: |
| 115 | except TypeError as e: |
116 | 116 | pass |
117 | 117 | else: |
118 | 118 | self.fail('Distance *= Distance should raise TypeError') |
119 | 119 | |
120 | 120 | try: |
121 | 121 | d5 = d1 / D(m=1) |
122 | | except TypeError, e: |
| 122 | except TypeError as e: |
123 | 123 | pass |
124 | 124 | else: |
125 | 125 | self.fail('Distance / Distance should raise TypeError') |
126 | 126 | |
127 | 127 | try: |
128 | 128 | d1 /= D(m=1) |
129 | | except TypeError, e: |
| 129 | except TypeError as e: |
130 | 130 | pass |
131 | 131 | else: |
132 | 132 | self.fail('Distance /= Distance should raise TypeError') |
… |
… |
class AreaTest(unittest.TestCase):
|
219 | 219 | |
220 | 220 | try: |
221 | 221 | a5 = a1 + 1 |
222 | | except TypeError, e: |
| 222 | except TypeError as e: |
223 | 223 | pass |
224 | 224 | else: |
225 | 225 | self.fail('Area + number should raise TypeError') |
226 | 226 | |
227 | 227 | try: |
228 | 228 | a5 = a1 - 1 |
229 | | except TypeError, e: |
| 229 | except TypeError as e: |
230 | 230 | pass |
231 | 231 | else: |
232 | 232 | self.fail('Area - number should raise TypeError') |
233 | 233 | |
234 | 234 | try: |
235 | 235 | a1 += 1 |
236 | | except TypeError, e: |
| 236 | except TypeError as e: |
237 | 237 | pass |
238 | 238 | else: |
239 | 239 | self.fail('Area += number should raise TypeError') |
240 | 240 | |
241 | 241 | try: |
242 | 242 | a1 -= 1 |
243 | | except TypeError, e: |
| 243 | except TypeError as e: |
244 | 244 | pass |
245 | 245 | else: |
246 | 246 | self.fail('Area -= number should raise TypeError') |
… |
… |
class AreaTest(unittest.TestCase):
|
263 | 263 | |
264 | 264 | try: |
265 | 265 | a5 = a1 * A(sq_m=1) |
266 | | except TypeError, e: |
| 266 | except TypeError as e: |
267 | 267 | pass |
268 | 268 | else: |
269 | 269 | self.fail('Area * Area should raise TypeError') |
270 | 270 | |
271 | 271 | try: |
272 | 272 | a1 *= A(sq_m=1) |
273 | | except TypeError, e: |
| 273 | except TypeError as e: |
274 | 274 | pass |
275 | 275 | else: |
276 | 276 | self.fail('Area *= Area should raise TypeError') |
277 | 277 | |
278 | 278 | try: |
279 | 279 | a5 = a1 / A(sq_m=1) |
280 | | except TypeError, e: |
| 280 | except TypeError as e: |
281 | 281 | pass |
282 | 282 | else: |
283 | 283 | self.fail('Area / Area should raise TypeError') |
284 | 284 | |
285 | 285 | try: |
286 | 286 | a1 /= A(sq_m=1) |
287 | | except TypeError, e: |
| 287 | except TypeError as e: |
288 | 288 | pass |
289 | 289 | else: |
290 | 290 | self.fail('Area /= Area should raise TypeError') |
-
diff --git a/django/contrib/gis/utils/layermapping.py b/django/contrib/gis/utils/layermapping.py
index 154617f..ea3f3d7 100644
a
|
b
|
class LayerMapping(object):
|
430 | 430 | |
431 | 431 | # Creating the CoordTransform object |
432 | 432 | return CoordTransform(self.source_srs, target_srs) |
433 | | except Exception, msg: |
| 433 | except Exception as msg: |
434 | 434 | raise LayerMapError('Could not translate between the data source and model geometry: %s' % msg) |
435 | 435 | |
436 | 436 | def geometry_field(self): |
… |
… |
class LayerMapping(object):
|
514 | 514 | # Getting the keyword arguments |
515 | 515 | try: |
516 | 516 | kwargs = self.feature_kwargs(feat) |
517 | | except LayerMapError, msg: |
| 517 | except LayerMapError as msg: |
518 | 518 | # Something borked the validation |
519 | 519 | if strict: raise |
520 | 520 | elif not silent: |
… |
… |
class LayerMapping(object):
|
553 | 553 | if verbose: stream.write('%s: %s\n' % (is_update and 'Updated' or 'Saved', m)) |
554 | 554 | except SystemExit: |
555 | 555 | raise |
556 | | except Exception, msg: |
| 556 | except Exception as msg: |
557 | 557 | if self.transaction_mode == 'autocommit': |
558 | 558 | # Rolling back the transaction so that other model saves |
559 | 559 | # will work. |
-
diff --git a/django/contrib/markup/tests.py b/django/contrib/markup/tests.py
index cccb5c8..05df318 100644
a
|
b
|
Paragraph 2 with a link_
|
87 | 87 | # Docutils v0.4 and earlier |
88 | 88 | self.assertEqual(rendered, """<p>Paragraph 1</p> |
89 | 89 | <p>Paragraph 2 with a <a class="reference" href="http://www.example.com/">link</a></p>""") |
90 | | except AssertionError, e: |
| 90 | except AssertionError as e: |
91 | 91 | # Docutils from SVN (which will become 0.5) |
92 | 92 | self.assertEqual(rendered, """<p>Paragraph 1</p> |
93 | 93 | <p>Paragraph 2 with a <a class="reference external" href="http://www.example.com/">link</a></p>""") |
-
diff --git a/django/contrib/messages/storage/__init__.py b/django/contrib/messages/storage/__init__.py
index ce3971b..a584acc 100644
a
|
b
|
def get_storage(import_path):
|
15 | 15 | module, classname = import_path[:dot], import_path[dot + 1:] |
16 | 16 | try: |
17 | 17 | mod = import_module(module) |
18 | | except ImportError, e: |
| 18 | except ImportError as e: |
19 | 19 | raise ImproperlyConfigured('Error importing module %s: "%s"' % |
20 | 20 | (module, e)) |
21 | 21 | try: |
-
diff --git a/django/contrib/sessions/backends/file.py b/django/contrib/sessions/backends/file.py
index 8ffddc4..cb81534 100644
a
|
b
|
class SessionStore(SessionBase):
|
90 | 90 | fd = os.open(session_file_name, flags) |
91 | 91 | os.close(fd) |
92 | 92 | |
93 | | except OSError, e: |
| 93 | except OSError as e: |
94 | 94 | if must_create and e.errno == errno.EEXIST: |
95 | 95 | raise CreateError |
96 | 96 | raise |
-
diff --git a/django/contrib/staticfiles/finders.py b/django/contrib/staticfiles/finders.py
index 7b4c7c8..766687c 100644
a
|
b
|
def _get_finder(import_path):
|
260 | 260 | module, attr = import_path.rsplit('.', 1) |
261 | 261 | try: |
262 | 262 | mod = import_module(module) |
263 | | except ImportError, e: |
| 263 | except ImportError as e: |
264 | 264 | raise ImproperlyConfigured('Error importing module %s: "%s"' % |
265 | 265 | (module, e)) |
266 | 266 | try: |
-
diff --git a/django/contrib/staticfiles/handlers.py b/django/contrib/staticfiles/handlers.py
index 962b835..f475b22 100644
a
|
b
|
class StaticFilesHandler(WSGIHandler):
|
56 | 56 | if self._should_handle(request.path): |
57 | 57 | try: |
58 | 58 | return self.serve(request) |
59 | | except Http404, e: |
| 59 | except Http404 as e: |
60 | 60 | if settings.DEBUG: |
61 | 61 | from django.views import debug |
62 | 62 | return debug.technical_404_response(request, e) |
-
diff --git a/django/core/cache/__init__.py b/django/core/cache/__init__.py
index 346deae..3b40555 100644
a
|
b
|
def get_cache(backend, **kwargs):
|
173 | 173 | mod_path, cls_name = backend.rsplit('.', 1) |
174 | 174 | mod = importlib.import_module(mod_path) |
175 | 175 | backend_cls = getattr(mod, cls_name) |
176 | | except (AttributeError, ImportError), e: |
| 176 | except (AttributeError, ImportError) as e: |
177 | 177 | raise InvalidCacheBackendError( |
178 | 178 | "Could not find backend '%s': %s" % (backend, e)) |
179 | 179 | cache = backend_cls(location, params) |
-
diff --git a/django/core/files/move.py b/django/core/files/move.py
index 3349fc2..4778228 100644
a
|
b
|
def file_move_safe(old_file_name, new_file_name, chunk_size = 1024*64, allow_ove
|
79 | 79 | |
80 | 80 | try: |
81 | 81 | os.remove(old_file_name) |
82 | | except OSError, e: |
| 82 | except OSError as e: |
83 | 83 | # Certain operating systems (Cygwin and Windows) |
84 | 84 | # fail when deleting opened files, ignore it. (For the |
85 | 85 | # systems where this happens, temporary files will be auto-deleted |
-
diff --git a/django/core/files/storage.py b/django/core/files/storage.py
index aa62175..6b724b4 100644
a
|
b
|
class FileSystemStorage(Storage):
|
166 | 166 | if not os.path.exists(directory): |
167 | 167 | try: |
168 | 168 | os.makedirs(directory) |
169 | | except OSError, e: |
| 169 | except OSError as e: |
170 | 170 | if e.errno != errno.EEXIST: |
171 | 171 | raise |
172 | 172 | if not os.path.isdir(directory): |
… |
… |
class FileSystemStorage(Storage):
|
197 | 197 | finally: |
198 | 198 | locks.unlock(fd) |
199 | 199 | os.close(fd) |
200 | | except OSError, e: |
| 200 | except OSError as e: |
201 | 201 | if e.errno == errno.EEXIST: |
202 | 202 | # Ooops, the file exists. We need a new file name. |
203 | 203 | name = self.get_available_name(name) |
… |
… |
class FileSystemStorage(Storage):
|
222 | 222 | if os.path.exists(name): |
223 | 223 | try: |
224 | 224 | os.remove(name) |
225 | | except OSError, e: |
| 225 | except OSError as e: |
226 | 226 | if e.errno != errno.ENOENT: |
227 | 227 | raise |
228 | 228 | |
… |
… |
def get_storage_class(import_path=None):
|
273 | 273 | module, classname = import_path[:dot], import_path[dot+1:] |
274 | 274 | try: |
275 | 275 | mod = import_module(module) |
276 | | except ImportError, e: |
| 276 | except ImportError as e: |
277 | 277 | raise ImproperlyConfigured('Error importing storage module %s: "%s"' % (module, e)) |
278 | 278 | try: |
279 | 279 | return getattr(mod, classname) |
-
diff --git a/django/core/files/uploadedfile.py b/django/core/files/uploadedfile.py
index 5178f0b..1dcd9ae 100644
a
|
b
|
class TemporaryUploadedFile(UploadedFile):
|
75 | 75 | def close(self): |
76 | 76 | try: |
77 | 77 | return self.file.close() |
78 | | except OSError, e: |
| 78 | except OSError as e: |
79 | 79 | if e.errno != 2: |
80 | 80 | # Means the file was moved or deleted before the tempfile |
81 | 81 | # could unlink it. Still sets self.file.close_called and |
-
diff --git a/django/core/files/uploadhandler.py b/django/core/files/uploadhandler.py
index 2afb79e..b806098 100644
a
|
b
|
def load_handler(path, *args, **kwargs):
|
204 | 204 | module, attr = path[:i], path[i+1:] |
205 | 205 | try: |
206 | 206 | mod = importlib.import_module(module) |
207 | | except ImportError, e: |
| 207 | except ImportError as e: |
208 | 208 | raise ImproperlyConfigured('Error importing upload handler module %s: "%s"' % (module, e)) |
209 | | except ValueError, e: |
| 209 | except ValueError as e: |
210 | 210 | raise ImproperlyConfigured('Error importing upload handler module. Is FILE_UPLOAD_HANDLERS a correctly defined list or tuple?') |
211 | 211 | try: |
212 | 212 | cls = getattr(mod, attr) |
-
diff --git a/django/core/handlers/base.py b/django/core/handlers/base.py
index a0918bf..4c9dfc0 100644
a
|
b
|
class BaseHandler(object):
|
43 | 43 | raise exceptions.ImproperlyConfigured('%s isn\'t a middleware module' % middleware_path) |
44 | 44 | try: |
45 | 45 | mod = import_module(mw_module) |
46 | | except ImportError, e: |
| 46 | except ImportError as e: |
47 | 47 | raise exceptions.ImproperlyConfigured('Error importing middleware %s: "%s"' % (mw_module, e)) |
48 | 48 | try: |
49 | 49 | mw_class = getattr(mod, mw_classname) |
… |
… |
class BaseHandler(object):
|
109 | 109 | if response is None: |
110 | 110 | try: |
111 | 111 | response = callback(request, *callback_args, **callback_kwargs) |
112 | | except Exception, e: |
| 112 | except Exception as e: |
113 | 113 | # If the view raised an exception, run it through exception |
114 | 114 | # middleware, and if the exception middleware returns a |
115 | 115 | # response, use that. Otherwise, reraise the exception. |
… |
… |
class BaseHandler(object):
|
135 | 135 | response = middleware_method(request, response) |
136 | 136 | response = response.render() |
137 | 137 | |
138 | | except http.Http404, e: |
| 138 | except http.Http404 as e: |
139 | 139 | logger.warning('Not Found: %s', request.path, |
140 | 140 | extra={ |
141 | 141 | 'status_code': 404, |
-
diff --git a/django/core/mail/__init__.py b/django/core/mail/__init__.py
index 7ab02c3..3e3ef0d 100644
a
|
b
|
def get_connection(backend=None, fail_silently=False, **kwds):
|
30 | 30 | try: |
31 | 31 | mod_name, klass_name = path.rsplit('.', 1) |
32 | 32 | mod = import_module(mod_name) |
33 | | except ImportError, e: |
| 33 | except ImportError as e: |
34 | 34 | raise ImproperlyConfigured(('Error importing email backend module %s: "%s"' |
35 | 35 | % (mod_name, e))) |
36 | 36 | try: |
-
diff --git a/django/core/mail/backends/filebased.py b/django/core/mail/backends/filebased.py
index 3f6b99b..674ca32 100644
a
|
b
|
class EmailBackend(ConsoleEmailBackend):
|
25 | 25 | elif not os.path.exists(self.file_path): |
26 | 26 | try: |
27 | 27 | os.makedirs(self.file_path) |
28 | | except OSError, err: |
| 28 | except OSError as err: |
29 | 29 | raise ImproperlyConfigured('Could not create directory for saving email messages: %s (%s)' % (self.file_path, err)) |
30 | 30 | # Make sure that self.file_path is writable. |
31 | 31 | if not os.access(self.file_path, os.W_OK): |
-
diff --git a/django/core/management/base.py b/django/core/management/base.py
index db855e1..42c9ccd 100644
a
|
b
|
class BaseCommand(object):
|
215 | 215 | from django.utils import translation |
216 | 216 | saved_lang = translation.get_language() |
217 | 217 | translation.activate('en-us') |
218 | | except ImportError, e: |
| 218 | except ImportError as e: |
219 | 219 | # If settings should be available, but aren't, |
220 | 220 | # raise the error and quit. |
221 | 221 | if show_traceback: |
… |
… |
class BaseCommand(object):
|
241 | 241 | self.stdout.write(output) |
242 | 242 | if self.output_transaction: |
243 | 243 | self.stdout.write('\n' + self.style.SQL_KEYWORD("COMMIT;") + '\n') |
244 | | except CommandError, e: |
| 244 | except CommandError as e: |
245 | 245 | if show_traceback: |
246 | 246 | traceback.print_exc() |
247 | 247 | else: |
… |
… |
class AppCommand(BaseCommand):
|
297 | 297 | raise CommandError('Enter at least one appname.') |
298 | 298 | try: |
299 | 299 | app_list = [models.get_app(app_label) for app_label in app_labels] |
300 | | except (ImproperlyConfigured, ImportError), e: |
| 300 | except (ImproperlyConfigured, ImportError) as e: |
301 | 301 | raise CommandError("%s. Are you sure your INSTALLED_APPS setting is correct?" % e) |
302 | 302 | output = [] |
303 | 303 | for app in app_list: |
-
diff --git a/django/core/management/commands/createcachetable.py b/django/core/management/commands/createcachetable.py
index 7164d1a..82a126b 100644
a
|
b
|
class Command(LabelCommand):
|
54 | 54 | curs = connection.cursor() |
55 | 55 | try: |
56 | 56 | curs.execute("\n".join(full_statement)) |
57 | | except DatabaseError, e: |
| 57 | except DatabaseError as e: |
58 | 58 | self.stderr.write( |
59 | 59 | self.style.ERROR("Cache table '%s' could not be created.\nThe error was: %s.\n" % |
60 | 60 | (tablename, e))) |
-
diff --git a/django/core/management/commands/dumpdata.py b/django/core/management/commands/dumpdata.py
index 1622929..71d6fa7 100644
a
|
b
|
class Command(BaseCommand):
|
111 | 111 | try: |
112 | 112 | return serializers.serialize(format, objects, indent=indent, |
113 | 113 | use_natural_keys=use_natural_keys) |
114 | | except Exception, e: |
| 114 | except Exception as e: |
115 | 115 | if show_traceback: |
116 | 116 | raise |
117 | 117 | raise CommandError("Unable to serialize database: %s" % e) |
-
diff --git a/django/core/management/commands/flush.py b/django/core/management/commands/flush.py
index 6d0f14e..12a276e 100644
a
|
b
|
Are you sure you want to do this?
|
55 | 55 | cursor = connection.cursor() |
56 | 56 | for sql in sql_list: |
57 | 57 | cursor.execute(sql) |
58 | | except Exception, e: |
| 58 | except Exception as e: |
59 | 59 | transaction.rollback_unless_managed(using=db) |
60 | 60 | raise CommandError("""Database %s couldn't be flushed. Possible reasons: |
61 | 61 | * The database isn't running or isn't configured correctly. |
-
diff --git a/django/core/management/commands/loaddata.py b/django/core/management/commands/loaddata.py
index 0c234fb..d066343 100644
a
|
b
|
class Command(BaseCommand):
|
194 | 194 | models.add(obj.object.__class__) |
195 | 195 | try: |
196 | 196 | obj.save(using=using) |
197 | | except (DatabaseError, IntegrityError), e: |
| 197 | except (DatabaseError, IntegrityError) as e: |
198 | 198 | msg = "Could not load %(app_label)s.%(object_name)s(pk=%(pk)s): %(error_msg)s" % { |
199 | 199 | 'app_label': obj.object._meta.app_label, |
200 | 200 | 'object_name': obj.object._meta.object_name, |
-
diff --git a/django/core/management/commands/reset.py b/django/core/management/commands/reset.py
index e45edb7..4ac1a03 100644
a
|
b
|
Type 'yes' to continue, or 'no' to cancel: """ % (app_name, connection.settings_
|
49 | 49 | cursor = connection.cursor() |
50 | 50 | for sql in sql_list: |
51 | 51 | cursor.execute(sql) |
52 | | except Exception, e: |
| 52 | except Exception as e: |
53 | 53 | transaction.rollback_unless_managed() |
54 | 54 | raise CommandError("""Error: %s couldn't be reset. Possible reasons: |
55 | 55 | * The database isn't running or isn't configured correctly. |
-
diff --git a/django/core/management/commands/runserver.py b/django/core/management/commands/runserver.py
index e93af96..3ec4ea8 100644
a
|
b
|
class BaseRunserverCommand(BaseCommand):
|
109 | 109 | handler = self.get_handler(*args, **options) |
110 | 110 | run(self.addr, int(self.port), handler, |
111 | 111 | ipv6=self.use_ipv6, threading=threading) |
112 | | except WSGIServerException, e: |
| 112 | except WSGIServerException as e: |
113 | 113 | # Use helpful error messages instead of ugly tracebacks. |
114 | 114 | ERRORS = { |
115 | 115 | 13: "You don't have permission to access that port.", |
-
diff --git a/django/core/management/commands/syncdb.py b/django/core/management/commands/syncdb.py
index 852fa15..1f5d2ed 100644
a
|
b
|
class Command(NoArgsCommand):
|
38 | 38 | for app_name in settings.INSTALLED_APPS: |
39 | 39 | try: |
40 | 40 | import_module('.management', app_name) |
41 | | except ImportError, exc: |
| 41 | except ImportError as exc: |
42 | 42 | # This is slightly hackish. We want to ignore ImportErrors |
43 | 43 | # if the "management" module itself is missing -- but we don't |
44 | 44 | # want to ignore the exception if the management module exists |
… |
… |
class Command(NoArgsCommand):
|
126 | 126 | try: |
127 | 127 | for sql in custom_sql: |
128 | 128 | cursor.execute(sql) |
129 | | except Exception, e: |
| 129 | except Exception as e: |
130 | 130 | sys.stderr.write("Failed to install custom SQL for %s.%s model: %s\n" % \ |
131 | 131 | (app_name, model._meta.object_name, e)) |
132 | 132 | if show_traceback: |
… |
… |
class Command(NoArgsCommand):
|
151 | 151 | try: |
152 | 152 | for sql in index_sql: |
153 | 153 | cursor.execute(sql) |
154 | | except Exception, e: |
| 154 | except Exception as e: |
155 | 155 | sys.stderr.write("Failed to install index for %s.%s model: %s\n" % \ |
156 | 156 | (app_name, model._meta.object_name, e)) |
157 | 157 | transaction.rollback_unless_managed(using=db) |
-
diff --git a/django/core/management/templates.py b/django/core/management/templates.py
index 9a4b2c1..6bf1888 100644
a
|
b
|
class TemplateCommand(BaseCommand):
|
82 | 82 | top_dir = path.join(os.getcwd(), name) |
83 | 83 | try: |
84 | 84 | os.makedirs(top_dir) |
85 | | except OSError, e: |
| 85 | except OSError as e: |
86 | 86 | if e.errno == errno.EEXIST: |
87 | 87 | message = "'%s' already exists" % top_dir |
88 | 88 | else: |
… |
… |
class TemplateCommand(BaseCommand):
|
232 | 232 | try: |
233 | 233 | the_path, info = urllib.urlretrieve(url, |
234 | 234 | path.join(tempdir, filename)) |
235 | | except IOError, e: |
| 235 | except IOError as e: |
236 | 236 | raise CommandError("couldn't download URL %s to %s: %s" % |
237 | 237 | (url, filename, e)) |
238 | 238 | |
… |
… |
class TemplateCommand(BaseCommand):
|
287 | 287 | try: |
288 | 288 | archive.extract(filename, tempdir) |
289 | 289 | return tempdir |
290 | | except (archive.ArchiveException, IOError), e: |
| 290 | except (archive.ArchiveException, IOError) as e: |
291 | 291 | raise CommandError("couldn't extract file %s to %s: %s" % |
292 | 292 | (filename, tempdir, e)) |
293 | 293 | |
-
diff --git a/django/core/serializers/json.py b/django/core/serializers/json.py
index 91af84e..e9570b8 100644
a
|
b
|
def Deserializer(stream_or_string, **options):
|
42 | 42 | yield obj |
43 | 43 | except GeneratorExit: |
44 | 44 | raise |
45 | | except Exception, e: |
| 45 | except Exception as e: |
46 | 46 | # Map to deserializer error |
47 | 47 | raise DeserializationError(e) |
48 | 48 | |
-
diff --git a/django/core/serializers/pyyaml.py b/django/core/serializers/pyyaml.py
index 7a508da..dc884a6 100644
a
|
b
|
def Deserializer(stream_or_string, **options):
|
57 | 57 | yield obj |
58 | 58 | except GeneratorExit: |
59 | 59 | raise |
60 | | except Exception, e: |
| 60 | except Exception as e: |
61 | 61 | # Map to deserializer error |
62 | 62 | raise DeserializationError(e) |
-
diff --git a/django/core/servers/basehttp.py b/django/core/servers/basehttp.py
index 8d4ceab..f728ea1 100644
a
|
b
|
def get_internal_wsgi_application():
|
52 | 52 | module_name, attr = app_path.rsplit('.', 1) |
53 | 53 | try: |
54 | 54 | mod = import_module(module_name) |
55 | | except ImportError, e: |
| 55 | except ImportError as e: |
56 | 56 | raise ImproperlyConfigured( |
57 | 57 | "WSGI application '%s' could not be loaded; " |
58 | 58 | "could not import module '%s': %s" % (app_path, module_name, e)) |
59 | 59 | try: |
60 | 60 | app = getattr(mod, attr) |
61 | | except AttributeError, e: |
| 61 | except AttributeError as e: |
62 | 62 | raise ImproperlyConfigured( |
63 | 63 | "WSGI application '%s' could not be loaded; " |
64 | 64 | "can't find '%s' in module '%s': %s" |
… |
… |
class WSGIServer(simple_server.WSGIServer, object):
|
122 | 122 | """Override server_bind to store the server name.""" |
123 | 123 | try: |
124 | 124 | super(WSGIServer, self).server_bind() |
125 | | except Exception, e: |
| 125 | except Exception as e: |
126 | 126 | raise WSGIServerException(e) |
127 | 127 | self.setup_environ() |
128 | 128 | |
-
diff --git a/django/core/servers/fastcgi.py b/django/core/servers/fastcgi.py
index 17fd609..9c652a7 100644
a
|
b
|
def runfastcgi(argset=[], **kwargs):
|
102 | 102 | |
103 | 103 | try: |
104 | 104 | import flup |
105 | | except ImportError, e: |
| 105 | except ImportError as e: |
106 | 106 | print >> sys.stderr, "ERROR: %s" % e |
107 | 107 | print >> sys.stderr, " Unable to load the flup package. In order to run django" |
108 | 108 | print >> sys.stderr, " as a FastCGI application, you will need to get flup from" |
-
diff --git a/django/core/signing.py b/django/core/signing.py
index 7f92d61..78a8659 100644
a
|
b
|
def get_cookie_signer(salt='django.core.signing.get_cookie_signer'):
|
76 | 76 | module, attr = modpath.rsplit('.', 1) |
77 | 77 | try: |
78 | 78 | mod = import_module(module) |
79 | | except ImportError, e: |
| 79 | except ImportError as e: |
80 | 80 | raise ImproperlyConfigured( |
81 | 81 | 'Error importing cookie signer %s: "%s"' % (modpath, e)) |
82 | 82 | try: |
83 | 83 | Signer = getattr(mod, attr) |
84 | | except AttributeError, e: |
| 84 | except AttributeError as e: |
85 | 85 | raise ImproperlyConfigured( |
86 | 86 | 'Error importing cookie signer %s: "%s"' % (modpath, e)) |
87 | 87 | return Signer('django.http.cookies' + settings.SECRET_KEY, salt=salt) |
-
diff --git a/django/core/urlresolvers.py b/django/core/urlresolvers.py
index 1497d43..aadd290 100644
a
|
b
|
class RegexURLResolver(LocaleRegexProvider):
|
298 | 298 | for pattern in self.url_patterns: |
299 | 299 | try: |
300 | 300 | sub_match = pattern.resolve(new_path) |
301 | | except Resolver404, e: |
| 301 | except Resolver404 as e: |
302 | 302 | sub_tried = e.args[0].get('tried') |
303 | 303 | if sub_tried is not None: |
304 | 304 | tried.extend([[pattern] + t for t in sub_tried]) |
… |
… |
class RegexURLResolver(LocaleRegexProvider):
|
358 | 358 | raise ValueError("Don't mix *args and **kwargs in call to reverse()!") |
359 | 359 | try: |
360 | 360 | lookup_view = get_callable(lookup_view, True) |
361 | | except (ImportError, AttributeError), e: |
| 361 | except (ImportError, AttributeError) as e: |
362 | 362 | raise NoReverseMatch("Error importing '%s': %s." % (lookup_view, e)) |
363 | 363 | possibilities = self.reverse_dict.getlist(lookup_view) |
364 | 364 | prefix_norm, prefix_args = normalize(_prefix)[0] |
… |
… |
def reverse(viewname, urlconf=None, args=None, kwargs=None, prefix=None, current
|
462 | 462 | extra, resolver = resolver.namespace_dict[ns] |
463 | 463 | resolved_path.append(ns) |
464 | 464 | ns_pattern = ns_pattern + extra |
465 | | except KeyError, key: |
| 465 | except KeyError as key: |
466 | 466 | if resolved_path: |
467 | 467 | raise NoReverseMatch( |
468 | 468 | "%s is not a registered namespace inside '%s'" % |
-
diff --git a/django/core/validators.py b/django/core/validators.py
index 95224e9..52971e2 100644
a
|
b
|
class URLValidator(RegexValidator):
|
61 | 61 | def __call__(self, value): |
62 | 62 | try: |
63 | 63 | super(URLValidator, self).__call__(value) |
64 | | except ValidationError, e: |
| 64 | except ValidationError as e: |
65 | 65 | # Trivial case failed. Try for possible IDN domain |
66 | 66 | if value: |
67 | 67 | value = smart_unicode(value) |
… |
… |
class EmailValidator(RegexValidator):
|
144 | 144 | def __call__(self, value): |
145 | 145 | try: |
146 | 146 | super(EmailValidator, self).__call__(value) |
147 | | except ValidationError, e: |
| 147 | except ValidationError as e: |
148 | 148 | # Trivial case failed. Try for possible IDN domain-part |
149 | 149 | if value and u'@' in value: |
150 | 150 | parts = value.split(u'@') |
-
diff --git a/django/db/backends/creation.py b/django/db/backends/creation.py
index 0cd0558..2e3b7e5 100644
a
|
b
|
class BaseDatabaseCreation(object):
|
323 | 323 | try: |
324 | 324 | cursor.execute( |
325 | 325 | "CREATE DATABASE %s %s" % (qn(test_database_name), suffix)) |
326 | | except Exception, e: |
| 326 | except Exception as e: |
327 | 327 | sys.stderr.write( |
328 | 328 | "Got an error creating the test database: %s\n" % e) |
329 | 329 | if not autoclobber: |
… |
… |
class BaseDatabaseCreation(object):
|
340 | 340 | cursor.execute( |
341 | 341 | "CREATE DATABASE %s %s" % (qn(test_database_name), |
342 | 342 | suffix)) |
343 | | except Exception, e: |
| 343 | except Exception as e: |
344 | 344 | sys.stderr.write( |
345 | 345 | "Got an error recreating the test database: %s\n" % e) |
346 | 346 | sys.exit(2) |
-
diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py
index faaefca..c272f9f 100644
a
|
b
|
import warnings
|
11 | 11 | |
12 | 12 | try: |
13 | 13 | import MySQLdb as Database |
14 | | except ImportError, e: |
| 14 | except ImportError as e: |
15 | 15 | from django.core.exceptions import ImproperlyConfigured |
16 | 16 | raise ImproperlyConfigured("Error loading MySQLdb module: %s" % e) |
17 | 17 | |
… |
… |
class CursorWrapper(object):
|
112 | 112 | def execute(self, query, args=None): |
113 | 113 | try: |
114 | 114 | return self.cursor.execute(query, args) |
115 | | except Database.IntegrityError, e: |
| 115 | except Database.IntegrityError as e: |
116 | 116 | raise utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2] |
117 | | except Database.OperationalError, e: |
| 117 | except Database.OperationalError as e: |
118 | 118 | # Map some error codes to IntegrityError, since they seem to be |
119 | 119 | # misclassified and Django would prefer the more logical place. |
120 | 120 | if e[0] in self.codes_for_integrityerror: |
121 | 121 | raise utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2] |
122 | 122 | raise utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2] |
123 | | except Database.DatabaseError, e: |
| 123 | except Database.DatabaseError as e: |
124 | 124 | raise utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2] |
125 | 125 | |
126 | 126 | def executemany(self, query, args): |
127 | 127 | try: |
128 | 128 | return self.cursor.executemany(query, args) |
129 | | except Database.IntegrityError, e: |
| 129 | except Database.IntegrityError as e: |
130 | 130 | raise utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2] |
131 | | except Database.OperationalError, e: |
| 131 | except Database.OperationalError as e: |
132 | 132 | # Map some error codes to IntegrityError, since they seem to be |
133 | 133 | # misclassified and Django would prefer the more logical place. |
134 | 134 | if e[0] in self.codes_for_integrityerror: |
135 | 135 | raise utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2] |
136 | 136 | raise utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2] |
137 | | except Database.DatabaseError, e: |
| 137 | except Database.DatabaseError as e: |
138 | 138 | raise utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2] |
139 | 139 | |
140 | 140 | def __getattr__(self, attr): |
-
diff --git a/django/db/backends/oracle/base.py b/django/db/backends/oracle/base.py
index fc02ac4..9c91baa 100644
a
|
b
|
def _setup_environment(environ):
|
18 | 18 | if platform.system().upper().startswith('CYGWIN'): |
19 | 19 | try: |
20 | 20 | import ctypes |
21 | | except ImportError, e: |
| 21 | except ImportError as e: |
22 | 22 | from django.core.exceptions import ImproperlyConfigured |
23 | 23 | raise ImproperlyConfigured("Error loading ctypes: %s; " |
24 | 24 | "the Oracle backend requires ctypes to " |
… |
… |
_setup_environment([
|
41 | 41 | |
42 | 42 | try: |
43 | 43 | import cx_Oracle as Database |
44 | | except ImportError, e: |
| 44 | except ImportError as e: |
45 | 45 | from django.core.exceptions import ImproperlyConfigured |
46 | 46 | raise ImproperlyConfigured("Error loading cx_Oracle module: %s" % e) |
47 | 47 | |
… |
… |
class DatabaseWrapper(BaseDatabaseWrapper):
|
532 | 532 | if self.connection is not None: |
533 | 533 | try: |
534 | 534 | return self.connection.commit() |
535 | | except Database.IntegrityError, e: |
| 535 | except Database.IntegrityError as e: |
536 | 536 | # In case cx_Oracle implements (now or in a future version) |
537 | 537 | # raising this specific exception |
538 | 538 | raise utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2] |
539 | | except Database.DatabaseError, e: |
| 539 | except Database.DatabaseError as e: |
540 | 540 | # cx_Oracle 5.0.4 raises a cx_Oracle.DatabaseError exception |
541 | 541 | # with the following attributes and values: |
542 | 542 | # code = 2091 |
… |
… |
class FormatStylePlaceholderCursor(object):
|
673 | 673 | self._guess_input_sizes([params]) |
674 | 674 | try: |
675 | 675 | return self.cursor.execute(query, self._param_generator(params)) |
676 | | except Database.IntegrityError, e: |
| 676 | except Database.IntegrityError as e: |
677 | 677 | raise utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2] |
678 | | except Database.DatabaseError, e: |
| 678 | except Database.DatabaseError as e: |
679 | 679 | # cx_Oracle <= 4.4.0 wrongly raises a DatabaseError for ORA-01400. |
680 | 680 | if hasattr(e.args[0], 'code') and e.args[0].code == 1400 and not isinstance(e, IntegrityError): |
681 | 681 | raise utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2] |
… |
… |
class FormatStylePlaceholderCursor(object):
|
702 | 702 | try: |
703 | 703 | return self.cursor.executemany(query, |
704 | 704 | [self._param_generator(p) for p in formatted]) |
705 | | except Database.IntegrityError, e: |
| 705 | except Database.IntegrityError as e: |
706 | 706 | raise utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2] |
707 | | except Database.DatabaseError, e: |
| 707 | except Database.DatabaseError as e: |
708 | 708 | # cx_Oracle <= 4.4.0 wrongly raises a DatabaseError for ORA-01400. |
709 | 709 | if hasattr(e.args[0], 'code') and e.args[0].code == 1400 and not isinstance(e, IntegrityError): |
710 | 710 | raise utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2] |
-
diff --git a/django/db/backends/oracle/creation.py b/django/db/backends/oracle/creation.py
index 9e6133f..758c9ec 100644
a
|
b
|
class DatabaseCreation(BaseDatabaseCreation):
|
62 | 62 | if self._test_database_create(): |
63 | 63 | try: |
64 | 64 | self._execute_test_db_creation(cursor, parameters, verbosity) |
65 | | except Exception, e: |
| 65 | except Exception as e: |
66 | 66 | sys.stderr.write("Got an error creating the test database: %s\n" % e) |
67 | 67 | if not autoclobber: |
68 | 68 | confirm = raw_input("It appears the test database, %s, already exists. Type 'yes' to delete it, or 'no' to cancel: " % TEST_NAME) |
… |
… |
class DatabaseCreation(BaseDatabaseCreation):
|
72 | 72 | print "Destroying old test database '%s'..." % self.connection.alias |
73 | 73 | self._execute_test_db_destruction(cursor, parameters, verbosity) |
74 | 74 | self._execute_test_db_creation(cursor, parameters, verbosity) |
75 | | except Exception, e: |
| 75 | except Exception as e: |
76 | 76 | sys.stderr.write("Got an error recreating the test database: %s\n" % e) |
77 | 77 | sys.exit(2) |
78 | 78 | else: |
… |
… |
class DatabaseCreation(BaseDatabaseCreation):
|
84 | 84 | print "Creating test user..." |
85 | 85 | try: |
86 | 86 | self._create_test_user(cursor, parameters, verbosity) |
87 | | except Exception, e: |
| 87 | except Exception as e: |
88 | 88 | sys.stderr.write("Got an error creating the test user: %s\n" % e) |
89 | 89 | if not autoclobber: |
90 | 90 | confirm = raw_input("It appears the test user, %s, already exists. Type 'yes' to delete it, or 'no' to cancel: " % TEST_USER) |
… |
… |
class DatabaseCreation(BaseDatabaseCreation):
|
96 | 96 | if verbosity >= 1: |
97 | 97 | print "Creating test user..." |
98 | 98 | self._create_test_user(cursor, parameters, verbosity) |
99 | | except Exception, e: |
| 99 | except Exception as e: |
100 | 100 | sys.stderr.write("Got an error recreating the test user: %s\n" % e) |
101 | 101 | sys.exit(2) |
102 | 102 | else: |
… |
… |
class DatabaseCreation(BaseDatabaseCreation):
|
197 | 197 | print stmt |
198 | 198 | try: |
199 | 199 | cursor.execute(stmt) |
200 | | except Exception, err: |
| 200 | except Exception as err: |
201 | 201 | sys.stderr.write("Failed (%s)\n" % (err)) |
202 | 202 | raise |
203 | 203 | |
-
diff --git a/django/db/backends/postgresql_psycopg2/base.py b/django/db/backends/postgresql_psycopg2/base.py
index 0d25129..61be680 100644
a
|
b
|
from django.utils.timezone import utc
|
20 | 20 | try: |
21 | 21 | import psycopg2 as Database |
22 | 22 | import psycopg2.extensions |
23 | | except ImportError, e: |
| 23 | except ImportError as e: |
24 | 24 | from django.core.exceptions import ImproperlyConfigured |
25 | 25 | raise ImproperlyConfigured("Error loading psycopg2 module: %s" % e) |
26 | 26 | |
… |
… |
class CursorWrapper(object):
|
50 | 50 | def execute(self, query, args=None): |
51 | 51 | try: |
52 | 52 | return self.cursor.execute(query, args) |
53 | | except Database.IntegrityError, e: |
| 53 | except Database.IntegrityError as e: |
54 | 54 | raise utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2] |
55 | | except Database.DatabaseError, e: |
| 55 | except Database.DatabaseError as e: |
56 | 56 | raise utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2] |
57 | 57 | |
58 | 58 | def executemany(self, query, args): |
59 | 59 | try: |
60 | 60 | return self.cursor.executemany(query, args) |
61 | | except Database.IntegrityError, e: |
| 61 | except Database.IntegrityError as e: |
62 | 62 | raise utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2] |
63 | | except Database.DatabaseError, e: |
| 63 | except Database.DatabaseError as e: |
64 | 64 | raise utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2] |
65 | 65 | |
66 | 66 | def __getattr__(self, attr): |
… |
… |
class DatabaseWrapper(BaseDatabaseWrapper):
|
233 | 233 | if self.connection is not None: |
234 | 234 | try: |
235 | 235 | return self.connection.commit() |
236 | | except Database.IntegrityError, e: |
| 236 | except Database.IntegrityError as e: |
237 | 237 | raise utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2] |
-
diff --git a/django/db/backends/sqlite3/base.py b/django/db/backends/sqlite3/base.py
index 0b19442..3d389ed 100644
a
|
b
|
from django.utils import timezone
|
24 | 24 | try: |
25 | 25 | try: |
26 | 26 | from pysqlite2 import dbapi2 as Database |
27 | | except ImportError, e1: |
| 27 | except ImportError as e1: |
28 | 28 | from sqlite3 import dbapi2 as Database |
29 | | except ImportError, exc: |
| 29 | except ImportError as exc: |
30 | 30 | from django.core.exceptions import ImproperlyConfigured |
31 | 31 | raise ImproperlyConfigured("Error loading either pysqlite2 or sqlite3 modules (tried in that order): %s" % exc) |
32 | 32 | |
… |
… |
class SQLiteCursorWrapper(Database.Cursor):
|
335 | 335 | query = self.convert_query(query) |
336 | 336 | try: |
337 | 337 | return Database.Cursor.execute(self, query, params) |
338 | | except Database.IntegrityError, e: |
| 338 | except Database.IntegrityError as e: |
339 | 339 | raise utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2] |
340 | | except Database.DatabaseError, e: |
| 340 | except Database.DatabaseError as e: |
341 | 341 | raise utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2] |
342 | 342 | |
343 | 343 | def executemany(self, query, param_list): |
344 | 344 | query = self.convert_query(query) |
345 | 345 | try: |
346 | 346 | return Database.Cursor.executemany(self, query, param_list) |
347 | | except Database.IntegrityError, e: |
| 347 | except Database.IntegrityError as e: |
348 | 348 | raise utils.IntegrityError, utils.IntegrityError(*tuple(e)), sys.exc_info()[2] |
349 | | except Database.DatabaseError, e: |
| 349 | except Database.DatabaseError as e: |
350 | 350 | raise utils.DatabaseError, utils.DatabaseError(*tuple(e)), sys.exc_info()[2] |
351 | 351 | |
352 | 352 | def convert_query(self, query): |
-
diff --git a/django/db/backends/sqlite3/creation.py b/django/db/backends/sqlite3/creation.py
index 5f55e39..9e660fa 100644
a
|
b
|
class DatabaseCreation(BaseDatabaseCreation):
|
57 | 57 | if autoclobber or confirm == 'yes': |
58 | 58 | try: |
59 | 59 | os.remove(test_database_name) |
60 | | except Exception, e: |
| 60 | except Exception as e: |
61 | 61 | sys.stderr.write("Got an error deleting the old test database: %s\n" % e) |
62 | 62 | sys.exit(2) |
63 | 63 | else: |
-
diff --git a/django/db/models/base.py b/django/db/models/base.py
index fc38224..b92058c 100644
a
|
b
|
class Model(object):
|
801 | 801 | |
802 | 802 | try: |
803 | 803 | self.clean_fields(exclude=exclude) |
804 | | except ValidationError, e: |
| 804 | except ValidationError as e: |
805 | 805 | errors = e.update_error_dict(errors) |
806 | 806 | |
807 | 807 | # Form.clean() is run even if other validation fails, so do the |
808 | 808 | # same with Model.clean() for consistency. |
809 | 809 | try: |
810 | 810 | self.clean() |
811 | | except ValidationError, e: |
| 811 | except ValidationError as e: |
812 | 812 | errors = e.update_error_dict(errors) |
813 | 813 | |
814 | 814 | # Run unique checks, but only for fields that passed validation. |
… |
… |
class Model(object):
|
817 | 817 | exclude.append(name) |
818 | 818 | try: |
819 | 819 | self.validate_unique(exclude=exclude) |
820 | | except ValidationError, e: |
| 820 | except ValidationError as e: |
821 | 821 | errors = e.update_error_dict(errors) |
822 | 822 | |
823 | 823 | if errors: |
… |
… |
class Model(object):
|
842 | 842 | continue |
843 | 843 | try: |
844 | 844 | setattr(self, f.attname, f.clean(raw_value, self)) |
845 | | except ValidationError, e: |
| 845 | except ValidationError as e: |
846 | 846 | errors[f.name] = e.messages |
847 | 847 | |
848 | 848 | if errors: |
-
diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py
index 22546c2..67a4381 100644
a
|
b
|
class Field(object):
|
152 | 152 | for v in self.validators: |
153 | 153 | try: |
154 | 154 | v(value) |
155 | | except exceptions.ValidationError, e: |
| 155 | except exceptions.ValidationError as e: |
156 | 156 | if hasattr(e, 'code') and e.code in self.error_messages: |
157 | 157 | message = self.error_messages[e.code] |
158 | 158 | if e.params: |
-
diff --git a/django/db/models/query.py b/django/db/models/query.py
index 44acadf..5c68237 100644
a
|
b
|
class QuerySet(object):
|
205 | 205 | qs = self._clone() |
206 | 206 | qs.query.set_limits(k, k + 1) |
207 | 207 | return list(qs)[0] |
208 | | except self.model.DoesNotExist, e: |
| 208 | except self.model.DoesNotExist as e: |
209 | 209 | raise IndexError(e.args) |
210 | 210 | |
211 | 211 | def __and__(self, other): |
… |
… |
class QuerySet(object):
|
449 | 449 | obj.save(force_insert=True, using=self.db) |
450 | 450 | transaction.savepoint_commit(sid, using=self.db) |
451 | 451 | return obj, True |
452 | | except IntegrityError, e: |
| 452 | except IntegrityError as e: |
453 | 453 | transaction.savepoint_rollback(sid, using=self.db) |
454 | 454 | exc_info = sys.exc_info() |
455 | 455 | try: |
-
diff --git a/django/db/models/sql/query.py b/django/db/models/sql/query.py
index 693dde3..bc7512f 100644
a
|
b
|
class Query(object):
|
1120 | 1120 | parts, opts, alias, True, allow_many, allow_explicit_fk=True, |
1121 | 1121 | can_reuse=can_reuse, negate=negate, |
1122 | 1122 | process_extras=process_extras) |
1123 | | except MultiJoin, e: |
| 1123 | except MultiJoin as e: |
1124 | 1124 | self.split_exclude(filter_expr, LOOKUP_SEP.join(parts[:e.level]), |
1125 | 1125 | can_reuse) |
1126 | 1126 | return |
-
diff --git a/django/db/utils.py b/django/db/utils.py
index 3f5b86e..2b6ae2c 100644
a
|
b
|
def load_backend(backend_name):
|
22 | 22 | # Look for a fully qualified database backend name |
23 | 23 | try: |
24 | 24 | return import_module('.base', backend_name) |
25 | | except ImportError, e_user: |
| 25 | except ImportError as e_user: |
26 | 26 | # The database backend wasn't found. Display a helpful error message |
27 | 27 | # listing all possible (built-in) database backends. |
28 | 28 | backend_dir = os.path.join(os.path.dirname(__file__), 'backends') |
… |
… |
class ConnectionRouter(object):
|
112 | 112 | try: |
113 | 113 | module_name, klass_name = r.rsplit('.', 1) |
114 | 114 | module = import_module(module_name) |
115 | | except ImportError, e: |
| 115 | except ImportError as e: |
116 | 116 | raise ImproperlyConfigured('Error importing database router %s: "%s"' % (klass_name, e)) |
117 | 117 | try: |
118 | 118 | router_class = getattr(module, klass_name) |
-
diff --git a/django/dispatch/dispatcher.py b/django/dispatch/dispatcher.py
index ed9da57..0903c3a 100644
a
|
b
|
class Signal(object):
|
205 | 205 | for receiver in self._live_receivers(_make_id(sender)): |
206 | 206 | try: |
207 | 207 | response = receiver(signal=self, sender=sender, **named) |
208 | | except Exception, err: |
| 208 | except Exception as err: |
209 | 209 | responses.append((receiver, err)) |
210 | 210 | else: |
211 | 211 | responses.append((receiver, response)) |
-
diff --git a/django/dispatch/saferef.py b/django/dispatch/saferef.py
index 1c7d164..364c13e 100644
a
|
b
|
class BoundMethodWeakref(object):
|
119 | 119 | try: |
120 | 120 | if callable( function ): |
121 | 121 | function( self ) |
122 | | except Exception, e: |
| 122 | except Exception as e: |
123 | 123 | try: |
124 | 124 | traceback.print_exc() |
125 | | except AttributeError, err: |
| 125 | except AttributeError as err: |
126 | 126 | print '''Exception during saferef %s cleanup function %s: %s'''%( |
127 | 127 | self, function, e |
128 | 128 | ) |
-
diff --git a/django/forms/fields.py b/django/forms/fields.py
index 96ecabf..5d9d581 100644
a
|
b
|
class Field(object):
|
132 | 132 | for v in self.validators: |
133 | 133 | try: |
134 | 134 | v(value) |
135 | | except ValidationError, e: |
| 135 | except ValidationError as e: |
136 | 136 | if hasattr(e, 'code') and e.code in self.error_messages: |
137 | 137 | message = self.error_messages[e.code] |
138 | 138 | if e.params: |
… |
… |
class MultiValueField(Field):
|
898 | 898 | raise ValidationError(self.error_messages['required']) |
899 | 899 | try: |
900 | 900 | clean_data.append(field.clean(field_value)) |
901 | | except ValidationError, e: |
| 901 | except ValidationError as e: |
902 | 902 | # Collect all validation errors in a single list, which we'll |
903 | 903 | # raise at the end of clean(), rather than raising a single |
904 | 904 | # exception for the first error we encounter. |
-
diff --git a/django/forms/forms.py b/django/forms/forms.py
index 94eb22d..09663d1 100644
a
|
b
|
class BaseForm(StrAndUnicode):
|
289 | 289 | if hasattr(self, 'clean_%s' % name): |
290 | 290 | value = getattr(self, 'clean_%s' % name)() |
291 | 291 | self.cleaned_data[name] = value |
292 | | except ValidationError, e: |
| 292 | except ValidationError as e: |
293 | 293 | self._errors[name] = self.error_class(e.messages) |
294 | 294 | if name in self.cleaned_data: |
295 | 295 | del self.cleaned_data[name] |
… |
… |
class BaseForm(StrAndUnicode):
|
297 | 297 | def _clean_form(self): |
298 | 298 | try: |
299 | 299 | self.cleaned_data = self.clean() |
300 | | except ValidationError, e: |
| 300 | except ValidationError as e: |
301 | 301 | self._errors[NON_FIELD_ERRORS] = self.error_class(e.messages) |
302 | 302 | |
303 | 303 | def _post_clean(self): |
-
diff --git a/django/forms/formsets.py b/django/forms/formsets.py
index dcd2f01..739a9d4 100644
a
|
b
|
class BaseFormSet(StrAndUnicode):
|
291 | 291 | # Give self.clean() a chance to do cross-form validation. |
292 | 292 | try: |
293 | 293 | self.clean() |
294 | | except ValidationError, e: |
| 294 | except ValidationError as e: |
295 | 295 | self._non_form_errors = self.error_class(e.messages) |
296 | 296 | |
297 | 297 | def clean(self): |
-
diff --git a/django/forms/models.py b/django/forms/models.py
index cd8f027..ea80f8d 100644
a
|
b
|
class BaseModelForm(BaseForm):
|
324 | 324 | # Clean the model instance's fields. |
325 | 325 | try: |
326 | 326 | self.instance.clean_fields(exclude=exclude) |
327 | | except ValidationError, e: |
| 327 | except ValidationError as e: |
328 | 328 | self._update_errors(e.message_dict) |
329 | 329 | |
330 | 330 | # Call the model instance's clean method. |
331 | 331 | try: |
332 | 332 | self.instance.clean() |
333 | | except ValidationError, e: |
| 333 | except ValidationError as e: |
334 | 334 | self._update_errors({NON_FIELD_ERRORS: e.messages}) |
335 | 335 | |
336 | 336 | # Validate uniqueness if needed. |
… |
… |
class BaseModelForm(BaseForm):
|
345 | 345 | exclude = self._get_validation_exclusions() |
346 | 346 | try: |
347 | 347 | self.instance.validate_unique(exclude=exclude) |
348 | | except ValidationError, e: |
| 348 | except ValidationError as e: |
349 | 349 | self._update_errors(e.message_dict) |
350 | 350 | |
351 | 351 | def save(self, commit=True): |
-
diff --git a/django/forms/util.py b/django/forms/util.py
index 886f08e..1f3e290 100644
a
|
b
|
def from_current_timezone(value):
|
66 | 66 | current_timezone = timezone.get_current_timezone() |
67 | 67 | try: |
68 | 68 | return timezone.make_aware(value, current_timezone) |
69 | | except Exception, e: |
| 69 | except Exception as e: |
70 | 70 | raise ValidationError(_('%(datetime)s couldn\'t be interpreted ' |
71 | 71 | 'in time zone %(current_timezone)s; it ' |
72 | 72 | 'may be ambiguous or it may not exist.') |
-
diff --git a/django/http/__init__.py b/django/http/__init__.py
index 94478ae..1e371bd 100644
a
|
b
|
class HttpRequest(object):
|
326 | 326 | raise Exception("You cannot access body after reading from request's data stream") |
327 | 327 | try: |
328 | 328 | self._body = self.read() |
329 | | except IOError, e: |
| 329 | except IOError as e: |
330 | 330 | raise UnreadablePostError, e, sys.exc_traceback |
331 | 331 | self._stream = StringIO(self._body) |
332 | 332 | return self._body |
… |
… |
class HttpResponse(object):
|
592 | 592 | if isinstance(value, unicode): |
593 | 593 | try: |
594 | 594 | value = value.encode('us-ascii') |
595 | | except UnicodeError, e: |
| 595 | except UnicodeError as e: |
596 | 596 | e.reason += ', HTTP response headers must be in US-ASCII format' |
597 | 597 | raise |
598 | 598 | else: |
-
diff --git a/django/http/multipartparser.py b/django/http/multipartparser.py
index 477a08c..180ec34 100644
a
|
b
|
class MultiPartParser(object):
|
196 | 196 | # We only special-case base64 transfer encoding |
197 | 197 | try: |
198 | 198 | chunk = str(chunk).decode('base64') |
199 | | except Exception, e: |
| 199 | except Exception as e: |
200 | 200 | # Since this is only a chunk, any error is an unfixable error. |
201 | 201 | raise MultiPartParserError("Could not decode base64 data: %r" % e) |
202 | 202 | |
… |
… |
class MultiPartParser(object):
|
209 | 209 | # If the chunk received by the handler is None, then don't continue. |
210 | 210 | break |
211 | 211 | |
212 | | except SkipFile, e: |
| 212 | except SkipFile as e: |
213 | 213 | # Just use up the rest of this file... |
214 | 214 | exhaust(field_stream) |
215 | 215 | else: |
… |
… |
class MultiPartParser(object):
|
218 | 218 | else: |
219 | 219 | # If this is neither a FIELD or a FILE, just exhaust the stream. |
220 | 220 | exhaust(stream) |
221 | | except StopUpload, e: |
| 221 | except StopUpload as e: |
222 | 222 | if not e.connection_reset: |
223 | 223 | exhaust(self._input_data) |
224 | 224 | else: |
-
diff --git a/django/template/base.py b/django/template/base.py
index e2fc66b..f08313c 100644
a
|
b
|
class Parser(object):
|
265 | 265 | self.invalid_block_tag(token, command, parse_until) |
266 | 266 | try: |
267 | 267 | compiled_result = compile_func(self, token) |
268 | | except TemplateSyntaxError, e: |
| 268 | except TemplateSyntaxError as e: |
269 | 269 | if not self.compile_function_error(token, e): |
270 | 270 | raise |
271 | 271 | self.extend_nodelist(nodelist, compiled_result, token) |
… |
… |
class Variable(object):
|
774 | 774 | # GOTCHA: This will also catch any TypeError |
775 | 775 | # raised in the function itself. |
776 | 776 | current = settings.TEMPLATE_STRING_IF_INVALID # invalid method call |
777 | | except Exception, e: |
| 777 | except Exception as e: |
778 | 778 | if getattr(e, 'silent_variable_failure', False): |
779 | 779 | current = settings.TEMPLATE_STRING_IF_INVALID |
780 | 780 | else: |
… |
… |
def import_library(taglib_module):
|
1237 | 1237 | """ |
1238 | 1238 | try: |
1239 | 1239 | mod = import_module(taglib_module) |
1240 | | except ImportError, e: |
| 1240 | except ImportError as e: |
1241 | 1241 | # If the ImportError is because the taglib submodule does not exist, |
1242 | 1242 | # that's not an error that should be raised. If the submodule exists |
1243 | 1243 | # and raised an ImportError on the attempt to load it, that we want |
-
diff --git a/django/template/context.py b/django/template/context.py
index bbd38ad..db24551 100644
a
|
b
|
def get_standard_processors():
|
147 | 147 | module, attr = path[:i], path[i+1:] |
148 | 148 | try: |
149 | 149 | mod = import_module(module) |
150 | | except ImportError, e: |
| 150 | except ImportError as e: |
151 | 151 | raise ImproperlyConfigured('Error importing request processor module %s: "%s"' % (module, e)) |
152 | 152 | try: |
153 | 153 | func = getattr(mod, attr) |
-
diff --git a/django/template/debug.py b/django/template/debug.py
index 74aa82b..e8fd0b0 100644
a
|
b
|
class DebugNodeList(NodeList):
|
72 | 72 | def render_node(self, node, context): |
73 | 73 | try: |
74 | 74 | return node.render(context) |
75 | | except Exception, e: |
| 75 | except Exception as e: |
76 | 76 | if not hasattr(e, 'django_template_source'): |
77 | 77 | e.django_template_source = node.source |
78 | 78 | raise |
… |
… |
class DebugVariableNode(VariableNode):
|
87 | 87 | output = force_unicode(output) |
88 | 88 | except UnicodeDecodeError: |
89 | 89 | return '' |
90 | | except Exception, e: |
| 90 | except Exception as e: |
91 | 91 | if not hasattr(e, 'django_template_source'): |
92 | 92 | e.django_template_source = self.source |
93 | 93 | raise |
-
diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py
index f93e799..ea7d5e4 100644
a
|
b
|
def pprint(value):
|
892 | 892 | """A wrapper around pprint.pprint -- for debugging, really.""" |
893 | 893 | try: |
894 | 894 | return pformat(value) |
895 | | except Exception, e: |
| 895 | except Exception as e: |
896 | 896 | return u"Error in formatting: %s" % force_unicode(e, errors="replace") |
-
diff --git a/django/template/defaulttags.py b/django/template/defaulttags.py
index 954c5d6..00cf08c 100644
a
|
b
|
class ForNode(Node):
|
183 | 183 | for node in self.nodelist_loop: |
184 | 184 | try: |
185 | 185 | nodelist.append(node.render(context)) |
186 | | except Exception, e: |
| 186 | except Exception as e: |
187 | 187 | if not hasattr(e, 'django_template_source'): |
188 | 188 | e.django_template_source = node.source |
189 | 189 | raise |
… |
… |
class SsiNode(Node):
|
340 | 340 | try: |
341 | 341 | t = Template(output, name=filepath) |
342 | 342 | return t.render(context) |
343 | | except TemplateSyntaxError, e: |
| 343 | except TemplateSyntaxError as e: |
344 | 344 | if settings.DEBUG: |
345 | 345 | return "[Included template had syntax error: %s]" % e |
346 | 346 | else: |
… |
… |
class URLNode(Node):
|
409 | 409 | url = '' |
410 | 410 | try: |
411 | 411 | url = reverse(view_name, args=args, kwargs=kwargs, current_app=context.current_app) |
412 | | except NoReverseMatch, e: |
| 412 | except NoReverseMatch as e: |
413 | 413 | if settings.SETTINGS_MODULE: |
414 | 414 | project_name = settings.SETTINGS_MODULE.split('.')[0] |
415 | 415 | try: |
… |
… |
def load(parser, token):
|
1015 | 1015 | try: |
1016 | 1016 | taglib = bits[-1] |
1017 | 1017 | lib = get_library(taglib) |
1018 | | except InvalidTemplateLibrary, e: |
| 1018 | except InvalidTemplateLibrary as e: |
1019 | 1019 | raise TemplateSyntaxError("'%s' is not a valid tag library: %s" % |
1020 | 1020 | (taglib, e)) |
1021 | 1021 | else: |
… |
… |
def load(parser, token):
|
1038 | 1038 | try: |
1039 | 1039 | lib = get_library(taglib) |
1040 | 1040 | parser.add_library(lib) |
1041 | | except InvalidTemplateLibrary, e: |
| 1041 | except InvalidTemplateLibrary as e: |
1042 | 1042 | raise TemplateSyntaxError("'%s' is not a valid tag library: %s" % |
1043 | 1043 | (taglib, e)) |
1044 | 1044 | return LoadNode() |
-
diff --git a/django/template/loader.py b/django/template/loader.py
index 4185017..b6d62cc 100644
a
|
b
|
def find_template_loader(loader):
|
93 | 93 | module, attr = loader.rsplit('.', 1) |
94 | 94 | try: |
95 | 95 | mod = import_module(module) |
96 | | except ImportError, e: |
| 96 | except ImportError as e: |
97 | 97 | raise ImproperlyConfigured('Error importing template source loader %s: "%s"' % (loader, e)) |
98 | 98 | try: |
99 | 99 | TemplateLoader = getattr(mod, attr) |
100 | | except AttributeError, e: |
| 100 | except AttributeError as e: |
101 | 101 | raise ImproperlyConfigured('Error importing template source loader %s: "%s"' % (loader, e)) |
102 | 102 | |
103 | 103 | if hasattr(TemplateLoader, 'load_template_source'): |
… |
… |
def select_template(template_name_list):
|
185 | 185 | for template_name in template_name_list: |
186 | 186 | try: |
187 | 187 | return get_template(template_name) |
188 | | except TemplateDoesNotExist, e: |
| 188 | except TemplateDoesNotExist as e: |
189 | 189 | if e.args[0] not in not_found: |
190 | 190 | not_found.append(e.args[0]) |
191 | 191 | continue |
-
diff --git a/django/template/loaders/app_directories.py b/django/template/loaders/app_directories.py
index b0560b4..1ddb18e 100644
a
|
b
|
app_template_dirs = []
|
19 | 19 | for app in settings.INSTALLED_APPS: |
20 | 20 | try: |
21 | 21 | mod = import_module(app) |
22 | | except ImportError, e: |
| 22 | except ImportError as e: |
23 | 23 | raise ImproperlyConfigured('ImportError %s: %s' % (app, e.args[0])) |
24 | 24 | template_dir = os.path.join(os.path.dirname(mod.__file__), 'templates') |
25 | 25 | if os.path.isdir(template_dir): |
-
diff --git a/django/test/_doctest.py b/django/test/_doctest.py
index fe9b2f1..af2f409 100644
a
|
b
|
class DebugRunner(DocTestRunner):
|
1626 | 1626 | ... {}, 'foo', 'foo.py', 0) |
1627 | 1627 | >>> try: |
1628 | 1628 | ... runner.run(test) |
1629 | | ... except UnexpectedException, failure: |
| 1629 | ... except UnexpectedException as failure: |
1630 | 1630 | ... pass |
1631 | 1631 | |
1632 | 1632 | >>> failure.test is test |
… |
… |
class DebugRunner(DocTestRunner):
|
1654 | 1654 | |
1655 | 1655 | >>> try: |
1656 | 1656 | ... runner.run(test) |
1657 | | ... except DocTestFailure, failure: |
| 1657 | ... except DocTestFailure as failure: |
1658 | 1658 | ... pass |
1659 | 1659 | |
1660 | 1660 | DocTestFailure objects provide access to the test: |
… |
… |
class DocTestCase(unittest.TestCase):
|
2164 | 2164 | >>> case = DocTestCase(test) |
2165 | 2165 | >>> try: |
2166 | 2166 | ... case.debug() |
2167 | | ... except UnexpectedException, failure: |
| 2167 | ... except UnexpectedException as failure: |
2168 | 2168 | ... pass |
2169 | 2169 | |
2170 | 2170 | The UnexpectedException contains the test, the example, and |
… |
… |
class DocTestCase(unittest.TestCase):
|
2193 | 2193 | |
2194 | 2194 | >>> try: |
2195 | 2195 | ... case.debug() |
2196 | | ... except DocTestFailure, failure: |
| 2196 | ... except DocTestFailure as failure: |
2197 | 2197 | ... pass |
2198 | 2198 | |
2199 | 2199 | DocTestFailure objects provide access to the test: |
-
diff --git a/django/test/client.py b/django/test/client.py
index 6f3b73d..69f72fd 100644
a
|
b
|
class Client(RequestFactory):
|
379 | 379 | |
380 | 380 | try: |
381 | 381 | response = self.handler(environ) |
382 | | except TemplateDoesNotExist, e: |
| 382 | except TemplateDoesNotExist as e: |
383 | 383 | # If the view raises an exception, Django will attempt to show |
384 | 384 | # the 500.html template. If that template is not available, |
385 | 385 | # we should ignore the error in favor of re-raising the |
-
diff --git a/django/test/testcases.py b/django/test/testcases.py
index b5e1dc0..7885225 100644
a
|
b
|
def restore_transaction_methods():
|
85 | 85 | def assert_and_parse_html(self, html, user_msg, msg): |
86 | 86 | try: |
87 | 87 | dom = parse_html(html) |
88 | | except HTMLParseError, e: |
| 88 | except HTMLParseError as e: |
89 | 89 | standardMsg = u'%s\n%s' % (msg, e.msg) |
90 | 90 | self.fail(self._formatMessage(user_msg, standardMsg)) |
91 | 91 | return dom |
… |
… |
class LiveServerThread(threading.Thread):
|
1036 | 1036 | try: |
1037 | 1037 | self.httpd = StoppableWSGIServer( |
1038 | 1038 | (self.host, port), QuietWSGIRequestHandler) |
1039 | | except WSGIServerException, e: |
| 1039 | except WSGIServerException as e: |
1040 | 1040 | if sys.version_info < (2, 6): |
1041 | 1041 | error_code = e.args[0].args[0] |
1042 | 1042 | else: |
… |
… |
class LiveServerThread(threading.Thread):
|
1059 | 1059 | self.httpd.set_app(handler) |
1060 | 1060 | self.is_ready.set() |
1061 | 1061 | self.httpd.serve_forever() |
1062 | | except Exception, e: |
| 1062 | except Exception as e: |
1063 | 1063 | self.error = e |
1064 | 1064 | self.is_ready.set() |
1065 | 1065 | |
-
diff --git a/django/utils/daemonize.py b/django/utils/daemonize.py
index 68e5392..a9d5128 100644
a
|
b
|
if os.name == 'posix':
|
9 | 9 | try: |
10 | 10 | if os.fork() > 0: |
11 | 11 | sys.exit(0) # kill off parent |
12 | | except OSError, e: |
| 12 | except OSError as e: |
13 | 13 | sys.stderr.write("fork #1 failed: (%d) %s\n" % (e.errno, e.strerror)) |
14 | 14 | sys.exit(1) |
15 | 15 | os.setsid() |
… |
… |
if os.name == 'posix':
|
20 | 20 | try: |
21 | 21 | if os.fork() > 0: |
22 | 22 | os._exit(0) |
23 | | except OSError, e: |
| 23 | except OSError as e: |
24 | 24 | sys.stderr.write("fork #2 failed: (%d) %s\n" % (e.errno, e.strerror)) |
25 | 25 | os._exit(1) |
26 | 26 | |
-
diff --git a/django/utils/decorators.py b/django/utils/decorators.py
index 22f33a7..e653a73 100644
a
|
b
|
def make_middleware_decorator(middleware_class):
|
89 | 89 | return result |
90 | 90 | try: |
91 | 91 | response = view_func(request, *args, **kwargs) |
92 | | except Exception, e: |
| 92 | except Exception as e: |
93 | 93 | if hasattr(middleware, 'process_exception'): |
94 | 94 | result = middleware.process_exception(request, e) |
95 | 95 | if result is not None: |
-
diff --git a/django/utils/dictconfig.py b/django/utils/dictconfig.py
index 42fbd93..ae797af 100644
a
|
b
|
class DictConfigurator(BaseConfigurator):
|
297 | 297 | level = handler_config.get('level', None) |
298 | 298 | if level: |
299 | 299 | handler.setLevel(_checkLevel(level)) |
300 | | except StandardError, e: |
| 300 | except StandardError as e: |
301 | 301 | raise ValueError('Unable to configure handler ' |
302 | 302 | '%r: %s' % (name, e)) |
303 | 303 | loggers = config.get('loggers', EMPTY_DICT) |
304 | 304 | for name in loggers: |
305 | 305 | try: |
306 | 306 | self.configure_logger(name, loggers[name], True) |
307 | | except StandardError, e: |
| 307 | except StandardError as e: |
308 | 308 | raise ValueError('Unable to configure logger ' |
309 | 309 | '%r: %s' % (name, e)) |
310 | 310 | root = config.get('root', None) |
311 | 311 | if root: |
312 | 312 | try: |
313 | 313 | self.configure_root(root, True) |
314 | | except StandardError, e: |
| 314 | except StandardError as e: |
315 | 315 | raise ValueError('Unable to configure root ' |
316 | 316 | 'logger: %s' % e) |
317 | 317 | else: |
… |
… |
class DictConfigurator(BaseConfigurator):
|
326 | 326 | try: |
327 | 327 | formatters[name] = self.configure_formatter( |
328 | 328 | formatters[name]) |
329 | | except StandardError, e: |
| 329 | except StandardError as e: |
330 | 330 | raise ValueError('Unable to configure ' |
331 | 331 | 'formatter %r: %s' % (name, e)) |
332 | 332 | # Next, do filters - they don't refer to anything else, either |
… |
… |
class DictConfigurator(BaseConfigurator):
|
334 | 334 | for name in filters: |
335 | 335 | try: |
336 | 336 | filters[name] = self.configure_filter(filters[name]) |
337 | | except StandardError, e: |
| 337 | except StandardError as e: |
338 | 338 | raise ValueError('Unable to configure ' |
339 | 339 | 'filter %r: %s' % (name, e)) |
340 | 340 | |
… |
… |
class DictConfigurator(BaseConfigurator):
|
347 | 347 | handler = self.configure_handler(handlers[name]) |
348 | 348 | handler.name = name |
349 | 349 | handlers[name] = handler |
350 | | except StandardError, e: |
| 350 | except StandardError as e: |
351 | 351 | raise ValueError('Unable to configure handler ' |
352 | 352 | '%r: %s' % (name, e)) |
353 | 353 | # Next, do loggers - they refer to handlers and filters |
… |
… |
class DictConfigurator(BaseConfigurator):
|
386 | 386 | existing.remove(name) |
387 | 387 | try: |
388 | 388 | self.configure_logger(name, loggers[name]) |
389 | | except StandardError, e: |
| 389 | except StandardError as e: |
390 | 390 | raise ValueError('Unable to configure logger ' |
391 | 391 | '%r: %s' % (name, e)) |
392 | 392 | |
… |
… |
class DictConfigurator(BaseConfigurator):
|
409 | 409 | if root: |
410 | 410 | try: |
411 | 411 | self.configure_root(root) |
412 | | except StandardError, e: |
| 412 | except StandardError as e: |
413 | 413 | raise ValueError('Unable to configure root ' |
414 | 414 | 'logger: %s' % e) |
415 | 415 | finally: |
… |
… |
class DictConfigurator(BaseConfigurator):
|
421 | 421 | factory = config['()'] # for use in exception handler |
422 | 422 | try: |
423 | 423 | result = self.configure_custom(config) |
424 | | except TypeError, te: |
| 424 | except TypeError as te: |
425 | 425 | if "'format'" not in str(te): |
426 | 426 | raise |
427 | 427 | #Name of parameter changed from fmt to format. |
… |
… |
class DictConfigurator(BaseConfigurator):
|
451 | 451 | for f in filters: |
452 | 452 | try: |
453 | 453 | filterer.addFilter(self.config['filters'][f]) |
454 | | except StandardError, e: |
| 454 | except StandardError as e: |
455 | 455 | raise ValueError('Unable to add filter %r: %s' % (f, e)) |
456 | 456 | |
457 | 457 | def configure_handler(self, config): |
… |
… |
class DictConfigurator(BaseConfigurator):
|
460 | 460 | if formatter: |
461 | 461 | try: |
462 | 462 | formatter = self.config['formatters'][formatter] |
463 | | except StandardError, e: |
| 463 | except StandardError as e: |
464 | 464 | raise ValueError('Unable to set formatter ' |
465 | 465 | '%r: %s' % (formatter, e)) |
466 | 466 | level = config.pop('level', None) |
… |
… |
class DictConfigurator(BaseConfigurator):
|
477 | 477 | 'target' in config: |
478 | 478 | try: |
479 | 479 | config['target'] = self.config['handlers'][config['target']] |
480 | | except StandardError, e: |
| 480 | except StandardError as e: |
481 | 481 | raise ValueError('Unable to set target handler ' |
482 | 482 | '%r: %s' % (config['target'], e)) |
483 | 483 | elif issubclass(klass, logging.handlers.SMTPHandler) and\ |
… |
… |
class DictConfigurator(BaseConfigurator):
|
490 | 490 | kwargs = dict([(k, config[k]) for k in config if valid_ident(k)]) |
491 | 491 | try: |
492 | 492 | result = factory(**kwargs) |
493 | | except TypeError, te: |
| 493 | except TypeError as te: |
494 | 494 | if "'stream'" not in str(te): |
495 | 495 | raise |
496 | 496 | #The argument name changed from strm to stream |
… |
… |
class DictConfigurator(BaseConfigurator):
|
512 | 512 | for h in handlers: |
513 | 513 | try: |
514 | 514 | logger.addHandler(self.config['handlers'][h]) |
515 | | except StandardError, e: |
| 515 | except StandardError as e: |
516 | 516 | raise ValueError('Unable to add handler %r: %s' % (h, e)) |
517 | 517 | |
518 | 518 | def common_logger_config(self, logger, config, incremental=False): |
-
diff --git a/django/utils/encoding.py b/django/utils/encoding.py
index 36e0da2..d9b5944 100644
a
|
b
|
def force_unicode(s, encoding='utf-8', strings_only=False, errors='strict'):
|
88 | 88 | # errors), so that if s is a SafeString, it ends up being a |
89 | 89 | # SafeUnicode at the end. |
90 | 90 | s = s.decode(encoding, errors) |
91 | | except UnicodeDecodeError, e: |
| 91 | except UnicodeDecodeError as e: |
92 | 92 | if not isinstance(s, Exception): |
93 | 93 | raise DjangoUnicodeDecodeError(s, *e.args) |
94 | 94 | else: |
-
diff --git a/django/views/debug.py b/django/views/debug.py
index b549959..14a151f 100644
a
|
b
|
def get_exception_reporter_filter(request):
|
77 | 77 | modname, classname = modpath.rsplit('.', 1) |
78 | 78 | try: |
79 | 79 | mod = import_module(modname) |
80 | | except ImportError, e: |
| 80 | except ImportError as e: |
81 | 81 | raise ImproperlyConfigured( |
82 | 82 | 'Error importing default exception reporter filter %s: "%s"' % (modpath, e)) |
83 | 83 | try: |
-
diff --git a/extras/csrf_migration_helper.py b/extras/csrf_migration_helper.py
index 94b5a20..0e13163 100755
a
|
b
|
class Template(object):
|
173 | 173 | fd = open(self.absolute_filename) |
174 | 174 | try: |
175 | 175 | content = fd.read().decode(TEMPLATE_ENCODING) |
176 | | except UnicodeDecodeError, e: |
| 176 | except UnicodeDecodeError as e: |
177 | 177 | message = '%s in %s' % ( |
178 | 178 | e[4], self.absolute_filename.encode('UTF-8', 'ignore')) |
179 | 179 | raise UnicodeDecodeError(*(e.args[:4] + (message,))) |
-
diff --git a/tests/modeltests/basic/tests.py b/tests/modeltests/basic/tests.py
index f9141dc..42192e0 100644
a
|
b
|
class ModelTest(TestCase):
|
374 | 374 | try: |
375 | 375 | Article.objects.all()[0:1] & Article.objects.all()[4:5] |
376 | 376 | self.fail('Should raise an AssertionError') |
377 | | except AssertionError, e: |
| 377 | except AssertionError as e: |
378 | 378 | self.assertEqual(str(e), "Cannot combine queries once a slice has been taken.") |
379 | | except Exception, e: |
| 379 | except Exception as e: |
380 | 380 | self.fail('Should raise an AssertionError, not %s' % e) |
381 | 381 | |
382 | 382 | # Negative slices are not supported, due to database constraints. |
… |
… |
class ModelTest(TestCase):
|
384 | 384 | try: |
385 | 385 | Article.objects.all()[-1] |
386 | 386 | self.fail('Should raise an AssertionError') |
387 | | except AssertionError, e: |
| 387 | except AssertionError as e: |
388 | 388 | self.assertEqual(str(e), "Negative indexing is not supported.") |
389 | | except Exception, e: |
| 389 | except Exception as e: |
390 | 390 | self.fail('Should raise an AssertionError, not %s' % e) |
391 | 391 | |
392 | 392 | error = None |
393 | 393 | try: |
394 | 394 | Article.objects.all()[0:-5] |
395 | | except Exception, e: |
| 395 | except Exception as e: |
396 | 396 | error = e |
397 | 397 | self.assertTrue(isinstance(error, AssertionError)) |
398 | 398 | self.assertEqual(str(error), "Negative indexing is not supported.") |
-
diff --git a/tests/modeltests/get_or_create/tests.py b/tests/modeltests/get_or_create/tests.py
index f98f0e6..1e300fb 100644
a
|
b
|
class GetOrCreateTests(TestCase):
|
60 | 60 | # the actual traceback. Refs #16340. |
61 | 61 | try: |
62 | 62 | ManualPrimaryKeyTest.objects.get_or_create(id=1, data="Different") |
63 | | except IntegrityError, e: |
| 63 | except IntegrityError as e: |
64 | 64 | formatted_traceback = traceback.format_exc() |
65 | 65 | self.assertIn('obj.save', formatted_traceback) |
66 | 66 | |
-
diff --git a/tests/modeltests/invalid_models/tests.py b/tests/modeltests/invalid_models/tests.py
index dac562c..a1084c6 100644
a
|
b
|
class InvalidModelTestCase(unittest.TestCase):
|
35 | 35 | |
36 | 36 | try: |
37 | 37 | module = load_app("modeltests.invalid_models.invalid_models") |
38 | | except Exception, e: |
| 38 | except Exception as e: |
39 | 39 | self.fail('Unable to load invalid model module') |
40 | 40 | |
41 | 41 | count = get_validation_errors(self.stdout, module) |
-
diff --git a/tests/modeltests/lookup/tests.py b/tests/modeltests/lookup/tests.py
index 3571e21..ccd7863 100644
a
|
b
|
class LookupTests(TestCase):
|
468 | 468 | try: |
469 | 469 | Article.objects.filter(pub_date_year='2005').count() |
470 | 470 | self.fail('FieldError not raised') |
471 | | except FieldError, ex: |
| 471 | except FieldError as ex: |
472 | 472 | self.assertEqual(str(ex), "Cannot resolve keyword 'pub_date_year' " |
473 | 473 | "into field. Choices are: author, headline, id, pub_date, tag") |
474 | 474 | try: |
475 | 475 | Article.objects.filter(headline__starts='Article') |
476 | 476 | self.fail('FieldError not raised') |
477 | | except FieldError, ex: |
| 477 | except FieldError as ex: |
478 | 478 | self.assertEqual(str(ex), "Join on field 'headline' not permitted. " |
479 | 479 | "Did you misspell 'starts' for the lookup type?") |
480 | 480 | |
-
diff --git a/tests/modeltests/select_for_update/tests.py b/tests/modeltests/select_for_update/tests.py
index 65bc13a..dba7889 100644
a
|
b
|
class SelectForUpdateTests(TransactionTestCase):
|
169 | 169 | people[0].name = 'Fred' |
170 | 170 | people[0].save() |
171 | 171 | transaction.commit() |
172 | | except DatabaseError, e: |
| 172 | except DatabaseError as e: |
173 | 173 | status.append(e) |
174 | | except Exception, e: |
| 174 | except Exception as e: |
175 | 175 | raise |
176 | 176 | finally: |
177 | 177 | # This method is run in a separate thread. It uses its own |
… |
… |
class SelectForUpdateTests(TransactionTestCase):
|
246 | 246 | ) |
247 | 247 | ) |
248 | 248 | ) |
249 | | except DatabaseError, e: |
| 249 | except DatabaseError as e: |
250 | 250 | status.append(e) |
251 | 251 | finally: |
252 | 252 | # This method is run in a separate thread. It uses its own |
-
diff --git a/tests/modeltests/validation/models.py b/tests/modeltests/validation/models.py
index 8010701..7791a09 100644
a
|
b
|
try:
|
100 | 100 | class MultipleAutoFields(models.Model): |
101 | 101 | auto1 = models.AutoField(primary_key=True) |
102 | 102 | auto2 = models.AutoField(primary_key=True) |
103 | | except AssertionError, assertion_error: |
| 103 | except AssertionError as assertion_error: |
104 | 104 | pass # Fail silently |
105 | 105 | assert str(assertion_error) == u"A model can't have more than one AutoField." |
| 106 | No newline at end of file |
-
diff --git a/tests/modeltests/validation/test_error_messages.py b/tests/modeltests/validation/test_error_messages.py
index 4a2ad1f..04ad7aa 100644
a
|
b
|
class ValidationMessagesTest(TestCase):
|
10 | 10 | self.assertRaises(ValidationError, f.clean, 'foo', None) |
11 | 11 | try: |
12 | 12 | f.clean('foo', None) |
13 | | except ValidationError, e: |
| 13 | except ValidationError as e: |
14 | 14 | self.assertEqual(e.messages, [u"'foo' value must be an integer."]) |
15 | 15 | # primary_key must be True. Refs #12467. |
16 | 16 | self.assertRaises(AssertionError, models.AutoField, 'primary_key', False) |
17 | 17 | try: |
18 | 18 | models.AutoField(primary_key=False) |
19 | | except AssertionError, e: |
| 19 | except AssertionError as e: |
20 | 20 | self.assertEqual(str(e), "AutoFields must have primary_key=True.") |
21 | 21 | |
22 | 22 | def test_integer_field_raises_error_message(self): |
… |
… |
class ValidationMessagesTest(TestCase):
|
24 | 24 | self.assertRaises(ValidationError, f.clean, 'foo', None) |
25 | 25 | try: |
26 | 26 | f.clean('foo', None) |
27 | | except ValidationError, e: |
| 27 | except ValidationError as e: |
28 | 28 | self.assertEqual(e.messages, [u"'foo' value must be an integer."]) |
29 | 29 | |
30 | 30 | def test_boolean_field_raises_error_message(self): |
… |
… |
class ValidationMessagesTest(TestCase):
|
32 | 32 | self.assertRaises(ValidationError, f.clean, 'foo', None) |
33 | 33 | try: |
34 | 34 | f.clean('foo', None) |
35 | | except ValidationError, e: |
| 35 | except ValidationError as e: |
36 | 36 | self.assertEqual(e.messages, |
37 | 37 | [u"'foo' value must be either True or False."]) |
38 | 38 | |
… |
… |
class ValidationMessagesTest(TestCase):
|
41 | 41 | self.assertRaises(ValidationError, f.clean, 'foo', None) |
42 | 42 | try: |
43 | 43 | f.clean('foo', None) |
44 | | except ValidationError, e: |
| 44 | except ValidationError as e: |
45 | 45 | self.assertEqual(e.messages, [u"'foo' value must be a float."]) |
46 | 46 | |
47 | 47 | def test_decimal_field_raises_error_message(self): |
… |
… |
class ValidationMessagesTest(TestCase):
|
49 | 49 | self.assertRaises(ValidationError, f.clean, 'foo', None) |
50 | 50 | try: |
51 | 51 | f.clean('foo', None) |
52 | | except ValidationError, e: |
| 52 | except ValidationError as e: |
53 | 53 | self.assertEqual(e.messages, |
54 | 54 | [u"'foo' value must be a decimal number."]) |
55 | 55 | |
… |
… |
class ValidationMessagesTest(TestCase):
|
58 | 58 | self.assertRaises(ValidationError, f.clean, 'foo', None) |
59 | 59 | try: |
60 | 60 | f.clean('foo', None) |
61 | | except ValidationError, e: |
| 61 | except ValidationError as e: |
62 | 62 | self.assertEqual(e.messages, |
63 | 63 | [u"'foo' value must be either None, True or False."]) |
64 | 64 | |
… |
… |
class ValidationMessagesTest(TestCase):
|
67 | 67 | self.assertRaises(ValidationError, f.clean, 'foo', None) |
68 | 68 | try: |
69 | 69 | f.clean('foo', None) |
70 | | except ValidationError, e: |
| 70 | except ValidationError as e: |
71 | 71 | self.assertEqual(e.messages, [ |
72 | 72 | u"'foo' value has an invalid date format. " |
73 | 73 | u"It must be in YYYY-MM-DD format."]) |
… |
… |
class ValidationMessagesTest(TestCase):
|
75 | 75 | self.assertRaises(ValidationError, f.clean, 'aaaa-10-10', None) |
76 | 76 | try: |
77 | 77 | f.clean('aaaa-10-10', None) |
78 | | except ValidationError, e: |
| 78 | except ValidationError as e: |
79 | 79 | self.assertEqual(e.messages, [ |
80 | 80 | u"'aaaa-10-10' value has an invalid date format. " |
81 | 81 | u"It must be in YYYY-MM-DD format."]) |
… |
… |
class ValidationMessagesTest(TestCase):
|
83 | 83 | self.assertRaises(ValidationError, f.clean, '2011-13-10', None) |
84 | 84 | try: |
85 | 85 | f.clean('2011-13-10', None) |
86 | | except ValidationError, e: |
| 86 | except ValidationError as e: |
87 | 87 | self.assertEqual(e.messages, [ |
88 | 88 | u"'2011-13-10' value has the correct format (YYYY-MM-DD) " |
89 | 89 | u"but it is an invalid date."]) |
… |
… |
class ValidationMessagesTest(TestCase):
|
91 | 91 | self.assertRaises(ValidationError, f.clean, '2011-10-32', None) |
92 | 92 | try: |
93 | 93 | f.clean('2011-10-32', None) |
94 | | except ValidationError, e: |
| 94 | except ValidationError as e: |
95 | 95 | self.assertEqual(e.messages, [ |
96 | 96 | u"'2011-10-32' value has the correct format (YYYY-MM-DD) " |
97 | 97 | u"but it is an invalid date."]) |
… |
… |
class ValidationMessagesTest(TestCase):
|
102 | 102 | self.assertRaises(ValidationError, f.clean, 'foo', None) |
103 | 103 | try: |
104 | 104 | f.clean('foo', None) |
105 | | except ValidationError, e: |
| 105 | except ValidationError as e: |
106 | 106 | self.assertEqual(e.messages, [ |
107 | 107 | u"'foo' value has an invalid format. It must be " |
108 | 108 | u"in YYYY-MM-DD HH:MM[:ss[.uuuuuu]][TZ] format."]) |
… |
… |
class ValidationMessagesTest(TestCase):
|
111 | 111 | self.assertRaises(ValidationError, f.clean, '2011-10-32', None) |
112 | 112 | try: |
113 | 113 | f.clean('2011-10-32', None) |
114 | | except ValidationError, e: |
| 114 | except ValidationError as e: |
115 | 115 | self.assertEqual(e.messages, [ |
116 | 116 | u"'2011-10-32' value has the correct format " |
117 | 117 | u"(YYYY-MM-DD) but it is an invalid date."]) |
… |
… |
class ValidationMessagesTest(TestCase):
|
120 | 120 | self.assertRaises(ValidationError, f.clean, '2011-10-32 10:10', None) |
121 | 121 | try: |
122 | 122 | f.clean('2011-10-32 10:10', None) |
123 | | except ValidationError, e: |
| 123 | except ValidationError as e: |
124 | 124 | self.assertEqual(e.messages, [ |
125 | 125 | u"'2011-10-32 10:10' value has the correct format " |
126 | 126 | u"(YYYY-MM-DD HH:MM[:ss[.uuuuuu]][TZ]) " |
… |
… |
class ValidationMessagesTest(TestCase):
|
132 | 132 | self.assertRaises(ValidationError, f.clean, 'foo', None) |
133 | 133 | try: |
134 | 134 | f.clean('foo', None) |
135 | | except ValidationError, e: |
| 135 | except ValidationError as e: |
136 | 136 | self.assertEqual(e.messages, [ |
137 | 137 | u"'foo' value has an invalid format. It must be in " |
138 | 138 | u"HH:MM[:ss[.uuuuuu]] format."]) |
… |
… |
class ValidationMessagesTest(TestCase):
|
140 | 140 | self.assertRaises(ValidationError, f.clean, '25:50', None) |
141 | 141 | try: |
142 | 142 | f.clean('25:50', None) |
143 | | except ValidationError, e: |
| 143 | except ValidationError as e: |
144 | 144 | self.assertEqual(e.messages, [ |
145 | 145 | u"'25:50' value has the correct format " |
146 | 146 | u"(HH:MM[:ss[.uuuuuu]]) but it is an invalid time."]) |
-
diff --git a/tests/modeltests/validation/test_unique.py b/tests/modeltests/validation/test_unique.py
index 3ae981d..e31698d 100644
a
|
b
|
class PerformUniqueChecksTest(TestCase):
|
115 | 115 | p = FlexibleDatePost(title="Django 1.0 is released") |
116 | 116 | try: |
117 | 117 | p.full_clean() |
118 | | except ValidationError, e: |
| 118 | except ValidationError as e: |
119 | 119 | self.fail("unique_for_date checks shouldn't trigger when the associated DateField is None.") |
120 | 120 | |
121 | 121 | p = FlexibleDatePost(slug="Django 1.0") |
122 | 122 | try: |
123 | 123 | p.full_clean() |
124 | | except ValidationError, e: |
| 124 | except ValidationError as e: |
125 | 125 | self.fail("unique_for_year checks shouldn't trigger when the associated DateField is None.") |
126 | 126 | |
127 | 127 | p = FlexibleDatePost(subtitle="Finally") |
128 | 128 | try: |
129 | 129 | p.full_clean() |
130 | | except ValidationError, e: |
| 130 | except ValidationError as e: |
131 | 131 | self.fail("unique_for_month checks shouldn't trigger when the associated DateField is None.") |
132 | 132 | |
133 | 133 | def test_unique_errors(self): |
-
diff --git a/tests/regressiontests/app_loading/tests.py b/tests/regressiontests/app_loading/tests.py
index 5173338..0e66a5a 100644
a
|
b
|
class EggLoadingTest(TestCase):
|
61 | 61 | self.assertRaises(ImportError, load_app, 'broken_app') |
62 | 62 | try: |
63 | 63 | load_app('broken_app') |
64 | | except ImportError, e: |
| 64 | except ImportError as e: |
65 | 65 | # Make sure the message is indicating the actual |
66 | 66 | # problem in the broken app. |
67 | 67 | self.assertTrue("modelz" in e.args[0]) |
-
diff --git a/tests/regressiontests/backends/tests.py b/tests/regressiontests/backends/tests.py
index cfb662e..e2e712a 100644
a
|
b
|
class ThreadTests(TestCase):
|
544 | 544 | connections['default'] = main_thread_connection |
545 | 545 | try: |
546 | 546 | models.Person.objects.get(first_name="John", last_name="Doe") |
547 | | except DatabaseError, e: |
| 547 | except DatabaseError as e: |
548 | 548 | exceptions.append(e) |
549 | 549 | t = threading.Thread(target=runner, args=[connections['default']]) |
550 | 550 | t.start() |
… |
… |
class ThreadTests(TestCase):
|
582 | 582 | def runner2(other_thread_connection): |
583 | 583 | try: |
584 | 584 | other_thread_connection.close() |
585 | | except DatabaseError, e: |
| 585 | except DatabaseError as e: |
586 | 586 | exceptions.add(e) |
587 | 587 | t2 = threading.Thread(target=runner2, args=[connections['default']]) |
588 | 588 | t2.start() |
… |
… |
class ThreadTests(TestCase):
|
599 | 599 | def runner2(other_thread_connection): |
600 | 600 | try: |
601 | 601 | other_thread_connection.close() |
602 | | except DatabaseError, e: |
| 602 | except DatabaseError as e: |
603 | 603 | exceptions.add(e) |
604 | 604 | # Enable thread sharing |
605 | 605 | connections['default'].allow_thread_sharing = True |
-
diff --git a/tests/regressiontests/file_uploads/tests.py b/tests/regressiontests/file_uploads/tests.py
index ffa2017..4e5020d 100644
a
|
b
|
class FileUploadTests(TestCase):
|
303 | 303 | # it raises when there is an attempt to read more than the available bytes: |
304 | 304 | try: |
305 | 305 | client.FakePayload('a').read(2) |
306 | | except Exception, reference_error: |
| 306 | except Exception as reference_error: |
307 | 307 | pass |
308 | 308 | |
309 | 309 | # install the custom handler that tries to access request.POST |
… |
… |
class FileUploadTests(TestCase):
|
311 | 311 | |
312 | 312 | try: |
313 | 313 | response = self.client.post('/file_uploads/upload_errors/', post_data) |
314 | | except reference_error.__class__, err: |
| 314 | except reference_error.__class__ as err: |
315 | 315 | self.failIf( |
316 | 316 | str(err) == str(reference_error), |
317 | 317 | "Caught a repeated exception that'll cause an infinite loop in file uploads." |
318 | 318 | ) |
319 | | except Exception, err: |
| 319 | except Exception as err: |
320 | 320 | # CustomUploadError is the error that should have been raised |
321 | 321 | self.assertEqual(err.__class__, uploadhandler.CustomUploadError) |
322 | 322 | |
… |
… |
class DirectoryCreationTests(unittest.TestCase):
|
373 | 373 | os.chmod(temp_storage.location, 0500) |
374 | 374 | try: |
375 | 375 | self.obj.testfile.save('foo.txt', SimpleUploadedFile('foo.txt', 'x')) |
376 | | except OSError, err: |
| 376 | except OSError as err: |
377 | 377 | self.assertEqual(err.errno, errno.EACCES) |
378 | | except Exception, err: |
| 378 | except Exception as err: |
379 | 379 | self.fail("OSError [Errno %s] not raised." % errno.EACCES) |
380 | 380 | |
381 | 381 | def test_not_a_directory(self): |
… |
… |
class DirectoryCreationTests(unittest.TestCase):
|
385 | 385 | fd.close() |
386 | 386 | try: |
387 | 387 | self.obj.testfile.save('foo.txt', SimpleUploadedFile('foo.txt', 'x')) |
388 | | except IOError, err: |
| 388 | except IOError as err: |
389 | 389 | # The test needs to be done on a specific string as IOError |
390 | 390 | # is raised even without the patch (just not early enough) |
391 | 391 | self.assertEqual(err.args[0], |
-
diff --git a/tests/regressiontests/forms/tests/error_messages.py b/tests/regressiontests/forms/tests/error_messages.py
index b7b4e98..9e1a6c9 100644
a
|
b
|
class AssertFormErrorsMixin(object):
|
15 | 15 | try: |
16 | 16 | the_callable(*args, **kwargs) |
17 | 17 | self.fail("Testing the 'clean' method on %s failed to raise a ValidationError.") |
18 | | except ValidationError, e: |
| 18 | except ValidationError as e: |
19 | 19 | self.assertEqual(e.messages, expected) |
20 | 20 | |
21 | 21 | class FormsErrorMessagesTestCase(TestCase, AssertFormErrorsMixin): |
-
diff --git a/tests/regressiontests/forms/tests/fields.py b/tests/regressiontests/forms/tests/fields.py
index 03e0ff6..138d3af 100644
a
|
b
|
class FieldsTests(SimpleTestCase):
|
660 | 660 | self.assertRaises(ValidationError, f.clean, 'http://qa-dev.w3.org/link-testsuite/http.php?code=405') # Method not allowed |
661 | 661 | try: |
662 | 662 | f.clean('http://www.broken.djangoproject.com') # bad domain |
663 | | except ValidationError, e: |
| 663 | except ValidationError as e: |
664 | 664 | self.assertEqual("[u'This URL appears to be a broken link.']", str(e)) |
665 | 665 | self.assertRaises(ValidationError, f.clean, 'http://qa-dev.w3.org/link-testsuite/http.php?code=400') # good domain, bad page |
666 | 666 | try: |
667 | 667 | f.clean('http://google.com/we-love-microsoft.html') # good domain, bad page |
668 | | except ValidationError, e: |
| 668 | except ValidationError as e: |
669 | 669 | self.assertEqual("[u'This URL appears to be a broken link.']", str(e)) |
670 | 670 | |
671 | 671 | @verify_exists_urls(('http://www.google.com/',)) |
… |
… |
class FieldsTests(SimpleTestCase):
|
719 | 719 | # Valid but non-existent IDN |
720 | 720 | try: |
721 | 721 | f.clean(u'http://broken.עברית.idn.icann.org/') |
722 | | except ValidationError, e: |
| 722 | except ValidationError as e: |
723 | 723 | self.assertEqual("[u'This URL appears to be a broken link.']", str(e)) |
724 | 724 | |
725 | 725 | @verify_exists_urls((u'http://xn--hxargifdar.idn.icann.org/%CE%91%CF%81%CF%87%CE%B9%CE%BA%CE%AE_%CF%83%CE%B5%CE%BB%CE%AF%CE%B4%CE%B1',)) |
-
diff --git a/tests/regressiontests/forms/tests/validators.py b/tests/regressiontests/forms/tests/validators.py
index cadf660..a4cb324 100644
a
|
b
|
class TestFieldWithValidators(TestCase):
|
12 | 12 | self.assertRaises(ValidationError, field.clean, 'not int nor mail') |
13 | 13 | try: |
14 | 14 | field.clean('not int nor mail') |
15 | | except ValidationError, e: |
| 15 | except ValidationError as e: |
16 | 16 | self.assertEqual(2, len(e.messages)) |
-
diff --git a/tests/regressiontests/middleware/tests.py b/tests/regressiontests/middleware/tests.py
index 6a1896a..5e48f8d 100644
a
|
b
|
class CommonMiddlewareTest(TestCase):
|
88 | 88 | request) |
89 | 89 | try: |
90 | 90 | CommonMiddleware().process_request(request) |
91 | | except RuntimeError, e: |
| 91 | except RuntimeError as e: |
92 | 92 | self.assertTrue('end in a slash' in str(e)) |
93 | 93 | settings.DEBUG = False |
94 | 94 | |
… |
… |
class CommonMiddlewareTest(TestCase):
|
202 | 202 | request) |
203 | 203 | try: |
204 | 204 | CommonMiddleware().process_request(request) |
205 | | except RuntimeError, e: |
| 205 | except RuntimeError as e: |
206 | 206 | self.assertTrue('end in a slash' in str(e)) |
207 | 207 | settings.DEBUG = False |
208 | 208 | |
-
diff --git a/tests/regressiontests/middleware_exceptions/tests.py b/tests/regressiontests/middleware_exceptions/tests.py
index ac5f09a..d1acbfd 100644
a
|
b
|
class BaseMiddlewareExceptionTest(TestCase):
|
118 | 118 | def assert_exceptions_handled(self, url, errors, extra_error=None): |
119 | 119 | try: |
120 | 120 | response = self.client.get(url) |
121 | | except TestException, e: |
| 121 | except TestException as e: |
122 | 122 | # Test client intentionally re-raises any exceptions being raised |
123 | 123 | # during request handling. Hence actual testing that exception was |
124 | 124 | # properly handled is done by relying on got_request_exception |
125 | 125 | # signal being sent. |
126 | 126 | pass |
127 | | except Exception, e: |
| 127 | except Exception as e: |
128 | 128 | if type(extra_error) != type(e): |
129 | 129 | self.fail("Unexpected exception: %s" % e) |
130 | 130 | self.assertEqual(len(self.exceptions), len(errors)) |
-
diff --git a/tests/regressiontests/model_fields/tests.py b/tests/regressiontests/model_fields/tests.py
index 8fe67fb..ea1e1c7 100644
a
|
b
|
class BasicFieldTests(test.TestCase):
|
44 | 44 | nullboolean = NullBooleanModel(nbfield=None) |
45 | 45 | try: |
46 | 46 | nullboolean.full_clean() |
47 | | except ValidationError, e: |
| 47 | except ValidationError as e: |
48 | 48 | self.fail("NullBooleanField failed validation with value of None: %s" % e.messages) |
49 | 49 | |
50 | 50 | def test_field_repr(self): |
-
diff --git a/tests/regressiontests/model_forms_regress/tests.py b/tests/regressiontests/model_forms_regress/tests.py
index caf24d3..09da973 100644
a
|
b
|
class InvalidFieldAndFactory(TestCase):
|
333 | 333 | class Meta: |
334 | 334 | model = Person |
335 | 335 | fields = ('name', 'no-field') |
336 | | except FieldError, e: |
| 336 | except FieldError as e: |
337 | 337 | # Make sure the exception contains some reference to the |
338 | 338 | # field responsible for the problem. |
339 | 339 | self.assertTrue('no-field' in e.args[0]) |
-
diff --git a/tests/regressiontests/servers/tests.py b/tests/regressiontests/servers/tests.py
index d237c83..ac92bec 100644
a
|
b
|
class LiveServerViews(LiveServerBase):
|
164 | 164 | """ |
165 | 165 | try: |
166 | 166 | self.urlopen('/') |
167 | | except urllib2.HTTPError, err: |
| 167 | except urllib2.HTTPError as err: |
168 | 168 | self.assertEquals(err.code, 404, 'Expected 404 response') |
169 | 169 | else: |
170 | 170 | self.fail('Expected 404 response') |
-
diff --git a/tests/regressiontests/settings_tests/tests.py b/tests/regressiontests/settings_tests/tests.py
index a2e6c49..4b0ede3 100644
a
|
b
|
class ClassDecoratedTestCase(ClassDecoratedTestCaseSuper):
|
65 | 65 | """ |
66 | 66 | try: |
67 | 67 | super(ClassDecoratedTestCase, self).test_max_recursion_error() |
68 | | except RuntimeError, e: |
| 68 | except RuntimeError as e: |
69 | 69 | self.fail() |
70 | 70 | |
71 | 71 | ClassDecoratedTestCase = override_settings(TEST='override')(ClassDecoratedTestCase) |
-
diff --git a/tests/regressiontests/templates/tests.py b/tests/regressiontests/templates/tests.py
index f74aa75..24dccd6 100644
a
|
b
|
from .response import (TemplateResponseTest, BaseTemplateResponseTest,
|
42 | 42 | |
43 | 43 | try: |
44 | 44 | from .loaders import RenderToStringTest, EggLoaderTest |
45 | | except ImportError, e: |
| 45 | except ImportError as e: |
46 | 46 | if "pkg_resources" in e.message: |
47 | 47 | pass # If setuptools isn't installed, that's fine. Just move on. |
48 | 48 | else: |
… |
… |
class Templates(unittest.TestCase):
|
280 | 280 | try: |
281 | 281 | tmpl = loader.select_template([load_name]) |
282 | 282 | r = tmpl.render(template.Context({})) |
283 | | except template.TemplateDoesNotExist, e: |
| 283 | except template.TemplateDoesNotExist as e: |
284 | 284 | settings.TEMPLATE_DEBUG = old_td |
285 | 285 | self.assertEqual(e.args[0], 'missing.html') |
286 | 286 | self.assertEqual(r, None, 'Template rendering unexpectedly succeeded, produced: ->%r<-' % r) |
… |
… |
class Templates(unittest.TestCase):
|
313 | 313 | r = None |
314 | 314 | try: |
315 | 315 | r = tmpl.render(template.Context({})) |
316 | | except template.TemplateDoesNotExist, e: |
| 316 | except template.TemplateDoesNotExist as e: |
317 | 317 | settings.TEMPLATE_DEBUG = old_td |
318 | 318 | self.assertEqual(e.args[0], 'missing.html') |
319 | 319 | self.assertEqual(r, None, 'Template rendering unexpectedly succeeded, produced: ->%r<-' % r) |
… |
… |
class Templates(unittest.TestCase):
|
340 | 340 | r = None |
341 | 341 | try: |
342 | 342 | r = tmpl.render(template.Context({})) |
343 | | except template.TemplateDoesNotExist, e: |
| 343 | except template.TemplateDoesNotExist as e: |
344 | 344 | self.assertEqual(e.args[0], 'missing.html') |
345 | 345 | self.assertEqual(r, None, 'Template rendering unexpectedly succeeded, produced: ->%r<-' % r) |
346 | 346 | |
… |
… |
class Templates(unittest.TestCase):
|
349 | 349 | tmpl = loader.get_template(load_name) |
350 | 350 | try: |
351 | 351 | tmpl.render(template.Context({})) |
352 | | except template.TemplateDoesNotExist, e: |
| 352 | except template.TemplateDoesNotExist as e: |
353 | 353 | self.assertEqual(e.args[0], 'missing.html') |
354 | 354 | self.assertEqual(r, None, 'Template rendering unexpectedly succeeded, produced: ->%r<-' % r) |
355 | 355 | finally: |
… |
… |
class Templates(unittest.TestCase):
|
393 | 393 | from django.template import Template, TemplateSyntaxError |
394 | 394 | try: |
395 | 395 | t = Template("{% if 1 %}lala{% endblock %}{% endif %}") |
396 | | except TemplateSyntaxError, e: |
| 396 | except TemplateSyntaxError as e: |
397 | 397 | self.assertEqual(e.args[0], "Invalid block tag: 'endblock', expected 'elif', 'else' or 'endif'") |
398 | 398 | |
399 | 399 | def test_templates(self): |
… |
… |
class TemplateTagLoading(unittest.TestCase):
|
1714 | 1714 | self.assertRaises(template.TemplateSyntaxError, template.Template, ttext) |
1715 | 1715 | try: |
1716 | 1716 | template.Template(ttext) |
1717 | | except template.TemplateSyntaxError, e: |
| 1717 | except template.TemplateSyntaxError as e: |
1718 | 1718 | self.assertTrue('ImportError' in e.args[0]) |
1719 | 1719 | self.assertTrue('Xtemplate' in e.args[0]) |
1720 | 1720 | |
… |
… |
class TemplateTagLoading(unittest.TestCase):
|
1726 | 1726 | self.assertRaises(template.TemplateSyntaxError, template.Template, ttext) |
1727 | 1727 | try: |
1728 | 1728 | template.Template(ttext) |
1729 | | except template.TemplateSyntaxError, e: |
| 1729 | except template.TemplateSyntaxError as e: |
1730 | 1730 | self.assertTrue('ImportError' in e.args[0]) |
1731 | 1731 | self.assertTrue('Xtemplate' in e.args[0]) |
1732 | 1732 | |
-
diff --git a/tests/regressiontests/test_client_regress/models.py b/tests/regressiontests/test_client_regress/models.py
index 0f98b2c..72ceff4 100644
a
|
b
|
class AssertContainsTests(TestCase):
|
39 | 39 | |
40 | 40 | try: |
41 | 41 | self.assertContains(response, 'text', status_code=999) |
42 | | except AssertionError, e: |
| 42 | except AssertionError as e: |
43 | 43 | self.assertIn("Couldn't retrieve content: Response code was 200 (expected 999)", str(e)) |
44 | 44 | try: |
45 | 45 | self.assertContains(response, 'text', status_code=999, msg_prefix='abc') |
46 | | except AssertionError, e: |
| 46 | except AssertionError as e: |
47 | 47 | self.assertIn("abc: Couldn't retrieve content: Response code was 200 (expected 999)", str(e)) |
48 | 48 | |
49 | 49 | try: |
50 | 50 | self.assertNotContains(response, 'text', status_code=999) |
51 | | except AssertionError, e: |
| 51 | except AssertionError as e: |
52 | 52 | self.assertIn("Couldn't retrieve content: Response code was 200 (expected 999)", str(e)) |
53 | 53 | try: |
54 | 54 | self.assertNotContains(response, 'text', status_code=999, msg_prefix='abc') |
55 | | except AssertionError, e: |
| 55 | except AssertionError as e: |
56 | 56 | self.assertIn("abc: Couldn't retrieve content: Response code was 200 (expected 999)", str(e)) |
57 | 57 | |
58 | 58 | try: |
59 | 59 | self.assertNotContains(response, 'once') |
60 | | except AssertionError, e: |
| 60 | except AssertionError as e: |
61 | 61 | self.assertIn("Response should not contain 'once'", str(e)) |
62 | 62 | try: |
63 | 63 | self.assertNotContains(response, 'once', msg_prefix='abc') |
64 | | except AssertionError, e: |
| 64 | except AssertionError as e: |
65 | 65 | self.assertIn("abc: Response should not contain 'once'", str(e)) |
66 | 66 | |
67 | 67 | try: |
68 | 68 | self.assertContains(response, 'never', 1) |
69 | | except AssertionError, e: |
| 69 | except AssertionError as e: |
70 | 70 | self.assertIn("Found 0 instances of 'never' in response (expected 1)", str(e)) |
71 | 71 | try: |
72 | 72 | self.assertContains(response, 'never', 1, msg_prefix='abc') |
73 | | except AssertionError, e: |
| 73 | except AssertionError as e: |
74 | 74 | self.assertIn("abc: Found 0 instances of 'never' in response (expected 1)", str(e)) |
75 | 75 | |
76 | 76 | try: |
77 | 77 | self.assertContains(response, 'once', 0) |
78 | | except AssertionError, e: |
| 78 | except AssertionError as e: |
79 | 79 | self.assertIn("Found 1 instances of 'once' in response (expected 0)", str(e)) |
80 | 80 | try: |
81 | 81 | self.assertContains(response, 'once', 0, msg_prefix='abc') |
82 | | except AssertionError, e: |
| 82 | except AssertionError as e: |
83 | 83 | self.assertIn("abc: Found 1 instances of 'once' in response (expected 0)", str(e)) |
84 | 84 | |
85 | 85 | try: |
86 | 86 | self.assertContains(response, 'once', 2) |
87 | | except AssertionError, e: |
| 87 | except AssertionError as e: |
88 | 88 | self.assertIn("Found 1 instances of 'once' in response (expected 2)", str(e)) |
89 | 89 | try: |
90 | 90 | self.assertContains(response, 'once', 2, msg_prefix='abc') |
91 | | except AssertionError, e: |
| 91 | except AssertionError as e: |
92 | 92 | self.assertIn("abc: Found 1 instances of 'once' in response (expected 2)", str(e)) |
93 | 93 | |
94 | 94 | try: |
95 | 95 | self.assertContains(response, 'twice', 1) |
96 | | except AssertionError, e: |
| 96 | except AssertionError as e: |
97 | 97 | self.assertIn("Found 2 instances of 'twice' in response (expected 1)", str(e)) |
98 | 98 | try: |
99 | 99 | self.assertContains(response, 'twice', 1, msg_prefix='abc') |
100 | | except AssertionError, e: |
| 100 | except AssertionError as e: |
101 | 101 | self.assertIn("abc: Found 2 instances of 'twice' in response (expected 1)", str(e)) |
102 | 102 | |
103 | 103 | try: |
104 | 104 | self.assertContains(response, 'thrice') |
105 | | except AssertionError, e: |
| 105 | except AssertionError as e: |
106 | 106 | self.assertIn("Couldn't find 'thrice' in response", str(e)) |
107 | 107 | try: |
108 | 108 | self.assertContains(response, 'thrice', msg_prefix='abc') |
109 | | except AssertionError, e: |
| 109 | except AssertionError as e: |
110 | 110 | self.assertIn("abc: Couldn't find 'thrice' in response", str(e)) |
111 | 111 | |
112 | 112 | try: |
113 | 113 | self.assertContains(response, 'thrice', 3) |
114 | | except AssertionError, e: |
| 114 | except AssertionError as e: |
115 | 115 | self.assertIn("Found 0 instances of 'thrice' in response (expected 3)", str(e)) |
116 | 116 | try: |
117 | 117 | self.assertContains(response, 'thrice', 3, msg_prefix='abc') |
118 | | except AssertionError, e: |
| 118 | except AssertionError as e: |
119 | 119 | self.assertIn("abc: Found 0 instances of 'thrice' in response (expected 3)", str(e)) |
120 | 120 | |
121 | 121 | def test_unicode_contains(self): |
… |
… |
class AssertTemplateUsedTests(TestCase):
|
176 | 176 | |
177 | 177 | try: |
178 | 178 | self.assertTemplateUsed(response, 'GET Template') |
179 | | except AssertionError, e: |
| 179 | except AssertionError as e: |
180 | 180 | self.assertIn("No templates used to render the response", str(e)) |
181 | 181 | |
182 | 182 | try: |
183 | 183 | self.assertTemplateUsed(response, 'GET Template', msg_prefix='abc') |
184 | | except AssertionError, e: |
| 184 | except AssertionError as e: |
185 | 185 | self.assertIn("abc: No templates used to render the response", str(e)) |
186 | 186 | |
187 | 187 | def test_single_context(self): |
… |
… |
class AssertTemplateUsedTests(TestCase):
|
190 | 190 | |
191 | 191 | try: |
192 | 192 | self.assertTemplateNotUsed(response, 'Empty GET Template') |
193 | | except AssertionError, e: |
| 193 | except AssertionError as e: |
194 | 194 | self.assertIn("Template 'Empty GET Template' was used unexpectedly in rendering the response", str(e)) |
195 | 195 | |
196 | 196 | try: |
197 | 197 | self.assertTemplateNotUsed(response, 'Empty GET Template', msg_prefix='abc') |
198 | | except AssertionError, e: |
| 198 | except AssertionError as e: |
199 | 199 | self.assertIn("abc: Template 'Empty GET Template' was used unexpectedly in rendering the response", str(e)) |
200 | 200 | |
201 | 201 | try: |
202 | 202 | self.assertTemplateUsed(response, 'Empty POST Template') |
203 | | except AssertionError, e: |
| 203 | except AssertionError as e: |
204 | 204 | self.assertIn("Template 'Empty POST Template' was not a template used to render the response. Actual template(s) used: Empty GET Template", str(e)) |
205 | 205 | |
206 | 206 | try: |
207 | 207 | self.assertTemplateUsed(response, 'Empty POST Template', msg_prefix='abc') |
208 | | except AssertionError, e: |
| 208 | except AssertionError as e: |
209 | 209 | self.assertIn("abc: Template 'Empty POST Template' was not a template used to render the response. Actual template(s) used: Empty GET Template", str(e)) |
210 | 210 | |
211 | 211 | def test_multiple_context(self): |
… |
… |
class AssertTemplateUsedTests(TestCase):
|
221 | 221 | self.assertContains(response, 'POST data OK') |
222 | 222 | try: |
223 | 223 | self.assertTemplateNotUsed(response, "form_view.html") |
224 | | except AssertionError, e: |
| 224 | except AssertionError as e: |
225 | 225 | self.assertIn("Template 'form_view.html' was used unexpectedly in rendering the response", str(e)) |
226 | 226 | |
227 | 227 | try: |
228 | 228 | self.assertTemplateNotUsed(response, 'base.html') |
229 | | except AssertionError, e: |
| 229 | except AssertionError as e: |
230 | 230 | self.assertIn("Template 'base.html' was used unexpectedly in rendering the response", str(e)) |
231 | 231 | |
232 | 232 | try: |
233 | 233 | self.assertTemplateUsed(response, "Valid POST Template") |
234 | | except AssertionError, e: |
| 234 | except AssertionError as e: |
235 | 235 | self.assertIn("Template 'Valid POST Template' was not a template used to render the response. Actual template(s) used: form_view.html, base.html", str(e)) |
236 | 236 | |
237 | 237 | class AssertRedirectsTests(TestCase): |
… |
… |
class AssertRedirectsTests(TestCase):
|
241 | 241 | response = self.client.get('/test_client/permanent_redirect_view/') |
242 | 242 | try: |
243 | 243 | self.assertRedirects(response, '/test_client/get_view/') |
244 | | except AssertionError, e: |
| 244 | except AssertionError as e: |
245 | 245 | self.assertIn("Response didn't redirect as expected: Response code was 301 (expected 302)", str(e)) |
246 | 246 | |
247 | 247 | try: |
248 | 248 | self.assertRedirects(response, '/test_client/get_view/', msg_prefix='abc') |
249 | | except AssertionError, e: |
| 249 | except AssertionError as e: |
250 | 250 | self.assertIn("abc: Response didn't redirect as expected: Response code was 301 (expected 302)", str(e)) |
251 | 251 | |
252 | 252 | def test_lost_query(self): |
… |
… |
class AssertRedirectsTests(TestCase):
|
254 | 254 | response = self.client.get('/test_client/redirect_view/', {'var': 'value'}) |
255 | 255 | try: |
256 | 256 | self.assertRedirects(response, '/test_client/get_view/') |
257 | | except AssertionError, e: |
| 257 | except AssertionError as e: |
258 | 258 | self.assertIn("Response redirected to 'http://testserver/test_client/get_view/?var=value', expected 'http://testserver/test_client/get_view/'", str(e)) |
259 | 259 | |
260 | 260 | try: |
261 | 261 | self.assertRedirects(response, '/test_client/get_view/', msg_prefix='abc') |
262 | | except AssertionError, e: |
| 262 | except AssertionError as e: |
263 | 263 | self.assertIn("abc: Response redirected to 'http://testserver/test_client/get_view/?var=value', expected 'http://testserver/test_client/get_view/'", str(e)) |
264 | 264 | |
265 | 265 | def test_incorrect_target(self): |
… |
… |
class AssertRedirectsTests(TestCase):
|
268 | 268 | try: |
269 | 269 | # Should redirect to get_view |
270 | 270 | self.assertRedirects(response, '/test_client/some_view/') |
271 | | except AssertionError, e: |
| 271 | except AssertionError as e: |
272 | 272 | self.assertIn("Response didn't redirect as expected: Response code was 301 (expected 302)", str(e)) |
273 | 273 | |
274 | 274 | def test_target_page(self): |
… |
… |
class AssertRedirectsTests(TestCase):
|
277 | 277 | try: |
278 | 278 | # The redirect target responds with a 301 code, not 200 |
279 | 279 | self.assertRedirects(response, 'http://testserver/test_client/permanent_redirect_view/') |
280 | | except AssertionError, e: |
| 280 | except AssertionError as e: |
281 | 281 | self.assertIn("Couldn't retrieve redirection page '/test_client/permanent_redirect_view/': response code was 301 (expected 200)", str(e)) |
282 | 282 | |
283 | 283 | try: |
284 | 284 | # The redirect target responds with a 301 code, not 200 |
285 | 285 | self.assertRedirects(response, 'http://testserver/test_client/permanent_redirect_view/', msg_prefix='abc') |
286 | | except AssertionError, e: |
| 286 | except AssertionError as e: |
287 | 287 | self.assertIn("abc: Couldn't retrieve redirection page '/test_client/permanent_redirect_view/': response code was 301 (expected 200)", str(e)) |
288 | 288 | |
289 | 289 | def test_redirect_chain(self): |
… |
… |
class AssertRedirectsTests(TestCase):
|
386 | 386 | response = self.client.get('/test_client/get_view/', follow=True) |
387 | 387 | try: |
388 | 388 | self.assertRedirects(response, '/test_client/get_view/') |
389 | | except AssertionError, e: |
| 389 | except AssertionError as e: |
390 | 390 | self.assertIn("Response didn't redirect as expected: Response code was 200 (expected 302)", str(e)) |
391 | 391 | |
392 | 392 | try: |
393 | 393 | self.assertRedirects(response, '/test_client/get_view/', msg_prefix='abc') |
394 | | except AssertionError, e: |
| 394 | except AssertionError as e: |
395 | 395 | self.assertIn("abc: Response didn't redirect as expected: Response code was 200 (expected 302)", str(e)) |
396 | 396 | |
397 | 397 | def test_redirect_on_non_redirect_page(self): |
… |
… |
class AssertRedirectsTests(TestCase):
|
400 | 400 | response = self.client.get('/test_client/get_view/') |
401 | 401 | try: |
402 | 402 | self.assertRedirects(response, '/test_client/get_view/') |
403 | | except AssertionError, e: |
| 403 | except AssertionError as e: |
404 | 404 | self.assertIn("Response didn't redirect as expected: Response code was 200 (expected 302)", str(e)) |
405 | 405 | |
406 | 406 | try: |
407 | 407 | self.assertRedirects(response, '/test_client/get_view/', msg_prefix='abc') |
408 | | except AssertionError, e: |
| 408 | except AssertionError as e: |
409 | 409 | self.assertIn("abc: Response didn't redirect as expected: Response code was 200 (expected 302)", str(e)) |
410 | 410 | |
411 | 411 | |
… |
… |
class AssertFormErrorTests(TestCase):
|
425 | 425 | |
426 | 426 | try: |
427 | 427 | self.assertFormError(response, 'wrong_form', 'some_field', 'Some error.') |
428 | | except AssertionError, e: |
| 428 | except AssertionError as e: |
429 | 429 | self.assertIn("The form 'wrong_form' was not used to render the response", str(e)) |
430 | 430 | try: |
431 | 431 | self.assertFormError(response, 'wrong_form', 'some_field', 'Some error.', msg_prefix='abc') |
432 | | except AssertionError, e: |
| 432 | except AssertionError as e: |
433 | 433 | self.assertIn("abc: The form 'wrong_form' was not used to render the response", str(e)) |
434 | 434 | |
435 | 435 | def test_unknown_field(self): |
… |
… |
class AssertFormErrorTests(TestCase):
|
447 | 447 | |
448 | 448 | try: |
449 | 449 | self.assertFormError(response, 'form', 'some_field', 'Some error.') |
450 | | except AssertionError, e: |
| 450 | except AssertionError as e: |
451 | 451 | self.assertIn("The form 'form' in context 0 does not contain the field 'some_field'", str(e)) |
452 | 452 | try: |
453 | 453 | self.assertFormError(response, 'form', 'some_field', 'Some error.', msg_prefix='abc') |
454 | | except AssertionError, e: |
| 454 | except AssertionError as e: |
455 | 455 | self.assertIn("abc: The form 'form' in context 0 does not contain the field 'some_field'", str(e)) |
456 | 456 | |
457 | 457 | def test_noerror_field(self): |
… |
… |
class AssertFormErrorTests(TestCase):
|
469 | 469 | |
470 | 470 | try: |
471 | 471 | self.assertFormError(response, 'form', 'value', 'Some error.') |
472 | | except AssertionError, e: |
| 472 | except AssertionError as e: |
473 | 473 | self.assertIn("The field 'value' on form 'form' in context 0 contains no errors", str(e)) |
474 | 474 | try: |
475 | 475 | self.assertFormError(response, 'form', 'value', 'Some error.', msg_prefix='abc') |
476 | | except AssertionError, e: |
| 476 | except AssertionError as e: |
477 | 477 | self.assertIn("abc: The field 'value' on form 'form' in context 0 contains no errors", str(e)) |
478 | 478 | |
479 | 479 | def test_unknown_error(self): |
… |
… |
class AssertFormErrorTests(TestCase):
|
491 | 491 | |
492 | 492 | try: |
493 | 493 | self.assertFormError(response, 'form', 'email', 'Some error.') |
494 | | except AssertionError, e: |
| 494 | except AssertionError as e: |
495 | 495 | self.assertIn("The field 'email' on form 'form' in context 0 does not contain the error 'Some error.' (actual errors: [u'Enter a valid e-mail address.'])", str(e)) |
496 | 496 | try: |
497 | 497 | self.assertFormError(response, 'form', 'email', 'Some error.', msg_prefix='abc') |
498 | | except AssertionError, e: |
| 498 | except AssertionError as e: |
499 | 499 | self.assertIn("abc: The field 'email' on form 'form' in context 0 does not contain the error 'Some error.' (actual errors: [u'Enter a valid e-mail address.'])", str(e)) |
500 | 500 | |
501 | 501 | def test_unknown_nonfield_error(self): |
… |
… |
class AssertFormErrorTests(TestCase):
|
516 | 516 | |
517 | 517 | try: |
518 | 518 | self.assertFormError(response, 'form', None, 'Some error.') |
519 | | except AssertionError, e: |
| 519 | except AssertionError as e: |
520 | 520 | self.assertIn("The form 'form' in context 0 does not contain the non-field error 'Some error.' (actual errors: )", str(e)) |
521 | 521 | try: |
522 | 522 | self.assertFormError(response, 'form', None, 'Some error.', msg_prefix='abc') |
523 | | except AssertionError, e: |
| 523 | except AssertionError as e: |
524 | 524 | self.assertIn("abc: The form 'form' in context 0 does not contain the non-field error 'Some error.' (actual errors: )", str(e)) |
525 | 525 | |
526 | 526 | class LoginTests(TestCase): |
… |
… |
class ContextTests(TestCase):
|
677 | 677 | try: |
678 | 678 | response.context['does-not-exist'] |
679 | 679 | self.fail('Should not be able to retrieve non-existent key') |
680 | | except KeyError, e: |
| 680 | except KeyError as e: |
681 | 681 | self.assertEqual(e.args[0], 'does-not-exist') |
682 | 682 | |
683 | 683 | def test_inherited_context(self): |
… |
… |
class ContextTests(TestCase):
|
693 | 693 | try: |
694 | 694 | response.context['does-not-exist'] |
695 | 695 | self.fail('Should not be able to retrieve non-existent key') |
696 | | except KeyError, e: |
| 696 | except KeyError as e: |
697 | 697 | self.assertEqual(e.args[0], 'does-not-exist') |
698 | 698 | |
699 | 699 | def test_15368(self): |
-
diff --git a/tests/regressiontests/urlpatterns_reverse/tests.py b/tests/regressiontests/urlpatterns_reverse/tests.py
index a1c9244..d25235e 100644
a
|
b
|
class URLPatternReverse(TestCase):
|
161 | 161 | for name, expected, args, kwargs in test_data: |
162 | 162 | try: |
163 | 163 | got = reverse(name, args=args, kwargs=kwargs) |
164 | | except NoReverseMatch, e: |
| 164 | except NoReverseMatch as e: |
165 | 165 | self.assertEqual(expected, NoReverseMatch) |
166 | 166 | else: |
167 | 167 | self.assertEqual(got, expected) |
… |
… |
class ResolverTests(unittest.TestCase):
|
207 | 207 | try: |
208 | 208 | resolve('/included/non-existent-url', urlconf=urls) |
209 | 209 | self.fail('resolve did not raise a 404') |
210 | | except Resolver404, e: |
| 210 | except Resolver404 as e: |
211 | 211 | # make sure we at least matched the root ('/') url resolver: |
212 | 212 | self.assertTrue('tried' in e.args[0]) |
213 | 213 | tried = e.args[0]['tried'] |