diff --git a/django/conf/urls/__init__.py b/django/conf/urls/__init__.py index fff5e35582..9f500ae8ba 100644 --- a/django/conf/urls/__init__.py +++ b/django/conf/urls/__init__.py @@ -50,7 +50,7 @@ def patterns(prefix, *args): return pattern_list def url(regex, view, kwargs=None, name=None, prefix=''): - if isinstance(view, (list,tuple)): + if isinstance(view, (list, tuple)): # For include(...) processing. urlconf_module, app_name, namespace = view return RegexURLResolver(regex, urlconf_module, kwargs, app_name=app_name, namespace=namespace) diff --git a/django/contrib/admin/templatetags/admin_list.py b/django/contrib/admin/templatetags/admin_list.py index 9941ca4c06..f58c5745ea 100644 --- a/django/contrib/admin/templatetags/admin_list.py +++ b/django/contrib/admin/templatetags/admin_list.py @@ -26,7 +26,7 @@ register = Library() DOT = '.' @register.simple_tag -def paginator_number(cl,i): +def paginator_number(cl, i): """ Generates an individual page index link in a paginated list. """ diff --git a/django/contrib/auth/tests/urls.py b/django/contrib/auth/tests/urls.py index 48fb8f3587..c6349a57d1 100644 --- a/django/contrib/auth/tests/urls.py +++ b/django/contrib/auth/tests/urls.py @@ -27,13 +27,13 @@ def auth_processor_no_attr_access(request): RequestContext(request, {}, processors=[context_processors.auth])) # *After* rendering, we check whether the session was accessed return render_to_response('context_processors/auth_attrs_test_access.html', - {'session_accessed':request.session.accessed}) + {'session_accessed': request.session.accessed}) def auth_processor_attr_access(request): render_to_response('context_processors/auth_attrs_access.html', RequestContext(request, {}, processors=[context_processors.auth])) return render_to_response('context_processors/auth_attrs_test_access.html', - {'session_accessed':request.session.accessed}) + {'session_accessed': request.session.accessed}) def auth_processor_user(request): return render_to_response('context_processors/auth_attrs_user.html', diff --git a/django/contrib/flatpages/tests/test_csrf.py b/django/contrib/flatpages/tests/test_csrf.py index d8f82b5d43..4506433195 100644 --- a/django/contrib/flatpages/tests/test_csrf.py +++ b/django/contrib/flatpages/tests/test_csrf.py @@ -45,7 +45,7 @@ class FlatpageCSRFTests(TestCase): response = self.client.get('/flatpage_root/sekrit/') self.assertRedirects(response, '/accounts/login/?next=/flatpage_root/sekrit/') User.objects.create_user('testuser', 'test@example.com', 's3krit') - self.client.login(username='testuser',password='s3krit') + self.client.login(username='testuser', password='s3krit') response = self.client.get('/flatpage_root/sekrit/') self.assertEqual(response.status_code, 200) self.assertContains(response, "
Isn't it sekrit!
") diff --git a/django/contrib/flatpages/tests/test_middleware.py b/django/contrib/flatpages/tests/test_middleware.py index 79e046b7a1..8f1becb0b2 100644 --- a/django/contrib/flatpages/tests/test_middleware.py +++ b/django/contrib/flatpages/tests/test_middleware.py @@ -43,7 +43,7 @@ class FlatpageMiddlewareTests(TestCase): response = self.client.get('/flatpage_root/sekrit/') self.assertRedirects(response, '/accounts/login/?next=/flatpage_root/sekrit/') User.objects.create_user('testuser', 'test@example.com', 's3krit') - self.client.login(username='testuser',password='s3krit') + self.client.login(username='testuser', password='s3krit') response = self.client.get('/flatpage_root/sekrit/') self.assertEqual(response.status_code, 200) self.assertContains(response, "Isn't it sekrit!
") @@ -65,7 +65,7 @@ class FlatpageMiddlewareTests(TestCase): response = self.client.get('/sekrit/') self.assertRedirects(response, '/accounts/login/?next=/sekrit/') User.objects.create_user('testuser', 'test@example.com', 's3krit') - self.client.login(username='testuser',password='s3krit') + self.client.login(username='testuser', password='s3krit') response = self.client.get('/sekrit/') self.assertEqual(response.status_code, 200) self.assertContains(response, "Isn't it sekrit!
") diff --git a/django/contrib/flatpages/tests/test_views.py b/django/contrib/flatpages/tests/test_views.py index 0448b21227..1f7093bb12 100644 --- a/django/contrib/flatpages/tests/test_views.py +++ b/django/contrib/flatpages/tests/test_views.py @@ -43,7 +43,7 @@ class FlatpageViewTests(TestCase): response = self.client.get('/flatpage_root/sekrit/') self.assertRedirects(response, '/accounts/login/?next=/flatpage_root/sekrit/') User.objects.create_user('testuser', 'test@example.com', 's3krit') - self.client.login(username='testuser',password='s3krit') + self.client.login(username='testuser', password='s3krit') response = self.client.get('/flatpage_root/sekrit/') self.assertEqual(response.status_code, 200) self.assertContains(response, "Isn't it sekrit!
") diff --git a/django/contrib/formtools/tests/tests.py b/django/contrib/formtools/tests/tests.py index f3e83db0c6..e15a310629 100644 --- a/django/contrib/formtools/tests/tests.py +++ b/django/contrib/formtools/tests/tests.py @@ -119,7 +119,7 @@ class PreviewTests(TestCase): ``bool1``. We need to make sure the hashes are the same in both cases. """ - self.test_data.update({'stage':2}) + self.test_data.update({'stage': 2}) hash = self.preview.security_hash(None, TestForm(self.test_data)) self.test_data.update({'hash': hash, 'bool1': 'False'}) with warnings.catch_warnings(record=True): @@ -133,7 +133,7 @@ class PreviewTests(TestCase): """ # Pass strings for form submittal and add stage variable to # show we previously saw first stage of the form. - self.test_data.update({'stage':2}) + self.test_data.update({'stage': 2}) response = self.client.post('/preview/', self.test_data) self.assertNotEqual(response.content, success_string_encoded) hash = utils.form_hmac(TestForm(self.test_data)) @@ -148,7 +148,7 @@ class PreviewTests(TestCase): """ # Pass strings for form submittal and add stage variable to # show we previously saw first stage of the form. - self.test_data.update({'stage':2}) + self.test_data.update({'stage': 2}) response = self.client.post('/preview/', self.test_data) self.assertEqual(response.status_code, 200) self.assertNotEqual(response.content, success_string_encoded) diff --git a/django/contrib/gis/admin/widgets.py b/django/contrib/gis/admin/widgets.py index 9f89a8b480..8533bdc044 100644 --- a/django/contrib/gis/admin/widgets.py +++ b/django/contrib/gis/admin/widgets.py @@ -53,7 +53,7 @@ class OpenLayersWidget(Textarea): self.params['name'] = name # note: we must switch out dashes for underscores since js # functions are created using the module variable - js_safe_name = self.params['name'].replace('-','_') + js_safe_name = self.params['name'].replace('-', '_') self.params['module'] = 'geodjango_%s' % js_safe_name if value: diff --git a/django/contrib/gis/db/models/query.py b/django/contrib/gis/db/models/query.py index 149827af5d..f418fc8f00 100644 --- a/django/contrib/gis/db/models/query.py +++ b/django/contrib/gis/db/models/query.py @@ -286,7 +286,7 @@ class GeoQuerySet(QuerySet): Reverses the coordinate order of the geometry, and attaches as a `reverse` attribute on each element of this GeoQuerySet. """ - s = {'select_field' : GeomField(),} + s = {'select_field': GeomField()} kwargs.setdefault('model_att', 'reverse_geom') if connections[self.db].ops.oracle: s['geo_field_type'] = LineStringField @@ -733,7 +733,7 @@ class GeoQuerySet(QuerySet): DRY routine for setting up a GeoQuerySet method that attaches a Geometry attribute (e.g., `centroid`, `point_on_surface`). """ - s = {'select_field' : GeomField(),} + s = {'select_field': GeomField()} if connections[self.db].ops.oracle: s['procedure_fmt'] = '%(geo_col)s,%(tolerance)s' s['procedure_args'] = {'tolerance' : tolerance} diff --git a/django/contrib/gis/forms/widgets.py b/django/contrib/gis/forms/widgets.py index d01e69077c..2609ac16fd 100644 --- a/django/contrib/gis/forms/widgets.py +++ b/django/contrib/gis/forms/widgets.py @@ -68,7 +68,7 @@ class BaseGeometryWidget(Widget): context = self.build_attrs(attrs, name=name, - module='geodjango_%s' % name.replace('-','_'), # JS-safe + module='geodjango_%s' % name.replace('-', '_'), # JS-safe serialized=self.serialize(value), geom_type=gdal.OGRGeomType(self.attrs['geom_type']), STATIC_URL=settings.STATIC_URL, diff --git a/django/contrib/gis/gdal/tests/test_ds.py b/django/contrib/gis/gdal/tests/test_ds.py index c25bdfae02..a2c0e9e133 100644 --- a/django/contrib/gis/gdal/tests/test_ds.py +++ b/django/contrib/gis/gdal/tests/test_ds.py @@ -12,20 +12,20 @@ if HAS_GDAL: # List of acceptable data sources. ds_list = ( TestDS('test_point', nfeat=5, nfld=3, geom='POINT', gtype=1, driver='ESRI Shapefile', - fields={'dbl' : OFTReal, 'int' : OFTInteger, 'str' : OFTString,}, - extent=(-1.35011,0.166623,-0.524093,0.824508), # Got extent from QGIS + fields={'dbl': OFTReal, 'int': OFTInteger, 'str': OFTString}, + extent=(-1.35011, 0.166623, -0.524093, 0.824508), # Got extent from QGIS srs_wkt='GEOGCS["GCS_WGS_1984",DATUM["WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]', - field_values={'dbl' : [float(i) for i in range(1, 6)], 'int' : list(range(1, 6)), 'str' : [str(i) for i in range(1, 6)]}, + field_values={'dbl': [float(i) for i in range(1, 6)], 'int': list(range(1, 6)), 'str': [str(i) for i in range(1, 6)]}, fids=range(5)), TestDS('test_vrt', ext='vrt', nfeat=3, nfld=3, geom='POINT', gtype='Point25D', driver='VRT', - fields={'POINT_X' : OFTString, 'POINT_Y' : OFTString, 'NUM' : OFTString}, # VRT uses CSV, which all types are OFTString. + fields={'POINT_X': OFTString, 'POINT_Y': OFTString, 'NUM': OFTString}, # VRT uses CSV, which all types are OFTString. extent=(1.0, 2.0, 100.0, 523.5), # Min/Max from CSV - field_values={'POINT_X' : ['1.0', '5.0', '100.0'], 'POINT_Y' : ['2.0', '23.0', '523.5'], 'NUM' : ['5', '17', '23']}, - fids=range(1,4)), + field_values={'POINT_X': ['1.0', '5.0', '100.0'], 'POINT_Y': ['2.0', '23.0', '523.5'], 'NUM': ['5', '17', '23']}, + fids=range(1, 4)), TestDS('test_poly', nfeat=3, nfld=3, geom='POLYGON', gtype=3, driver='ESRI Shapefile', - fields={'float' : OFTReal, 'int' : OFTInteger, 'str' : OFTString,}, - extent=(-1.01513,-0.558245,0.161876,0.839637), # Got extent from QGIS + fields={'float': OFTReal, 'int': OFTInteger, 'str': OFTString}, + extent=(-1.01513, -0.558245, 0.161876, 0.839637), # Got extent from QGIS srs_wkt='GEOGCS["GCS_WGS_1984",DATUM["WGS_1984",SPHEROID["WGS_1984",6378137,298.257223563]],PRIMEM["Greenwich",0],UNIT["Degree",0.017453292519943295]]'), ) diff --git a/django/contrib/gis/gdal/tests/test_srs.py b/django/contrib/gis/gdal/tests/test_srs.py index 33941458c8..39cccf8440 100644 --- a/django/contrib/gis/gdal/tests/test_srs.py +++ b/django/contrib/gis/gdal/tests/test_srs.py @@ -18,20 +18,20 @@ srlist = (TestSRS('GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,29 proj='+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs ', epsg=4326, projected=False, geographic=True, local=False, lin_name='unknown', ang_name='degree', lin_units=1.0, ang_units=0.0174532925199, - auth={'GEOGCS' : ('EPSG', '4326'), 'spheroid' : ('EPSG', '7030')}, - attr=(('DATUM', 'WGS_1984'), (('SPHEROID', 1), '6378137'),('primem|authority', 'EPSG'),), + auth={'GEOGCS': ('EPSG', '4326'), 'spheroid': ('EPSG', '7030')}, + attr=(('DATUM', 'WGS_1984'), (('SPHEROID', 1), '6378137'), ('primem|authority', 'EPSG'),), ), TestSRS('PROJCS["NAD83 / Texas South Central",GEOGCS["NAD83",DATUM["North_American_Datum_1983",SPHEROID["GRS 1980",6378137,298.257222101,AUTHORITY["EPSG","7019"]],AUTHORITY["EPSG","6269"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4269"]],PROJECTION["Lambert_Conformal_Conic_2SP"],PARAMETER["standard_parallel_1",30.28333333333333],PARAMETER["standard_parallel_2",28.38333333333333],PARAMETER["latitude_of_origin",27.83333333333333],PARAMETER["central_meridian",-99],PARAMETER["false_easting",600000],PARAMETER["false_northing",4000000],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AUTHORITY["EPSG","32140"]]', proj=None, epsg=32140, projected=True, geographic=False, local=False, lin_name='metre', ang_name='degree', lin_units=1.0, ang_units=0.0174532925199, - auth={'PROJCS' : ('EPSG', '32140'), 'spheroid' : ('EPSG', '7019'), 'unit' : ('EPSG', '9001'),}, - attr=(('DATUM', 'North_American_Datum_1983'),(('SPHEROID', 2), '298.257222101'),('PROJECTION','Lambert_Conformal_Conic_2SP'),), + auth={'PROJCS': ('EPSG', '32140'), 'spheroid': ('EPSG', '7019'), 'unit': ('EPSG', '9001')}, + attr=(('DATUM', 'North_American_Datum_1983'), (('SPHEROID', 2), '298.257222101'), ('PROJECTION', 'Lambert_Conformal_Conic_2SP'),), ), TestSRS('PROJCS["NAD_1983_StatePlane_Texas_South_Central_FIPS_4204_Feet",GEOGCS["GCS_North_American_1983",DATUM["North_American_Datum_1983",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Lambert_Conformal_Conic_2SP"],PARAMETER["False_Easting",1968500.0],PARAMETER["False_Northing",13123333.33333333],PARAMETER["Central_Meridian",-99.0],PARAMETER["Standard_Parallel_1",28.38333333333333],PARAMETER["Standard_Parallel_2",30.28333333333334],PARAMETER["Latitude_Of_Origin",27.83333333333333],UNIT["Foot_US",0.3048006096012192]]', proj=None, epsg=None, projected=True, geographic=False, local=False, lin_name='Foot_US', ang_name='Degree', lin_units=0.3048006096012192, ang_units=0.0174532925199, - auth={'PROJCS' : (None, None),}, - attr=(('PROJCS|GeOgCs|spheroid', 'GRS_1980'),(('projcs', 9), 'UNIT'), (('projcs', 11), None),), + auth={'PROJCS': (None, None)}, + attr=(('PROJCS|GeOgCs|spheroid', 'GRS_1980'), (('projcs', 9), 'UNIT'), (('projcs', 11), None),), ), # This is really ESRI format, not WKT -- but the import should work the same TestSRS('LOCAL_CS["Non-Earth (Meter)",LOCAL_DATUM["Local Datum",0],UNIT["Meter",1.0],AXIS["X",EAST],AXIS["Y",NORTH]]', @@ -46,7 +46,7 @@ well_known = (TestSRS('GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",637813 TestSRS('GEOGCS["WGS 72",DATUM["WGS_1972",SPHEROID["WGS 72",6378135,298.26,AUTHORITY["EPSG","7043"]],AUTHORITY["EPSG","6322"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4322"]]', wk='WGS72', name='WGS 72', attrs=(('GEOGCS|AUTHORITY', 1, '4322'), ('SPHEROID', 'WGS 72'))), TestSRS('GEOGCS["NAD27",DATUM["North_American_Datum_1927",SPHEROID["Clarke 1866",6378206.4,294.9786982138982,AUTHORITY["EPSG","7008"]],AUTHORITY["EPSG","6267"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4267"]]', wk='NAD27', name='NAD27', attrs=(('GEOGCS|AUTHORITY', 1, '4267'), ('SPHEROID', 'Clarke 1866'))), TestSRS('GEOGCS["NAD83",DATUM["North_American_Datum_1983",SPHEROID["GRS 1980",6378137,298.257222101,AUTHORITY["EPSG","7019"]],AUTHORITY["EPSG","6269"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4269"]]', wk='NAD83', name='NAD83', attrs=(('GEOGCS|AUTHORITY', 1, '4269'), ('SPHEROID', 'GRS 1980'))), - TestSRS('PROJCS["NZGD49 / Karamea Circuit",GEOGCS["NZGD49",DATUM["New_Zealand_Geodetic_Datum_1949",SPHEROID["International 1924",6378388,297,AUTHORITY["EPSG","7022"]],TOWGS84[59.47,-5.04,187.44,0.47,-0.1,1.024,-4.5993],AUTHORITY["EPSG","6272"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4272"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",-41.28991152777778],PARAMETER["central_meridian",172.1090281944444],PARAMETER["scale_factor",1],PARAMETER["false_easting",300000],PARAMETER["false_northing",700000],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AUTHORITY["EPSG","27216"]]', wk='EPSG:27216', name='NZGD49 / Karamea Circuit', attrs=(('PROJECTION','Transverse_Mercator'), ('SPHEROID', 'International 1924'))), + TestSRS('PROJCS["NZGD49 / Karamea Circuit",GEOGCS["NZGD49",DATUM["New_Zealand_Geodetic_Datum_1949",SPHEROID["International 1924",6378388,297,AUTHORITY["EPSG","7022"]],TOWGS84[59.47,-5.04,187.44,0.47,-0.1,1.024,-4.5993],AUTHORITY["EPSG","6272"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4272"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",-41.28991152777778],PARAMETER["central_meridian",172.1090281944444],PARAMETER["scale_factor",1],PARAMETER["false_easting",300000],PARAMETER["false_northing",700000],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AUTHORITY["EPSG","27216"]]', wk='EPSG:27216', name='NZGD49 / Karamea Circuit', attrs=(('PROJECTION', 'Transverse_Mercator'), ('SPHEROID', 'International 1924'))), ) bad_srlist = ('Foobar', 'OOJCS["NAD83 / Texas South Central",GEOGCS["NAD83",DATUM["North_American_Datum_1983",SPHEROID["GRS 1980",6378137,298.257222101,AUTHORITY["EPSG","7019"]],AUTHORITY["EPSG","6269"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4269"]],PROJECTION["Lambert_Conformal_Conic_2SP"],PARAMETER["standard_parallel_1",30.28333333333333],PARAMETER["standard_parallel_2",28.38333333333333],PARAMETER["latitude_of_origin",27.83333333333333],PARAMETER["central_meridian",-99],PARAMETER["false_easting",600000],PARAMETER["false_northing",4000000],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AUTHORITY["EPSG","32140"]]',) diff --git a/django/contrib/gis/geos/mutable_list.py b/django/contrib/gis/geos/mutable_list.py index 42d0d76563..87ae6dd8f3 100644 --- a/django/contrib/gis/geos/mutable_list.py +++ b/django/contrib/gis/geos/mutable_list.py @@ -223,7 +223,7 @@ class ListMixin(object): def sort(self, cmp=None, key=None, reverse=False): "Standard list sort method" if key: - temp = [(key(v),v) for v in self] + temp = [(key(v), v) for v in self] temp.sort(key=lambda x: x[0], reverse=reverse) self[:] = [v[1] for v in temp] else: diff --git a/django/contrib/gis/geos/tests/test_geos.py b/django/contrib/gis/geos/tests/test_geos.py index c691120c98..8e1552539f 100644 --- a/django/contrib/gis/geos/tests/test_geos.py +++ b/django/contrib/gis/geos/tests/test_geos.py @@ -757,17 +757,17 @@ class GEOSTest(unittest.TestCase, TestDataMixin): "Testing three-dimensional geometries." # Testing a 3D Point pnt = Point(2, 3, 8) - self.assertEqual((2.,3.,8.), pnt.coords) - self.assertRaises(TypeError, pnt.set_coords, (1.,2.)) - pnt.coords = (1.,2.,3.) - self.assertEqual((1.,2.,3.), pnt.coords) + self.assertEqual((2., 3., 8.), pnt.coords) + self.assertRaises(TypeError, pnt.set_coords, (1., 2.)) + pnt.coords = (1., 2., 3.) + self.assertEqual((1., 2., 3.), pnt.coords) # Testing a 3D LineString ls = LineString((2., 3., 8.), (50., 250., -117.)) - self.assertEqual(((2.,3.,8.), (50.,250.,-117.)), ls.tuple) - self.assertRaises(TypeError, ls.__setitem__, 0, (1.,2.)) - ls[0] = (1.,2.,3.) - self.assertEqual((1.,2.,3.), ls[0]) + self.assertEqual(((2., 3., 8.), (50., 250., -117.)), ls.tuple) + self.assertRaises(TypeError, ls.__setitem__, 0, (1., 2.)) + ls[0] = (1., 2., 3.) + self.assertEqual((1., 2., 3.), ls[0]) def test_distance(self): "Testing the distance() function." diff --git a/django/contrib/gis/geos/tests/test_geos_mutation.py b/django/contrib/gis/geos/tests/test_geos_mutation.py index 0be82f821b..2db2940819 100644 --- a/django/contrib/gis/geos/tests/test_geos_mutation.py +++ b/django/contrib/gis/geos/tests/test_geos_mutation.py @@ -14,7 +14,7 @@ if HAS_GEOS: if HAS_GEOS: def api_get_distance(x): - return x.distance(Point(-200,-200)) + return x.distance(Point(-200, -200)) def api_get_buffer(x): return x.buffer(10) @@ -69,24 +69,24 @@ class GEOSMutationTest(unittest.TestCase): def test00_GEOSIndexException(self): 'Testing Geometry GEOSIndexError' - p = Point(1,2) - for i in range(-2,2): + p = Point(1, 2) + for i in range(-2, 2): p._checkindex(i) self.assertRaises(GEOSIndexError, p._checkindex, 2) self.assertRaises(GEOSIndexError, p._checkindex, -3) def test01_PointMutations(self): 'Testing Point mutations' - for p in (Point(1,2,3), fromstr('POINT (1 2 3)')): + for p in (Point(1, 2, 3), fromstr('POINT (1 2 3)')): self.assertEqual(p._get_single_external(1), 2.0, 'Point _get_single_external') # _set_single - p._set_single(0,100) - self.assertEqual(p.coords, (100.0,2.0,3.0), 'Point _set_single') + p._set_single(0, 100) + self.assertEqual(p.coords, (100.0, 2.0, 3.0), 'Point _set_single') # _set_list - p._set_list(2,(50,3141)) - self.assertEqual(p.coords, (50.0,3141.0), 'Point _set_list') + p._set_list(2, (50, 3141)) + self.assertEqual(p.coords, (50.0, 3141.0), 'Point _set_list') def test02_PointExceptions(self): 'Testing Point exceptions' @@ -95,25 +95,25 @@ class GEOSMutationTest(unittest.TestCase): def test03_PointApi(self): 'Testing Point API' - q = Point(4,5,3) - for p in (Point(1,2,3), fromstr('POINT (1 2 3)')): - p[0:2] = [4,5] + q = Point(4, 5, 3) + for p in (Point(1, 2, 3), fromstr('POINT (1 2 3)')): + p[0:2] = [4, 5] for f in geos_function_tests: self.assertEqual(f(q), f(p), 'Point ' + f.__name__) def test04_LineStringMutations(self): 'Testing LineString mutations' - for ls in (LineString((1,0),(4,1),(6,-1)), + for ls in (LineString((1, 0), (4, 1), (6, -1)), fromstr('LINESTRING (1 0,4 1,6 -1)')): - self.assertEqual(ls._get_single_external(1), (4.0,1.0), 'LineString _get_single_external') + self.assertEqual(ls._get_single_external(1), (4.0, 1.0), 'LineString _get_single_external') # _set_single - ls._set_single(0,(-50,25)) - self.assertEqual(ls.coords, ((-50.0,25.0),(4.0,1.0),(6.0,-1.0)), 'LineString _set_single') + ls._set_single(0, (-50, 25)) + self.assertEqual(ls.coords, ((-50.0, 25.0),(4.0, 1.0),(6.0, -1.0)), 'LineString _set_single') # _set_list - ls._set_list(2, ((-50.0,25.0),(6.0,-1.0))) - self.assertEqual(ls.coords, ((-50.0,25.0),(6.0,-1.0)), 'LineString _set_list') + ls._set_list(2, ((-50.0, 25.0), (6.0, -1.0))) + self.assertEqual(ls.coords, ((-50.0, 25.0), (6.0, -1.0)), 'LineString _set_list') lsa = LineString(ls.coords) for f in geos_function_tests: diff --git a/django/contrib/gis/geos/tests/test_mutable_list.py b/django/contrib/gis/geos/tests/test_mutable_list.py index 2e708dda75..b052222753 100644 --- a/django/contrib/gis/geos/tests/test_mutable_list.py +++ b/django/contrib/gis/geos/tests/test_mutable_list.py @@ -320,7 +320,7 @@ class ListMixinTest(unittest.TestCase): def setfcn(x, i, v): x[i] = v - self.assertRaises(TypeError, setfcn, ul, slice(0,3,2), 2) + self.assertRaises(TypeError, setfcn, ul, slice(0, 3, 2), 2) def test10_checkindex(self): 'Index check' @@ -374,7 +374,7 @@ class ListMixinTest(unittest.TestCase): self.assertEqual(pl[:], ul[:], 'in-place add') self.assertEqual(objid, id(ul), 'in-place add id') - for n in (-1,0,1,3): + for n in (-1, 0, 1, 3): pl, ul = self.lists_of_len() self.assertEqual(list(pl * n), list(ul * n), 'mul by %d' % n) self.assertEqual(type(ul), type(ul * n), 'type of mul by %d result' % n) diff --git a/django/contrib/gis/measure.py b/django/contrib/gis/measure.py index 7b4afef16f..a63e4eef9d 100644 --- a/django/contrib/gis/measure.py +++ b/django/contrib/gis/measure.py @@ -103,42 +103,42 @@ class MeasureBase(object): return self.__class__(default_unit=self._default_unit, **{self.STANDARD_UNIT: (self.standard + other.standard)}) else: - raise TypeError('%(class)s must be added with %(class)s' % {"class":pretty_name(self)}) + raise TypeError('%(class)s must be added with %(class)s' % {"class": pretty_name(self)}) def __iadd__(self, other): if isinstance(other, self.__class__): self.standard += other.standard return self else: - raise TypeError('%(class)s must be added with %(class)s' % {"class":pretty_name(self)}) + raise TypeError('%(class)s must be added with %(class)s' % {"class": pretty_name(self)}) def __sub__(self, other): if isinstance(other, self.__class__): return self.__class__(default_unit=self._default_unit, **{self.STANDARD_UNIT: (self.standard - other.standard)}) else: - raise TypeError('%(class)s must be subtracted from %(class)s' % {"class":pretty_name(self)}) + raise TypeError('%(class)s must be subtracted from %(class)s' % {"class": pretty_name(self)}) def __isub__(self, other): if isinstance(other, self.__class__): self.standard -= other.standard return self else: - raise TypeError('%(class)s must be subtracted from %(class)s' % {"class":pretty_name(self)}) + raise TypeError('%(class)s must be subtracted from %(class)s' % {"class": pretty_name(self)}) def __mul__(self, other): if isinstance(other, NUMERIC_TYPES): return self.__class__(default_unit=self._default_unit, **{self.STANDARD_UNIT: (self.standard * other)}) else: - raise TypeError('%(class)s must be multiplied with number' % {"class":pretty_name(self)}) + raise TypeError('%(class)s must be multiplied with number' % {"class": pretty_name(self)}) def __imul__(self, other): if isinstance(other, NUMERIC_TYPES): self.standard *= float(other) return self else: - raise TypeError('%(class)s must be multiplied with number' % {"class":pretty_name(self)}) + raise TypeError('%(class)s must be multiplied with number' % {"class": pretty_name(self)}) def __rmul__(self, other): return self * other @@ -150,7 +150,7 @@ class MeasureBase(object): return self.__class__(default_unit=self._default_unit, **{self.STANDARD_UNIT: (self.standard / other)}) else: - raise TypeError('%(class)s must be divided with number or %(class)s' % {"class":pretty_name(self)}) + raise TypeError('%(class)s must be divided with number or %(class)s' % {"class": pretty_name(self)}) def __div__(self, other): # Python 2 compatibility return type(self).__truediv__(self, other) @@ -160,7 +160,7 @@ class MeasureBase(object): self.standard /= float(other) return self else: - raise TypeError('%(class)s must be divided with number' % {"class":pretty_name(self)}) + raise TypeError('%(class)s must be divided with number' % {"class": pretty_name(self)}) def __idiv__(self, other): # Python 2 compatibility return type(self).__itruediv__(self, other) @@ -304,7 +304,7 @@ class Distance(MeasureBase): **{self.STANDARD_UNIT: (self.standard * other)}) else: raise TypeError('%(distance)s must be multiplied with number or %(distance)s' % { - "distance" : pretty_name(self.__class__), + "distance": pretty_name(self.__class__), }) @@ -320,7 +320,7 @@ class Area(MeasureBase): return self.__class__(default_unit=self._default_unit, **{self.STANDARD_UNIT: (self.standard / other)}) else: - raise TypeError('%(class)s must be divided by a number' % {"class":pretty_name(self)}) + raise TypeError('%(class)s must be divided by a number' % {"class": pretty_name(self)}) def __div__(self, other): # Python 2 compatibility return type(self).__truediv__(self, other) diff --git a/django/contrib/sitemaps/__init__.py b/django/contrib/sitemaps/__init__.py index b8d0a4f31e..31d2d8c5d9 100644 --- a/django/contrib/sitemaps/__init__.py +++ b/django/contrib/sitemaps/__init__.py @@ -32,7 +32,7 @@ def ping_google(sitemap_url=None, ping_url=PING_URL): current_site = Site.objects.get_current() url = "http://%s%s" % (current_site.domain, sitemap_url) - params = urlencode({'sitemap':url}) + params = urlencode({'sitemap': url}) urlopen("%s?%s" % (ping_url, params)) class Sitemap(object): diff --git a/django/core/cache/backends/filebased.py b/django/core/cache/backends/filebased.py index 83ded57034..acfd1c38ed 100644 --- a/django/core/cache/backends/filebased.py +++ b/django/core/cache/backends/filebased.py @@ -141,7 +141,7 @@ class FileBasedCache(BaseCache): def _get_num_entries(self): count = 0 - for _,_,files in os.walk(self._dir): + for _, _, files in os.walk(self._dir): count += len(files) return count _num_entries = property(_get_num_entries) diff --git a/django/core/files/locks.py b/django/core/files/locks.py index 6f0e4b9508..04ae67fd30 100644 --- a/django/core/files/locks.py +++ b/django/core/files/locks.py @@ -14,7 +14,7 @@ Example Usage:: ... f.write('Django') """ -__all__ = ('LOCK_EX','LOCK_SH','LOCK_NB','lock','unlock') +__all__ = ('LOCK_EX', 'LOCK_SH', 'LOCK_NB', 'lock', 'unlock') system_type = None diff --git a/django/core/files/move.py b/django/core/files/move.py index 7363201cde..14b9b649d7 100644 --- a/django/core/files/move.py +++ b/django/core/files/move.py @@ -26,7 +26,7 @@ __all__ = ['file_move_safe'] def _samefile(src, dst): # Macintosh, Unix. - if hasattr(os.path,'samefile'): + if hasattr(os.path, 'samefile'): try: return os.path.samefile(src, dst) except OSError: diff --git a/django/core/files/uploadhandler.py b/django/core/files/uploadhandler.py index 185aca72cc..d267871bbd 100644 --- a/django/core/files/uploadhandler.py +++ b/django/core/files/uploadhandler.py @@ -11,9 +11,11 @@ from django.core.files.uploadedfile import TemporaryUploadedFile, InMemoryUpload from django.utils.encoding import python_2_unicode_compatible from django.utils.module_loading import import_by_path -__all__ = ['UploadFileException','StopUpload', 'SkipFile', 'FileUploadHandler', - 'TemporaryFileUploadHandler', 'MemoryFileUploadHandler', - 'load_handler', 'StopFutureHandlers'] +__all__ = [ + 'UploadFileException', 'StopUpload', 'SkipFile', 'FileUploadHandler', + 'TemporaryFileUploadHandler', 'MemoryFileUploadHandler', 'load_handler', + 'StopFutureHandlers' +] class UploadFileException(Exception): """ diff --git a/django/core/mail/backends/filebased.py b/django/core/mail/backends/filebased.py index 0f6cc0ae20..9d1e6cb060 100644 --- a/django/core/mail/backends/filebased.py +++ b/django/core/mail/backends/filebased.py @@ -14,7 +14,7 @@ class EmailBackend(ConsoleEmailBackend): if 'file_path' in kwargs: self.file_path = kwargs.pop('file_path') else: - self.file_path = getattr(settings, 'EMAIL_FILE_PATH',None) + self.file_path = getattr(settings, 'EMAIL_FILE_PATH', None) # Make sure self.file_path is a string. if not isinstance(self.file_path, six.string_types): raise ImproperlyConfigured('Path for saving emails is invalid: %r' % self.file_path) diff --git a/django/dispatch/saferef.py b/django/dispatch/saferef.py index 7c971e44f7..c40dbba462 100644 --- a/django/dispatch/saferef.py +++ b/django/dispatch/saferef.py @@ -70,7 +70,7 @@ class BoundMethodWeakref(object): _allInstances = weakref.WeakValueDictionary() - def __new__(cls, target, onDelete=None, *arguments,**named): + def __new__(cls, target, onDelete=None, *arguments, **named): """Create new instance or return current instance Basically this method of construction allows us to diff --git a/django/forms/models.py b/django/forms/models.py index cb321510c7..f52fe19bc3 100644 --- a/django/forms/models.py +++ b/django/forms/models.py @@ -859,7 +859,7 @@ class BaseInlineFormSet(BaseModelFormSet): @classmethod def get_default_prefix(cls): from django.db.models.fields.related import RelatedObject - return RelatedObject(cls.fk.rel.to, cls.model, cls.fk).get_accessor_name().replace('+','') + return RelatedObject(cls.fk.rel.to, cls.model, cls.fk).get_accessor_name().replace('+', '') def save_new(self, form, commit=True): # Use commit=False so we can assign the parent key afterwards, then diff --git a/django/forms/widgets.py b/django/forms/widgets.py index 545d29aa45..3b5c460ef9 100644 --- a/django/forms/widgets.py +++ b/django/forms/widgets.py @@ -660,7 +660,7 @@ class ChoiceFieldRenderer(object): output = [start_tag] for i, choice in enumerate(self.choices): choice_value, choice_label = choice - if isinstance(choice_label, (tuple,list)): + if isinstance(choice_label, (tuple, list)): attrs_plus = self.attrs.copy() if id_: attrs_plus['id'] += '_{0}'.format(i) diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py index 32f275bfb3..6e424fc6cb 100644 --- a/django/template/defaultfilters.py +++ b/django/template/defaultfilters.py @@ -810,7 +810,7 @@ def filesizeformat(bytes): """ try: bytes = float(bytes) - except (TypeError,ValueError,UnicodeDecodeError): + except (TypeError, ValueError, UnicodeDecodeError): value = ungettext("%(size)d byte", "%(size)d bytes", 0) % {'size': 0} return avoid_wrapping(value) diff --git a/tests/admin_views/admin.py b/tests/admin_views/admin.py index 889c51a6db..af197498ce 100644 --- a/tests/admin_views/admin.py +++ b/tests/admin_views/admin.py @@ -723,7 +723,7 @@ class EmptyModelVisibleAdmin(admin.ModelAdmin): form = FormWithoutHiddenField fieldsets = ( (None, { - 'fields':(('first', 'second'),), + 'fields': (('first', 'second'),), }), ) diff --git a/tests/aggregation/tests.py b/tests/aggregation/tests.py index 5abd4aaf6c..eee61654bc 100644 --- a/tests/aggregation/tests.py +++ b/tests/aggregation/tests.py @@ -340,7 +340,7 @@ class BaseAggregateTestCase(TestCase): price=Decimal("1000"), publisher=p, contact_id=1, - pubdate=datetime.date(2008,12,1) + pubdate=datetime.date(2008, 12, 1) ) Book.objects.create( name='ExpensiveBook2', @@ -350,7 +350,7 @@ class BaseAggregateTestCase(TestCase): price=Decimal("1000"), publisher=p, contact_id=1, - pubdate=datetime.date(2008,12,2) + pubdate=datetime.date(2008, 12, 2) ) Book.objects.create( name='ExpensiveBook3', @@ -360,7 +360,7 @@ class BaseAggregateTestCase(TestCase): price=Decimal("35"), publisher=p, contact_id=1, - pubdate=datetime.date(2008,12,3) + pubdate=datetime.date(2008, 12, 3) ) publishers = Publisher.objects.annotate(num_books=Count("book__id")).filter(num_books__gt=1).order_by("pk") diff --git a/tests/inspectdb/tests.py b/tests/inspectdb/tests.py index 56f48fc207..a0053bfcaa 100644 --- a/tests/inspectdb/tests.py +++ b/tests/inspectdb/tests.py @@ -35,7 +35,7 @@ class InspectDBTestCase(TestCase): """Test introspection of various Django field types""" out = StringIO() call_command('inspectdb', - table_name_filter=lambda tn:tn.startswith('inspectdb_columntypes'), + table_name_filter=lambda tn: tn.startswith('inspectdb_columntypes'), stdout=out) output = out.getvalue() diff --git a/tests/validation/tests.py b/tests/validation/tests.py index 7f028e655b..14337b6576 100644 --- a/tests/validation/tests.py +++ b/tests/validation/tests.py @@ -129,9 +129,9 @@ class GenericIPAddressFieldTests(ValidationTestCase): def test_invalid_v4_ip_raises_error(self): giptm = GenericIPAddressTestModel(v4_ip="294.4.2.1") - self.assertFailsValidation(giptm.full_clean, ['v4_ip',]) + self.assertFailsValidation(giptm.full_clean, ['v4_ip']) giptm = GenericIPAddressTestModel(v4_ip="2001::2") - self.assertFailsValidation(giptm.full_clean, ['v4_ip',]) + self.assertFailsValidation(giptm.full_clean, ['v4_ip']) def test_correct_v6_ip_passes(self): giptm = GenericIPAddressTestModel(v6_ip="2001::2") @@ -139,16 +139,16 @@ class GenericIPAddressFieldTests(ValidationTestCase): def test_invalid_v6_ip_raises_error(self): giptm = GenericIPAddressTestModel(v6_ip="1.2.3.4") - self.assertFailsValidation(giptm.full_clean, ['v6_ip',]) + self.assertFailsValidation(giptm.full_clean, ['v6_ip']) giptm = GenericIPAddressTestModel(v6_ip="1:2") - self.assertFailsValidation(giptm.full_clean, ['v6_ip',]) + self.assertFailsValidation(giptm.full_clean, ['v6_ip']) def test_v6_uniqueness_detection(self): # These two addresses are the same with different syntax giptm = GenericIPAddressTestModel(generic_ip="2001::1:0:0:0:0:2") giptm.save() giptm = GenericIPAddressTestModel(generic_ip="2001:0:1:2") - self.assertFailsValidation(giptm.full_clean, ['generic_ip',]) + self.assertFailsValidation(giptm.full_clean, ['generic_ip']) def test_v4_unpack_uniqueness_detection(self): # These two are different, because we are not doing IPv4 unpacking