Fixed #21270 -- Fixed E701 pep8 warnings

This commit is contained in:
Alasdair Nicol 2013-10-17 09:17:41 +01:00
parent 650b6fd90e
commit eb214452c3
78 changed files with 625 additions and 285 deletions

View File

@ -198,8 +198,10 @@ class ChangeList(six.with_metaclass(RenameChangeListMethods)):
six.reraise(IncorrectLookupParameters, IncorrectLookupParameters(e), sys.exc_info()[2])
def get_query_string(self, new_params=None, remove=None):
if new_params is None: new_params = {}
if remove is None: remove = []
if new_params is None:
new_params = {}
if remove is None:
remove = []
p = self.params.copy()
for r in remove:
for k in list(p):

View File

@ -94,15 +94,19 @@ ROLES = {
def create_reference_role(rolename, urlbase):
def _role(name, rawtext, text, lineno, inliner, options=None, content=None):
if options is None: options = {}
if content is None: content = []
if options is None:
options = {}
if content is None:
content = []
node = docutils.nodes.reference(rawtext, text, refuri=(urlbase % (inliner.document.settings.link_base, text.lower())), **options)
return [node], []
docutils.parsers.rst.roles.register_canonical_role(rolename, _role)
def default_reference_role(name, rawtext, text, lineno, inliner, options=None, content=None):
if options is None: options = {}
if content is None: content = []
if options is None:
options = {}
if content is None:
content = []
context = inliner.document.settings.default_reference_context
node = docutils.nodes.reference(rawtext, text, refuri=(ROLES[context] % (inliner.document.settings.link_base, text.lower())), **options)
return [node], []

View File

@ -70,8 +70,10 @@ class GeoModelAdmin(ModelAdmin):
"""
is_collection = db_field.geom_type in ('MULTIPOINT', 'MULTILINESTRING', 'MULTIPOLYGON', 'GEOMETRYCOLLECTION')
if is_collection:
if db_field.geom_type == 'GEOMETRYCOLLECTION': collection_type = 'Any'
else: collection_type = OGRGeomType(db_field.geom_type.replace('MULTI', ''))
if db_field.geom_type == 'GEOMETRYCOLLECTION':
collection_type = 'Any'
else:
collection_type = OGRGeomType(db_field.geom_type.replace('MULTI', ''))
else:
collection_type = 'None'

View File

@ -20,7 +20,8 @@ class OpenLayersWidget(Textarea):
"""
def render(self, name, value, attrs=None):
# Update the template parameters with any attributes passed in.
if attrs: self.params.update(attrs)
if attrs:
self.params.update(attrs)
# Defaulting the WKT value to a blank string -- this
# will be tested in the JavaScript and the appropriate

View File

@ -201,8 +201,10 @@ class SpatialRefSysMixin(object):
return self.srs.ellipsoid
else:
m = self.spheroid_regex.match(self.wkt)
if m: return (float(m.group('major')), float(m.group('flattening')))
else: return None
if m:
return (float(m.group('major')), float(m.group('flattening')))
else:
return None
@property
def name(self):

View File

@ -72,7 +72,8 @@ class PostGISIntrospection(DatabaseIntrospection):
'WHERE "f_table_name"=%s AND "f_geometry_column"=%s',
(table_name, geo_col))
row = cursor.fetchone()
if not row: raise GeoIntrospectionError
if not row:
raise GeoIntrospectionError
except GeoIntrospectionError:
if self.connection.ops.geography:
cursor.execute('SELECT "coord_dimension", "srid", "type" '

View File

@ -453,8 +453,10 @@ class PostGISOperations(DatabaseOperations, BaseSpatialOperations):
Helper routine that returns a boolean indicating whether the number of
parameters is correct for the lookup type.
"""
def exactly_two(np): return np == 2
def two_to_three(np): return np >= 2 and np <=3
def exactly_two(np):
return np == 2
def two_to_three(np):
return np >= 2 and np <=3
if (lookup_type in self.distance_functions and
lookup_type != 'dwithin'):
return two_to_three(num_param)

View File

@ -275,12 +275,14 @@ class SpatiaLiteOperations(DatabaseOperations, BaseSpatialOperations):
version = None
try:
tmp = self._get_spatialite_func("X(GeomFromText('POINT(1 1)'))")
if tmp == 1.0: version = '2.3.0'
if tmp == 1.0:
version = '2.3.0'
except DatabaseError:
pass
# If no version string defined, then just re-raise the original
# exception.
if version is None: raise
if version is None:
raise
m = self.version_regex.match(version)
if m:
@ -301,7 +303,8 @@ class SpatiaLiteOperations(DatabaseOperations, BaseSpatialOperations):
if not self.check_aggregate_support(agg):
raise NotImplementedError('%s spatial aggregate is not implmented for this backend.' % agg_name)
agg_name = agg_name.lower()
if agg_name == 'union': agg_name += 'agg'
if agg_name == 'union':
agg_name += 'agg'
sql_template = self.select % '%(function)s(%(field)s)'
sql_function = getattr(self, agg_name)
return sql_template, sql_function

View File

@ -54,7 +54,8 @@ class GeometryProxy(object):
# general GeometryField is used.
if isinstance(value, self._klass) and (str(value.geom_type).upper() == gtype or gtype == 'GEOMETRY'):
# Assigning the SRID to the geometry.
if value.srid is None: value.srid = self._field.srid
if value.srid is None:
value.srid = self._field.srid
elif value is None or isinstance(value, six.string_types + (memoryview,)):
# Set with None, WKT, HEX, or WKB
pass

View File

@ -156,14 +156,20 @@ class GeoQuerySet(QuerySet):
# PostGIS we're using. SpatiaLite only uses the first group of options.
if backend.spatial_version >= (1, 4, 0):
options = 0
if crs and bbox: options = 3
elif bbox: options = 1
elif crs: options = 2
if crs and bbox:
options = 3
elif bbox:
options = 1
elif crs:
options = 2
else:
options = 0
if crs and bbox: options = 3
elif crs: options = 1
elif bbox: options = 2
if crs and bbox:
options = 3
elif crs:
options = 1
elif bbox:
options = 2
s = {'desc' : 'GeoJSON',
'procedure_args' : {'precision' : precision, 'options' : options},
'procedure_fmt' : '%(geo_col)s,%(precision)s,%(options)s',
@ -441,7 +447,8 @@ class GeoQuerySet(QuerySet):
# Does the spatial backend support this?
connection = connections[self.db]
func = getattr(connection.ops, att, False)
if desc is None: desc = att
if desc is None:
desc = att
if not func:
raise NotImplementedError('%s stored procedure not available on '
'the %s backend.' %
@ -489,7 +496,8 @@ class GeoQuerySet(QuerySet):
# Adding any keyword parameters for the Aggregate object. Oracle backends
# in particular need an additional `tolerance` parameter.
agg_kwargs = {}
if connections[self.db].ops.oracle: agg_kwargs['tolerance'] = tolerance
if connections[self.db].ops.oracle:
agg_kwargs['tolerance'] = tolerance
# Calling the QuerySet.aggregate, and returning only the value of the aggregate.
return self.aggregate(geoagg=aggregate(agg_col, **agg_kwargs))['geoagg']
@ -533,12 +541,14 @@ class GeoQuerySet(QuerySet):
if settings.get('setup', True):
default_args, geo_field = self._spatial_setup(att, desc=settings['desc'], field_name=field_name,
geo_field_type=settings.get('geo_field_type', None))
for k, v in six.iteritems(default_args): settings['procedure_args'].setdefault(k, v)
for k, v in six.iteritems(default_args):
settings['procedure_args'].setdefault(k, v)
else:
geo_field = settings['geo_field']
# The attribute to attach to the model.
if not isinstance(model_att, six.string_types): model_att = att
if not isinstance(model_att, six.string_types):
model_att = att
# Special handling for any argument that is a geometry.
for name in settings['geom_args']:

View File

@ -166,7 +166,8 @@ class GeoSQLCompiler(compiler.SQLCompiler):
# doing pagination with Oracle.
rn_offset = 0
if self.connection.ops.oracle:
if self.query.high_mark is not None or self.query.low_mark: rn_offset = 1
if self.query.high_mark is not None or self.query.low_mark:
rn_offset = 1
index_start = rn_offset + len(aliases)
# Converting any extra selection values (e.g., geometries and
@ -243,7 +244,8 @@ class GeoSQLCompiler(compiler.SQLCompiler):
used. If `column` is specified, it will be used instead of the value
in `field.column`.
"""
if table_alias is None: table_alias = self.query.get_meta().db_table
if table_alias is None:
table_alias = self.query.get_meta().db_table
return "%s.%s" % (self.quote_name_unless_alias(table_alias),
self.connection.ops.quote_name(column or field.column))

View File

@ -113,7 +113,8 @@ class GeoQuery(sql.Query):
if field_name is None:
# Incrementing until the first geographic field is found.
for fld in self.model._meta.fields:
if isinstance(fld, GeometryField): return fld
if isinstance(fld, GeometryField):
return fld
return False
else:
# Otherwise, check by the given field name -- which may be

View File

@ -58,7 +58,8 @@ class GeoFeedMixin(object):
raise ValueError('Only should be 2 or 4 numeric elements.')
# If a GeoRSS box was given via tuple.
if not box_coords is None:
if w3c_geo: raise ValueError('Cannot use simple GeoRSS box in W3C Geo feeds.')
if w3c_geo:
raise ValueError('Cannot use simple GeoRSS box in W3C Geo feeds.')
handler.addQuickElement('georss:box', self.georss_coords(box_coords))
else:
# Getting the lower-case geometry type.
@ -66,7 +67,8 @@ class GeoFeedMixin(object):
if gtype == 'point':
self.add_georss_point(handler, geom.coords, w3c_geo=w3c_geo)
else:
if w3c_geo: raise ValueError('W3C Geo only supports Point geometries.')
if w3c_geo:
raise ValueError('W3C Geo only supports Point geometries.')
# For formatting consistent w/the GeoRSS simple standard:
# http://georss.org/1.0#simple
if gtype in ('linestring', 'linearring'):

View File

@ -19,8 +19,10 @@ class GDALBase(object):
# Raise an exception if the pointer isn't valid don't
# want to be passing NULL pointers to routines --
# that's very bad.
if self._ptr: return self._ptr
else: raise GDALException('GDAL %s pointer no longer valid.' % self.__class__.__name__)
if self._ptr:
return self._ptr
else:
raise GDALException('GDAL %s pointer no longer valid.' % self.__class__.__name__)
def _set_ptr(self, ptr):
# Only allow the pointer to be set with pointers of the

View File

@ -95,7 +95,8 @@ class DataSource(GDALBase):
def __del__(self):
"Destroys this DataStructure object."
if self._ptr: capi.destroy_ds(self._ptr)
if self._ptr:
capi.destroy_ds(self._ptr)
def __iter__(self):
"Allows for iteration over the layers in a data source."
@ -106,7 +107,8 @@ class DataSource(GDALBase):
"Allows use of the index [] operator to get a layer at the index."
if isinstance(index, six.string_types):
l = capi.get_layer_by_name(self.ptr, force_bytes(index))
if not l: raise OGRIndexError('invalid OGR Layer name given: "%s"' % index)
if not l:
raise OGRIndexError('invalid OGR Layer name given: "%s"' % index)
elif isinstance(index, int):
if index < 0 or index >= self.layer_count:
raise OGRIndexError('index out of range')

View File

@ -59,7 +59,8 @@ class Driver(GDALBase):
"Attempts to register all the data source drivers."
# Only register all if the driver count is 0 (or else all drivers
# will be registered over and over again)
if not self.driver_count: capi.register_all()
if not self.driver_count:
capi.register_all()
# Driver properties
@property

View File

@ -4,9 +4,15 @@
OGR methods.
"""
#### OGR & SRS Exceptions ####
class GDALException(Exception): pass
class OGRException(Exception): pass
class SRSException(Exception): pass
class GDALException(Exception):
pass
class OGRException(Exception):
pass
class SRSException(Exception):
pass
class OGRIndexError(OGRException, KeyError):
"""
This exception is raised when an invalid index is encountered, and has

View File

@ -33,7 +33,8 @@ class Feature(GDALBase):
def __del__(self):
"Releases a reference to this object."
if self._ptr: capi.destroy_feature(self._ptr)
if self._ptr:
capi.destroy_feature(self._ptr)
def __getitem__(self, index):
"""

View File

@ -132,9 +132,14 @@ class OFTReal(Field):
return self.as_double()
# String & Binary fields, just subclasses
class OFTString(Field): pass
class OFTWideString(Field): pass
class OFTBinary(Field): pass
class OFTString(Field):
pass
class OFTWideString(Field):
pass
class OFTBinary(Field):
pass
# OFTDate, OFTTime, OFTDateTime fields.
class OFTDate(Field):
@ -172,10 +177,17 @@ class OFTTime(Field):
return None
# List fields are also just subclasses
class OFTIntegerList(Field): pass
class OFTRealList(Field): pass
class OFTStringList(Field): pass
class OFTWideStringList(Field): pass
class OFTIntegerList(Field):
pass
class OFTRealList(Field):
pass
class OFTStringList(Field):
pass
class OFTWideStringList(Field):
pass
# Class mapping dictionary for OFT Types and reverse mapping.
OGRFieldTypes = {

View File

@ -122,14 +122,16 @@ class OGRGeometry(GDALBase):
self.ptr = g
# Assigning the SpatialReference object to the geometry, if valid.
if bool(srs): self.srs = srs
if bool(srs):
self.srs = srs
# Setting the class depending upon the OGR Geometry Type
self.__class__ = GEO_CLASSES[self.geom_type.num]
def __del__(self):
"Deletes this Geometry."
if self._ptr: capi.destroy_geom(self._ptr)
if self._ptr:
capi.destroy_geom(self._ptr)
# Pickle routines
def __getstate__(self):
@ -143,7 +145,8 @@ class OGRGeometry(GDALBase):
def __setstate__(self, state):
wkb, srs = state
ptr = capi.from_wkb(wkb, None, byref(c_void_p()), len(wkb))
if not ptr: raise OGRException('Invalid OGRGeometry loaded from pickled state.')
if not ptr:
raise OGRException('Invalid OGRGeometry loaded from pickled state.')
self.ptr = ptr
self.srs = srs
@ -285,7 +288,8 @@ class OGRGeometry(GDALBase):
# The SRID property
def _get_srid(self):
srs = self.srs
if srs: return srs.srid
if srs:
return srs.srid
return None
def _set_srid(self, srid):
@ -602,7 +606,8 @@ class LineString(OGRGeometry):
return self._listarr(capi.getz)
# LinearRings are used in Polygons.
class LinearRing(LineString): pass
class LinearRing(LineString):
pass
class Polygon(OGRGeometry):
@ -673,7 +678,8 @@ class GeometryCollection(OGRGeometry):
"Add the geometry to this Geometry Collection."
if isinstance(geom, OGRGeometry):
if isinstance(geom, self.__class__):
for g in geom: capi.add_geom(self.ptr, g.ptr)
for g in geom:
capi.add_geom(self.ptr, g.ptr)
else:
capi.add_geom(self.ptr, geom.ptr)
elif isinstance(geom, six.string_types):
@ -695,9 +701,14 @@ class GeometryCollection(OGRGeometry):
coords = tuple
# Multiple Geometry types.
class MultiPoint(GeometryCollection): pass
class MultiLineString(GeometryCollection): pass
class MultiPolygon(GeometryCollection): pass
class MultiPoint(GeometryCollection):
pass
class MultiLineString(GeometryCollection):
pass
class MultiPolygon(GeometryCollection):
pass
# Class mapping dictionary (using the OGRwkbGeometryType as the key)
GEO_CLASSES = {1 : Point,

View File

@ -36,7 +36,8 @@ class OGRGeomType(object):
num = type_input.num
elif isinstance(type_input, six.string_types):
type_input = type_input.lower()
if type_input == 'geometry': type_input='unknown'
if type_input == 'geometry':
type_input='unknown'
num = self._str_types.get(type_input, None)
if num is None:
raise OGRException('Invalid OGR String Type "%s"' % type_input)

View File

@ -47,7 +47,8 @@ class Layer(GDALBase):
# An integer index was given -- we cannot do a check based on the
# number of features because the beginning and ending feature IDs
# are not guaranteed to be 0 and len(layer)-1, respectively.
if index < 0: raise OGRIndexError('Negative indices are not allowed on OGR Layers.')
if index < 0:
raise OGRIndexError('Negative indices are not allowed on OGR Layers.')
return self._make_feature(index)
elif isinstance(index, slice):
# A slice was given
@ -88,7 +89,8 @@ class Layer(GDALBase):
# Random access isn't supported, have to increment through
# each feature until the given feature ID is encountered.
for feat in self:
if feat.fid == feat_id: return feat
if feat.fid == feat_id:
return feat
# Should have returned a Feature, raise an OGRIndexError.
raise OGRIndexError('Invalid feature id: %s.' % feat_id)

View File

@ -36,7 +36,8 @@ else:
if lib_names:
for lib_name in lib_names:
lib_path = find_library(lib_name)
if not lib_path is None: break
if not lib_path is None:
break
if lib_path is None:
raise OGRException('Could not find the GDAL library (tried "%s"). '
@ -83,7 +84,8 @@ version_regex = re.compile(r'^(?P<major>\d+)\.(?P<minor>\d+)(\.(?P<subminor>\d+)
def gdal_version_info():
ver = gdal_version().decode()
m = version_regex.match(ver)
if not m: raise OGRException('Could not parse GDAL version string "%s"' % ver)
if not m:
raise OGRException('Could not parse GDAL version string "%s"' % ver)
return dict((key, m.group(key)) for key in ('major', 'minor', 'subminor'))
_verinfo = gdal_version_info()

View File

@ -19,8 +19,10 @@ def ptr_byref(args, offset=-1):
def check_bool(result, func, cargs):
"Returns the boolean evaluation of the value."
if bool(result): return True
else: return False
if bool(result):
return True
else:
return False
### String checking Routines ###
def check_const_string(result, func, cargs, offset=None):
@ -46,8 +48,10 @@ def check_string(result, func, cargs, offset=-1, str_result=False):
if str_result:
# For routines that return a string.
ptr = result
if not ptr: s = None
else: s = string_at(result)
if not ptr:
s = None
else:
s = string_at(result)
else:
# Error-code return specified.
check_err(result)
@ -56,7 +60,8 @@ def check_string(result, func, cargs, offset=-1, str_result=False):
s = ptr.value
# Correctly freeing the allocated memory beind GDAL pointer
# w/the VSIFree routine.
if ptr: lgdal.VSIFree(ptr)
if ptr:
lgdal.VSIFree(ptr)
return s
### DataSource, Layer error-checking ###

View File

@ -15,8 +15,10 @@ def double_output(func, argtypes, errcheck=False, strarg=False):
"Generates a ctypes function that returns a double value."
func.argtypes = argtypes
func.restype = c_double
if errcheck: func.errcheck = check_arg_errcode
if strarg: func.errcheck = check_str_arg
if errcheck:
func.errcheck = check_arg_errcode
if strarg:
func.errcheck = check_str_arg
return func
def geom_output(func, argtypes, offset=None):
@ -106,7 +108,8 @@ def void_output(func, argtypes, errcheck=True):
For functions that don't only return an error code that needs to
be examined.
"""
if argtypes: func.argtypes = argtypes
if argtypes:
func.argtypes = argtypes
if errcheck:
# `errcheck` keyword may be set to False for routines that
# return void, rather than a status code.

View File

@ -97,7 +97,8 @@ class SpatialReference(GDALBase):
def __del__(self):
"Destroys this spatial reference."
if self._ptr: capi.release_srs(self._ptr)
if self._ptr:
capi.release_srs(self._ptr)
def __getitem__(self, target):
"""
@ -176,10 +177,14 @@ class SpatialReference(GDALBase):
@property
def name(self):
"Returns the name of this Spatial Reference."
if self.projected: return self.attr_value('PROJCS')
elif self.geographic: return self.attr_value('GEOGCS')
elif self.local: return self.attr_value('LOCAL_CS')
else: return None
if self.projected:
return self.attr_value('PROJCS')
elif self.geographic:
return self.attr_value('GEOGCS')
elif self.local:
return self.attr_value('LOCAL_CS')
else:
return None
@property
def srid(self):
@ -336,7 +341,8 @@ class CoordTransform(GDALBase):
def __del__(self):
"Deletes this Coordinate Transformation object."
if self._ptr: capi.destroy_ct(self._ptr)
if self._ptr:
capi.destroy_ct(self._ptr)
def __str__(self):
return 'Transform from "%s" to "%s"' % (self._srs1_name, self._srs2_name)

View File

@ -93,7 +93,8 @@ class DataSourceTest(unittest.TestCase):
# Now checking the field names.
flds = layer.fields
for f in flds: self.assertEqual(True, f in source.fields)
for f in flds:
self.assertEqual(True, f in source.fields)
# Negative FIDs are not allowed.
self.assertRaises(OGRIndexError, layer.__getitem__, -1)

View File

@ -418,7 +418,8 @@ class OGRGeomTest(unittest.TestCase, TestDataMixin):
mp1.add(poly) # Adding a geometry at a time
mp2.add(poly.wkt) # Adding WKT
mp3.add(mpoly) # Adding a MultiPolygon's entire contents at once.
for tmp in (mp1, mp2, mp3): self.assertEqual(mpoly, tmp)
for tmp in (mp1, mp2, mp3):
self.assertEqual(mpoly, tmp)
def test15_extent(self):
"Testing `extent` property."

View File

@ -89,7 +89,8 @@ class GeoIP(object):
# Getting the GeoIP data path.
if not path:
path = GEOIP_SETTINGS.get('GEOIP_PATH', None)
if not path: raise GeoIPException('GeoIP path must be provided via parameter or the GEOIP_PATH setting.')
if not path:
raise GeoIPException('GeoIP path must be provided via parameter or the GEOIP_PATH setting.')
if not isinstance(path, six.string_types):
raise TypeError('Invalid path type: %s' % type(path).__name__)
@ -129,8 +130,10 @@ class GeoIP(object):
# Cleaning any GeoIP file handles lying around.
if GeoIP_delete is None:
return
if self._country: GeoIP_delete(self._country)
if self._city: GeoIP_delete(self._city)
if self._country:
GeoIP_delete(self._country)
if self._city:
GeoIP_delete(self._city)
def _check_query(self, query, country=False, city=False, city_or_country=False):
"Helper routine for checking the query and database availability."
@ -199,8 +202,10 @@ class GeoIP(object):
#### Coordinate retrieval routines ####
def coords(self, query, ordering=('longitude', 'latitude')):
cdict = self.city(query)
if cdict is None: return None
else: return tuple(cdict[o] for o in ordering)
if cdict is None:
return None
else:
return tuple(cdict[o] for o in ordering)
def lon_lat(self, query):
"Returns a tuple of the (longitude, latitude) for the given query."

View File

@ -18,9 +18,11 @@ else:
lib_name = 'GeoIP'
# Getting the path to the GeoIP library.
if lib_name: lib_path = find_library(lib_name)
if lib_path is None: raise RuntimeError('Could not find the GeoIP library (tried "%s"). '
'Try setting GEOIP_LIBRARY_PATH in your settings.' % lib_name)
if lib_name:
lib_path = find_library(lib_name)
if lib_path is None:
raise RuntimeError('Could not find the GeoIP library (tried "%s"). '
'Try setting GEOIP_LIBRARY_PATH in your settings.' % lib_name)
lgeoip = CDLL(lib_path)
# Getting the C `free` for the platform.

View File

@ -27,7 +27,8 @@ geoip_encodings = {
1: 'utf8',
}
class GeoIPTag(Structure): pass
class GeoIPTag(Structure):
pass
RECTYPE = POINTER(GeoIPRecord)
DBTYPE = POINTER(GeoIPTag)

View File

@ -34,8 +34,10 @@ class GEOSBase(object):
# Raise an exception if the pointer isn't valid don't
# want to be passing NULL pointers to routines --
# that's very bad.
if self._ptr: return self._ptr
else: raise GEOSException('NULL GEOS %s pointer encountered.' % self.__class__.__name__)
if self._ptr:
return self._ptr
else:
raise GEOSException('NULL GEOS %s pointer encountered.' % self.__class__.__name__)
def _set_ptr(self, ptr):
# Only allow the pointer to be set with pointers of the

View File

@ -73,7 +73,8 @@ class GeometryCollection(GEOSGeometry):
prev_ptr = self.ptr
srid = self.srid
self.ptr = self._create_collection(length, items)
if srid: self.srid = srid
if srid:
self.srid = srid
capi.destroy_geom(prev_ptr)
_set_single = GEOSGeometry._set_single_rebuild

View File

@ -64,7 +64,8 @@ class GEOSCoordSeq(GEOSBase):
# Setting the X, Y, Z
self.setX(index, value[0])
self.setY(index, value[1])
if set_3d: self.setZ(index, value[2])
if set_3d:
self.setZ(index, value[2])
#### Internal Routines ####
def _checkindex(self, index):
@ -144,8 +145,10 @@ class GEOSCoordSeq(GEOSBase):
"Returns the KML representation for the coordinates."
# Getting the substitution string depending on whether the coordinates have
# a Z dimension.
if self.hasz: substr = '%s,%s,%s '
else: substr = '%s,%s,0 '
if self.hasz:
substr = '%s,%s,%s '
else:
substr = '%s,%s,0 '
return '<coordinates>%s</coordinates>' % \
''.join(substr % self[i] for i in xrange(len(self))).strip()
@ -153,5 +156,7 @@ class GEOSCoordSeq(GEOSBase):
def tuple(self):
"Returns a tuple version of this coordinate sequence."
n = self.size
if n == 1: return self[0]
else: return tuple(self[i] for i in xrange(n))
if n == 1:
return self[0]
else:
return tuple(self[i] for i in xrange(n))

View File

@ -66,7 +66,8 @@ class GEOSGeometry(GEOSBase, ListMixin):
wkt_m = wkt_regex.match(geo_input)
if wkt_m:
# Handling WKT input.
if wkt_m.group('srid'): srid = int(wkt_m.group('srid'))
if wkt_m.group('srid'):
srid = int(wkt_m.group('srid'))
g = wkt_r().read(force_bytes(wkt_m.group('wkt')))
elif hex_regex.match(geo_input):
# Handling HEXEWKB input.
@ -100,7 +101,8 @@ class GEOSGeometry(GEOSBase, ListMixin):
def _post_init(self, srid):
"Helper routine for performing post-initialization setup."
# Setting the SRID, if given.
if srid and isinstance(srid, int): self.srid = srid
if srid and isinstance(srid, int):
self.srid = srid
# Setting the class type (e.g., Point, Polygon, etc.)
self.__class__ = GEOS_CLASSES[self.geom_typeid]
@ -114,7 +116,8 @@ class GEOSGeometry(GEOSBase, ListMixin):
Destroys this Geometry; in other words, frees the memory used by the
GEOS C++ object.
"""
if self._ptr: capi.destroy_geom(self._ptr)
if self._ptr:
capi.destroy_geom(self._ptr)
def __copy__(self):
"""
@ -149,7 +152,8 @@ class GEOSGeometry(GEOSBase, ListMixin):
# Instantiating from the tuple state that was pickled.
wkb, srid = state
ptr = wkb_r().read(memoryview(wkb))
if not ptr: raise GEOSException('Invalid Geometry loaded from pickled state.')
if not ptr:
raise GEOSException('Invalid Geometry loaded from pickled state.')
self.ptr = ptr
self._post_init(srid)
@ -361,8 +365,10 @@ class GEOSGeometry(GEOSBase, ListMixin):
def get_srid(self):
"Gets the SRID for the geometry, returns None if no SRID is set."
s = capi.geos_get_srid(self.ptr)
if s == 0: return None
else: return s
if s == 0:
return None
else:
return s
def set_srid(self, srid):
"Sets the SRID for the geometry."
@ -377,8 +383,10 @@ class GEOSGeometry(GEOSBase, ListMixin):
are *not* included in this representation because GEOS does not yet
support serializing them.
"""
if self.get_srid(): return 'SRID=%s;%s' % (self.srid, self.wkt)
else: return self.wkt
if self.get_srid():
return 'SRID=%s;%s' % (self.srid, self.wkt)
else:
return self.wkt
@property
def wkt(self):

View File

@ -43,7 +43,8 @@ else:
if lib_names:
for lib_name in lib_names:
lib_path = find_library(lib_name)
if not lib_path is None: break
if not lib_path is None:
break
# No GEOS library could be found.
if lib_path is None:
@ -83,10 +84,17 @@ error_h = ERRORFUNC(error_h)
#### GEOS Geometry C data structures, and utility functions. ####
# Opaque GEOS geometry structures, used for GEOM_PTR and CS_PTR
class GEOSGeom_t(Structure): pass
class GEOSPrepGeom_t(Structure): pass
class GEOSCoordSeq_t(Structure): pass
class GEOSContextHandle_t(Structure): pass
class GEOSGeom_t(Structure):
pass
class GEOSPrepGeom_t(Structure):
pass
class GEOSCoordSeq_t(Structure):
pass
class GEOSContextHandle_t(Structure):
pass
# Pointers to opaque GEOS geometry structures.
GEOM_PTR = POINTER(GEOSGeom_t)

View File

@ -24,25 +24,31 @@ class LineString(GEOSGeometry):
ls = LineString(Point(1, 1), Point(2, 2))
"""
# If only one argument provided, set the coords array appropriately
if len(args) == 1: coords = args[0]
else: coords = args
if len(args) == 1:
coords = args[0]
else:
coords = args
if isinstance(coords, (tuple, list)):
# Getting the number of coords and the number of dimensions -- which
# must stay the same, e.g., no LineString((1, 2), (1, 2, 3)).
ncoords = len(coords)
if coords: ndim = len(coords[0])
else: raise TypeError('Cannot initialize on empty sequence.')
if coords:
ndim = len(coords[0])
else:
raise TypeError('Cannot initialize on empty sequence.')
self._checkdim(ndim)
# Incrementing through each of the coordinates and verifying
for i in xrange(1, ncoords):
if not isinstance(coords[i], (tuple, list, Point)):
raise TypeError('each coordinate should be a sequence (list or tuple)')
if len(coords[i]) != ndim: raise TypeError('Dimension mismatch.')
if len(coords[i]) != ndim:
raise TypeError('Dimension mismatch.')
numpy_coords = False
elif numpy and isinstance(coords, numpy.ndarray):
shape = coords.shape # Using numpy's shape.
if len(shape) != 2: raise TypeError('Too many dimensions.')
if len(shape) != 2:
raise TypeError('Too many dimensions.')
self._checkdim(shape[1])
ncoords = shape[0]
ndim = shape[1]
@ -55,9 +61,12 @@ class LineString(GEOSGeometry):
cs = GEOSCoordSeq(capi.create_cs(ncoords, ndim), z=bool(ndim==3))
for i in xrange(ncoords):
if numpy_coords: cs[i] = coords[i,:]
elif isinstance(coords[i], Point): cs[i] = coords[i].tuple
else: cs[i] = coords[i]
if numpy_coords:
cs[i] = coords[i,:]
elif isinstance(coords[i], Point):
cs[i] = coords[i].tuple
else:
cs[i] = coords[i]
# If SRID was passed in with the keyword arguments
srid = kwargs.get('srid', None)
@ -103,7 +112,8 @@ class LineString(GEOSGeometry):
self._cs[index] = value
def _checkdim(self, dim):
if dim not in (2, 3): raise TypeError('Dimension mismatch.')
if dim not in (2, 3):
raise TypeError('Dimension mismatch.')
#### Sequence Properties ####
@property
@ -118,8 +128,10 @@ class LineString(GEOSGeometry):
the given function. Will return a numpy array if possible.
"""
lst = [func(i) for i in xrange(len(self))]
if numpy: return numpy.array(lst) # ARRRR!
else: return lst
if numpy:
return numpy.array(lst) # ARRRR!
else:
return lst
@property
def array(self):
@ -144,8 +156,10 @@ class LineString(GEOSGeometry):
@property
def z(self):
"Returns a list or numpy array of the Z variable."
if not self.hasz: return None
else: return self._listarr(self._cs.getZ)
if not self.hasz:
return None
else:
return self._listarr(self._cs.getZ)
# LinearRings are LineStrings used within Polygons.
class LinearRing(LineString):

View File

@ -180,13 +180,15 @@ class ListMixin(object):
"Standard list count method"
count = 0
for i in self:
if val == i: count += 1
if val == i:
count += 1
return count
def index(self, val):
"Standard list index method"
for i in xrange(0, len(self)):
if self[i] == val: return i
if self[i] == val:
return i
raise ValueError('%s not found in object' % str(val))
## Mutating ##

View File

@ -50,7 +50,8 @@ class Point(GEOSGeometry):
i = iter(coords)
capi.cs_setx(cs, 0, next(i))
capi.cs_sety(cs, 0, next(i))
if ndim == 3: capi.cs_setz(cs, 0, next(i))
if ndim == 3:
capi.cs_setz(cs, 0, next(i))
return capi.create_point(cs)
@ -74,9 +75,12 @@ class Point(GEOSGeometry):
def __len__(self):
"Returns the number of dimensions for this Point (either 0, 2 or 3)."
if self.empty: return 0
if self.hasz: return 3
else: return 2
if self.empty:
return 0
if self.hasz:
return 3
else:
return 2
def _get_single_external(self, index):
if index == 0:

View File

@ -99,7 +99,8 @@ class Polygon(GEOSGeometry):
def _construct_ring(self, param, msg='Parameter must be a sequence of LinearRings or objects that can initialize to LinearRings'):
"Helper routine for trying to construct a ring from the given parameter."
if isinstance(param, LinearRing): return param
if isinstance(param, LinearRing):
return param
try:
ring = LinearRing(param)
return ring
@ -112,7 +113,8 @@ class Polygon(GEOSGeometry):
prev_ptr = self.ptr
srid = self.srid
self.ptr = self._create_polygon(length, items)
if srid: self.srid = srid
if srid:
self.srid = srid
capi.destroy_geom(prev_ptr)
def _get_single_internal(self, index):

View File

@ -11,11 +11,13 @@ class PreparedGeometry(GEOSBase):
ptr_type = capi.PREPGEOM_PTR
def __init__(self, geom):
if not isinstance(geom, GEOSGeometry): raise TypeError
if not isinstance(geom, GEOSGeometry):
raise TypeError
self.ptr = capi.geos_prepare(geom.ptr)
def __del__(self):
if self._ptr: capi.prepared_destroy(self._ptr)
if self._ptr:
capi.prepared_destroy(self._ptr)
def contains(self, other):
return capi.prepared_contains(self.ptr, other.ptr)

View File

@ -33,7 +33,8 @@ def last_arg_byref(args):
def check_dbl(result, func, cargs):
"Checks the status code and returns the double value passed in by reference."
# Checking the status code
if result != 1: return None
if result != 1:
return None
# Double passed in by reference, return its value.
return last_arg_byref(cargs)
@ -53,8 +54,10 @@ def check_minus_one(result, func, cargs):
def check_predicate(result, func, cargs):
"Error checking for unary/binary predicate functions."
val = ord(result) # getting the ordinal from the character
if val == 1: return True
elif val == 0: return False
if val == 1:
return True
elif val == 0:
return False
else:
raise GEOSException('Error encountered on GEOS C predicate function "%s".' % func.__name__)
@ -80,7 +83,8 @@ def check_string(result, func, cargs):
This frees the memory allocated by GEOS at the result pointer.
"""
if not result: raise GEOSException('Error encountered checking string return value in GEOS C function "%s".' % func.__name__)
if not result:
raise GEOSException('Error encountered checking string return value in GEOS C function "%s".' % func.__name__)
# Getting the string value at the pointer address.
s = string_at(result)
# Freeing the memory allocated within GEOS

View File

@ -35,7 +35,8 @@ def bin_output(func):
def geom_output(func, argtypes):
"For GEOS routines that return a geometry."
if argtypes: func.argtypes = argtypes
if argtypes:
func.argtypes = argtypes
func.restype = GEOM_PTR
func.errcheck = check_geom
return func

View File

@ -11,10 +11,17 @@ from django.utils import six
from django.utils.encoding import force_bytes
### The WKB/WKT Reader/Writer structures and pointers ###
class WKTReader_st(Structure): pass
class WKTWriter_st(Structure): pass
class WKBReader_st(Structure): pass
class WKBWriter_st(Structure): pass
class WKTReader_st(Structure):
pass
class WKTWriter_st(Structure):
pass
class WKBReader_st(Structure):
pass
class WKBWriter_st(Structure):
pass
WKT_READ_PTR = POINTER(WKTReader_st)
WKT_WRITE_PTR = POINTER(WKTWriter_st)
@ -121,7 +128,8 @@ class IOBase(GEOSBase):
def __del__(self):
# Cleaning up with the appropriate destructor.
if self._ptr: self._destructor(self._ptr)
if self._ptr:
self._destructor(self._ptr)
### Base WKB/WKT Reading and Writing objects ###
@ -194,7 +202,8 @@ class WKBWriter(IOBase):
return wkb_writer_get_byteorder(self.ptr)
def _set_byteorder(self, order):
if not order in (0, 1): raise ValueError('Byte order parameter must be 0 (Big Endian) or 1 (Little Endian).')
if not order in (0, 1):
raise ValueError('Byte order parameter must be 0 (Big Endian) or 1 (Little Endian).')
wkb_writer_set_byteorder(self.ptr, order)
byteorder = property(_get_byteorder, _set_byteorder)
@ -204,7 +213,8 @@ class WKBWriter(IOBase):
return wkb_writer_get_outdim(self.ptr)
def _set_outdim(self, new_dim):
if not new_dim in (2, 3): raise ValueError('WKB output dimension must be 2 or 3')
if not new_dim in (2, 3):
raise ValueError('WKB output dimension must be 2 or 3')
wkb_writer_set_outdim(self.ptr, new_dim)
outdim = property(_get_outdim, _set_outdim)
@ -214,8 +224,10 @@ class WKBWriter(IOBase):
return bool(ord(wkb_writer_get_include_srid(self.ptr)))
def _set_include_srid(self, include):
if bool(include): flag = b'\x01'
else: flag = b'\x00'
if bool(include):
flag = b'\x01'
else:
flag = b'\x00'
wkb_writer_set_include_srid(self.ptr, flag)
srid = property(_get_include_srid, _set_include_srid)

View File

@ -11,7 +11,8 @@ from django.contrib.gis.geos.prototypes.threadsafe import GEOSFunc
def binary_predicate(func, *args):
"For GEOS binary predicate functions."
argtypes = [GEOM_PTR, GEOM_PTR]
if args: argtypes += args
if args:
argtypes += args
func.argtypes = argtypes
func.restype = c_char
func.errcheck = check_predicate

View File

@ -11,7 +11,8 @@ class GEOSContextHandle(object):
self.ptr = lgeos.initGEOS_r(notice_h, error_h)
def __del__(self):
if self.ptr: lgeos.finishGEOS_r(self.ptr)
if self.ptr:
lgeos.finishGEOS_r(self.ptr)
# Defining a thread-local object and creating an instance
# to hold a reference to GEOSContextHandle for this thread.

View File

@ -16,7 +16,8 @@ from django.contrib.gis.geos.prototypes.threadsafe import GEOSFunc
def topology(func, *args, **kwargs):
"For GEOS unary topology functions."
argtypes = [GEOM_PTR]
if args: argtypes += args
if args:
argtypes += args
func.argtypes = argtypes
func.restype = kwargs.get('restype', GEOM_PTR)
func.errcheck = kwargs.get('errcheck', check_geom)

View File

@ -143,7 +143,8 @@ class GEOSTest(unittest.TestCase, TestDataMixin):
for tg in self.geometries.wkt_out:
geom = fromstr(tg.wkt)
kml = getattr(tg, 'kml', False)
if kml: self.assertEqual(kml, geom.kml)
if kml:
self.assertEqual(kml, geom.kml)
def test_errors(self):
"Testing the Error handlers."
@ -338,7 +339,8 @@ class GEOSTest(unittest.TestCase, TestDataMixin):
self.assertEqual(ls, LineString(*ls.tuple)) # as individual arguments
self.assertEqual(ls, LineString([list(tup) for tup in ls.tuple])) # as list
self.assertEqual(ls.wkt, LineString(*tuple(Point(tup) for tup in ls.tuple)).wkt) # Point individual arguments
if numpy: self.assertEqual(ls, LineString(numpy.array(ls.tuple))) # as numpy array
if numpy:
self.assertEqual(ls, LineString(numpy.array(ls.tuple))) # as numpy array
def test_multilinestring(self):
"Testing MultiLineString objects."
@ -378,7 +380,8 @@ class GEOSTest(unittest.TestCase, TestDataMixin):
self.assertEqual(lr, LinearRing(lr.tuple))
self.assertEqual(lr, LinearRing(*lr.tuple))
self.assertEqual(lr, LinearRing([list(tup) for tup in lr.tuple]))
if numpy: self.assertEqual(lr, LinearRing(numpy.array(lr.tuple)))
if numpy:
self.assertEqual(lr, LinearRing(numpy.array(lr.tuple)))
def test_polygons_from_bbox(self):
"Testing `from_bbox` class method."
@ -528,8 +531,10 @@ class GEOSTest(unittest.TestCase, TestDataMixin):
self.assertEqual(c1, c2)
# Constructing the test value to set the coordinate sequence with
if len(c1) == 2: tset = (5, 23)
else: tset = (5, 23, 8)
if len(c1) == 2:
tset = (5, 23)
else:
tset = (5, 23, 8)
cs[i] = tset
# Making sure every set point matches what we expect
@ -636,14 +641,16 @@ class GEOSTest(unittest.TestCase, TestDataMixin):
# Testing SRID keyword on fromstr(), and on Polygon rings.
poly = fromstr(self.geometries.polygons[1].wkt, srid=4269)
self.assertEqual(4269, poly.srid)
for ring in poly: self.assertEqual(4269, ring.srid)
for ring in poly:
self.assertEqual(4269, ring.srid)
poly.srid = 4326
self.assertEqual(4326, poly.shell.srid)
# Testing SRID keyword on GeometryCollection
gc = GeometryCollection(Point(5, 23), LineString((0, 0), (1.5, 1.5), (3, 3)), srid=32021)
self.assertEqual(32021, gc.srid)
for i in range(len(gc)): self.assertEqual(32021, gc[i].srid)
for i in range(len(gc)):
self.assertEqual(32021, gc[i].srid)
# GEOS may get the SRID from HEXEWKB
# 'POINT(5 23)' at SRID=4326 in hex form -- obtained from PostGIS
@ -691,7 +698,8 @@ class GEOSTest(unittest.TestCase, TestDataMixin):
# Constructing the new shell by adding 500 to every point in the old shell.
shell_tup = poly.shell.tuple
new_coords = []
for point in shell_tup: new_coords.append((point[0] + 500., point[1] + 500.))
for point in shell_tup:
new_coords.append((point[0] + 500., point[1] + 500.))
new_shell = LinearRing(*tuple(new_coords))
# Assigning polygon's exterior ring w/the new shell
@ -724,7 +732,8 @@ class GEOSTest(unittest.TestCase, TestDataMixin):
# Offsetting the each ring in the polygon by 500.
for j in xrange(len(poly)):
r = poly[j]
for k in xrange(len(r)): r[k] = (r[k][0] + 500., r[k][1] + 500.)
for k in xrange(len(r)):
r[k] = (r[k][0] + 500., r[k][1] + 500.)
poly[j] = r
self.assertNotEqual(mpoly[i], poly)
@ -1017,7 +1026,8 @@ class GEOSTest(unittest.TestCase, TestDataMixin):
g1, g2 = cPickle.loads(s1), pickle.loads(s2)
for tmpg in (g1, g2):
self.assertEqual(geom, tmpg)
if not no_srid: self.assertEqual(geom.srid, tmpg.srid)
if not no_srid:
self.assertEqual(geom.srid, tmpg.srid)
@skipUnless(HAS_GEOS and GEOS_PREPARE, "geos >= 3.1.0 is required")
def test_prepared(self):

View File

@ -12,26 +12,57 @@ if HAS_GEOS:
from ..error import GEOSIndexError
def getItem(o,i): return o[i]
def delItem(o,i): del o[i]
def setItem(o,i,v): o[i] = v
def getItem(o,i):
return o[i]
def delItem(o,i):
del o[i]
def setItem(o,i,v):
o[i] = v
if HAS_GEOS:
def api_get_distance(x): return x.distance(Point(-200,-200))
def api_get_distance(x):
return x.distance(Point(-200,-200))
def api_get_buffer(x): return x.buffer(10)
def api_get_geom_typeid(x): return x.geom_typeid
def api_get_num_coords(x): return x.num_coords
def api_get_centroid(x): return x.centroid
def api_get_empty(x): return x.empty
def api_get_valid(x): return x.valid
def api_get_simple(x): return x.simple
def api_get_ring(x): return x.ring
def api_get_boundary(x): return x.boundary
def api_get_convex_hull(x): return x.convex_hull
def api_get_extent(x): return x.extent
def api_get_area(x): return x.area
def api_get_length(x): return x.length
def api_get_buffer(x):
return x.buffer(10)
def api_get_geom_typeid(x):
return x.geom_typeid
def api_get_num_coords(x):
return x.num_coords
def api_get_centroid(x):
return x.centroid
def api_get_empty(x):
return x.empty
def api_get_valid(x):
return x.valid
def api_get_simple(x):
return x.simple
def api_get_ring(x):
return x.ring
def api_get_boundary(x):
return x.boundary
def api_get_convex_hull(x):
return x.convex_hull
def api_get_extent(x):
return x.extent
def api_get_area(x):
return x.area
def api_get_length(x):
return x.length
geos_function_tests = [val for name, val in vars().items()
if hasattr(val, '__call__')
@ -48,7 +79,8 @@ class GEOSMutationTest(unittest.TestCase):
def test00_GEOSIndexException(self):
'Testing Geometry GEOSIndexError'
p = Point(1,2)
for i in range(-2,2): p._checkindex(i)
for i in range(-2,2):
p._checkindex(i)
self.assertRaises(GEOSIndexError, p._checkindex, 2)
self.assertRaises(GEOSIndexError, p._checkindex, -3)

View File

@ -59,7 +59,8 @@ class ListMixinTest(unittest.TestCase):
listType = UserListA
def lists_of_len(self, length=None):
if length is None: length = self.limit
if length is None:
length = self.limit
pl = list(range(length))
return pl, self.listType(pl)
@ -90,7 +91,8 @@ class ListMixinTest(unittest.TestCase):
def test02_setslice(self):
'Slice assignment'
def setfcn(x,i,j,k,L): x[i:j:k] = range(L)
def setfcn(x,i,j,k,L):
x[i:j:k] = range(L)
pl, ul = self.lists_of_len()
for slen in range(self.limit + 1):
ssl = nextRange(slen)
@ -208,9 +210,12 @@ class ListMixinTest(unittest.TestCase):
def test05_out_of_range_exceptions(self):
'Out of range exceptions'
def setfcn(x, i): x[i] = 20
def getfcn(x, i): return x[i]
def delfcn(x, i): del x[i]
def setfcn(x, i):
x[i] = 20
def getfcn(x, i):
return x[i]
def delfcn(x, i):
del x[i]
pl, ul = self.lists_of_len()
for i in (-1 - self.limit, self.limit):
self.assertRaises(IndexError, setfcn, ul, i) # 'set index %d' % i)
@ -248,7 +253,8 @@ class ListMixinTest(unittest.TestCase):
self.assertEqual(pl[:], ul[:], 'after pop')
pl, ul = self.lists_of_len()
def popfcn(x, i): x.pop(i)
def popfcn(x, i):
x.pop(i)
self.assertRaises(IndexError, popfcn, ul, self.limit)
self.assertRaises(IndexError, popfcn, ul, -1 - self.limit)
@ -265,8 +271,10 @@ class ListMixinTest(unittest.TestCase):
ul.remove(val)
self.assertEqual(pl[:], ul[:], 'after remove val %d' % val)
def indexfcn(x, v): return x.index(v)
def removefcn(x, v): return x.remove(v)
def indexfcn(x, v):
return x.index(v)
def removefcn(x, v):
return x.remove(v)
self.assertRaises(ValueError, indexfcn, ul, 40)
self.assertRaises(ValueError, removefcn, ul, 40)
@ -276,7 +284,8 @@ class ListMixinTest(unittest.TestCase):
ul._allowed = six.integer_types
ul[1] = 50
ul[:2] = [60, 70, 80]
def setfcn(x, i, v): x[i] = v
def setfcn(x, i, v):
x[i] = v
self.assertRaises(TypeError, setfcn, ul, 2, 'hello')
self.assertRaises(TypeError, setfcn, ul, slice(0,3,2), ('hello','goodbye'))
@ -284,8 +293,10 @@ class ListMixinTest(unittest.TestCase):
'Length limits'
pl, ul = self.lists_of_len()
ul._minlength = 1
def delfcn(x,i): del x[:i]
def setfcn(x,i): x[:i] = []
def delfcn(x,i):
del x[:i]
def setfcn(x,i):
x[:i] = []
for i in range(self.limit - ul._minlength + 1, self.limit + 1):
self.assertRaises(ValueError, delfcn, ul, i)
self.assertRaises(ValueError, setfcn, ul, i)
@ -299,7 +310,8 @@ class ListMixinTest(unittest.TestCase):
def test09_iterable_check(self):
'Error on assigning non-iterable to slice'
pl, ul = self.lists_of_len(self.limit + 1)
def setfcn(x, i, v): x[i] = v
def setfcn(x, i, v):
x[i] = v
self.assertRaises(TypeError, setfcn, ul, slice(0,3,2), 2)
def test10_checkindex(self):

View File

@ -87,9 +87,11 @@ class GoogleMap(object):
# Defaults for the zoom level and center coordinates if the zoom
# is not automatically calculated.
if zoom is None: zoom = 4
if zoom is None:
zoom = 4
self.zoom = zoom
if center is None: center = (0, 0)
if center is None:
center = (0, 0)
self.center = center
def render(self):
@ -229,5 +231,6 @@ class GoogleMapSet(GoogleMap):
def icons(self):
"Returns a sequence of all icons in each map of the set."
icons = set()
for map in self.maps: icons |= map.icons
for map in self.maps:
icons |= map.icons
return icons

View File

@ -102,8 +102,10 @@ class GPolygon(GOverlayBase):
fill_opacity:
The opacity of the polygon fill. Defaults to 0.4.
"""
if isinstance(poly, six.string_types): poly = fromstr(poly)
if isinstance(poly, (tuple, list)): poly = Polygon(poly)
if isinstance(poly, six.string_types):
poly = fromstr(poly)
if isinstance(poly, (tuple, list)):
poly = Polygon(poly)
if not isinstance(poly, Polygon):
raise TypeError('GPolygon may only initialize on GEOS Polygons.')
@ -152,8 +154,10 @@ class GPolyline(GOverlayBase):
The opacity of the polyline, between 0 and 1. Defaults to 1.
"""
# If a GEOS geometry isn't passed in, try to contsruct one.
if isinstance(geom, six.string_types): geom = fromstr(geom)
if isinstance(geom, (tuple, list)): geom = Polygon(geom)
if isinstance(geom, six.string_types):
geom = fromstr(geom)
if isinstance(geom, (tuple, list)):
geom = Polygon(geom)
# Generating the lat/lng coordinate pairs.
if isinstance(geom, (LineString, LinearRing)):
self.latlngs = self.latlng_from_coords(geom.coords)
@ -282,8 +286,10 @@ class GMarker(GOverlayBase):
Draggable option for GMarker, disabled by default.
"""
# If a GEOS geometry isn't passed in, try to construct one.
if isinstance(geom, six.string_types): geom = fromstr(geom)
if isinstance(geom, (tuple, list)): geom = Point(geom)
if isinstance(geom, six.string_types):
geom = fromstr(geom)
if isinstance(geom, (tuple, list)):
geom = Point(geom)
if isinstance(geom, Point):
self.latlng = self.latlng_from_coords(geom.coords)
else:
@ -301,9 +307,12 @@ class GMarker(GOverlayBase):
def options(self):
result = []
if self.title: result.append('title: "%s"' % self.title)
if self.icon: result.append('icon: %s' % self.icon.varname)
if self.draggable: result.append('draggable: true')
if self.title:
result.append('title: "%s"' % self.title)
if self.icon:
result.append('icon: %s' % self.icon.varname)
if self.draggable:
result.append('draggable: true')
return '{%s}' % ','.join(result)
@property

View File

@ -179,7 +179,8 @@ class MeasureBase(object):
val = 0.0
default_unit = self.STANDARD_UNIT
for unit, value in six.iteritems(kwargs):
if not isinstance(value, float): value = float(value)
if not isinstance(value, float):
value = float(value)
if unit in self.UNITS:
val += self.UNITS[unit] * value
default_unit = unit

View File

@ -27,7 +27,8 @@ class GeoRSSSitemap(Sitemap):
# Setting up.
self.feed_dict = feed_dict
self.locations = []
if slug_dict is None: slug_dict = {}
if slug_dict is None:
slug_dict = {}
# Getting the feed locations.
for section in feed_dict.keys():
if slug_dict.get(section, False):
@ -42,7 +43,8 @@ class GeoRSSSitemap(Sitemap):
is placed on each URL element.
"""
urls = Sitemap.get_urls(self, page=page, site=site)
for url in urls: url['geo_format'] = 'georss'
for url in urls:
url['geo_format'] = 'georss'
return urls
def items(self):

View File

@ -46,7 +46,8 @@ class KMLSitemap(Sitemap):
is placed on each URL element.
"""
urls = Sitemap.get_urls(self, page=page, site=site)
for url in urls: url['geo_format'] = self.geo_format
for url in urls:
url['geo_format'] = self.geo_format
return urls
def items(self):

View File

@ -7,7 +7,9 @@ class SouthTexasCity(models.Model):
name = models.CharField(max_length=30)
point = models.PointField(srid=32140)
objects = models.GeoManager()
def __str__(self): return self.name
def __str__(self):
return self.name
@python_2_unicode_compatible
class SouthTexasCityFt(models.Model):
@ -15,7 +17,9 @@ class SouthTexasCityFt(models.Model):
name = models.CharField(max_length=30)
point = models.PointField(srid=2278)
objects = models.GeoManager()
def __str__(self): return self.name
def __str__(self):
return self.name
@python_2_unicode_compatible
class AustraliaCity(models.Model):
@ -23,7 +27,9 @@ class AustraliaCity(models.Model):
name = models.CharField(max_length=30)
point = models.PointField()
objects = models.GeoManager()
def __str__(self): return self.name
def __str__(self):
return self.name
@python_2_unicode_compatible
class CensusZipcode(models.Model):
@ -31,7 +37,9 @@ class CensusZipcode(models.Model):
name = models.CharField(max_length=5)
poly = models.PolygonField(srid=4269)
objects = models.GeoManager()
def __str__(self): return self.name
def __str__(self):
return self.name
@python_2_unicode_compatible
class SouthTexasZipcode(models.Model):
@ -39,7 +47,9 @@ class SouthTexasZipcode(models.Model):
name = models.CharField(max_length=5)
poly = models.PolygonField(srid=32140, null=True)
objects = models.GeoManager()
def __str__(self): return self.name
def __str__(self):
return self.name
@python_2_unicode_compatible
class Interstate(models.Model):
@ -47,7 +57,9 @@ class Interstate(models.Model):
name = models.CharField(max_length=10)
path = models.LineStringField()
objects = models.GeoManager()
def __str__(self): return self.name
def __str__(self):
return self.name
@python_2_unicode_compatible
class SouthTexasInterstate(models.Model):
@ -55,4 +67,6 @@ class SouthTexasInterstate(models.Model):
name = models.CharField(max_length=10)
path = models.LineStringField(srid=32140)
objects = models.GeoManager()
def __str__(self): return self.name
def __str__(self):
return self.name

View File

@ -66,8 +66,10 @@ class DistanceTest(TestCase):
# Performing distance queries on two projected coordinate systems one
# with units in meters and the other in units of U.S. survey feet.
for dist in tx_dists:
if isinstance(dist, tuple): dist1, dist2 = dist
else: dist1 = dist2 = dist
if isinstance(dist, tuple):
dist1, dist2 = dist
else:
dist1 = dist2 = dist
qs1 = SouthTexasCity.objects.filter(point__dwithin=(self.stx_pnt, dist1))
qs2 = SouthTexasCityFt.objects.filter(point__dwithin=(self.stx_pnt, dist2))
for qs in qs1, qs2:
@ -75,12 +77,16 @@ class DistanceTest(TestCase):
# Now performing the `dwithin` queries on a geodetic coordinate system.
for dist in au_dists:
if isinstance(dist, D) and not oracle: type_error = True
else: type_error = False
if isinstance(dist, D) and not oracle:
type_error = True
else:
type_error = False
if isinstance(dist, tuple):
if oracle: dist = dist[1]
else: dist = dist[0]
if oracle:
dist = dist[1]
else:
dist = dist[0]
# Creating the query set.
qs = AustraliaCity.objects.order_by('name')

View File

@ -7,6 +7,8 @@ class City(models.Model):
name = models.CharField(max_length=30)
point = models.PointField()
objects = models.GeoManager()
def __str__(self): return self.name
def __str__(self):
return self.name
admin.site.register(City, admin.OSMGeoAdmin)

View File

@ -10,14 +10,18 @@ class Country(models.Model):
name = models.CharField(max_length=30)
mpoly = models.MultiPolygonField() # SRID, by default, is 4326
objects = models.GeoManager()
def __str__(self): return self.name
def __str__(self):
return self.name
@python_2_unicode_compatible
class City(models.Model):
name = models.CharField(max_length=30)
point = models.PointField()
objects = models.GeoManager()
def __str__(self): return self.name
def __str__(self):
return self.name
# This is an inherited model from City
class PennsylvaniaCity(City):
@ -30,14 +34,18 @@ class State(models.Model):
name = models.CharField(max_length=30)
poly = models.PolygonField(null=null_flag) # Allowing NULL geometries here.
objects = models.GeoManager()
def __str__(self): return self.name
def __str__(self):
return self.name
@python_2_unicode_compatible
class Track(models.Model):
name = models.CharField(max_length=30)
line = models.LineStringField()
objects = models.GeoManager()
def __str__(self): return self.name
def __str__(self):
return self.name
class Truth(models.Model):
val = models.BooleanField(default=False)
@ -49,7 +57,9 @@ if not spatialite:
name = models.CharField(max_length=20)
geom = models.GeometryField()
objects = models.GeoManager()
def __str__(self): return self.name
def __str__(self):
return self.name
class MinusOneSRID(models.Model):
geom = models.PointField(srid=-1) # Minus one SRID.

View File

@ -190,7 +190,8 @@ class GeoModelTest(TestCase):
qs = PennsylvaniaCity.objects.transform(32128)
self.assertEqual(1, qs.count())
for pc in qs: self.assertEqual(32128, pc.point.srid)
for pc in qs:
self.assertEqual(32128, pc.point.srid)
def test_raw_sql_query(self):
"Testing raw SQL query."
@ -229,7 +230,8 @@ class GeoLookupTest(TestCase):
qs = City.objects.filter(point__contained=texas.mpoly)
self.assertEqual(3, qs.count())
cities = ['Houston', 'Dallas', 'Oklahoma City']
for c in qs: self.assertEqual(True, c.name in cities)
for c in qs:
self.assertEqual(True, c.name in cities)
# Pulling out some cities.
houston = City.objects.get(name='Houston')
@ -284,13 +286,15 @@ class GeoLookupTest(TestCase):
'Lawrence', 'Chicago', 'Wellington']
qs = City.objects.filter(point__right=co_border)
self.assertEqual(6, len(qs))
for c in qs: self.assertEqual(True, c.name in cities)
for c in qs:
self.assertEqual(True, c.name in cities)
# These cities should be strictly to the right of the KS border.
cities = ['Chicago', 'Wellington']
qs = City.objects.filter(point__right=ks_border)
self.assertEqual(2, len(qs))
for c in qs: self.assertEqual(True, c.name in cities)
for c in qs:
self.assertEqual(True, c.name in cities)
# Note: Wellington has an 'X' value of 174, so it will not be considered
# to the left of CO.
@ -300,7 +304,8 @@ class GeoLookupTest(TestCase):
cities = ['Pueblo', 'Victoria']
qs = City.objects.filter(point__left=ks_border)
self.assertEqual(2, len(qs))
for c in qs: self.assertEqual(True, c.name in cities)
for c in qs:
self.assertEqual(True, c.name in cities)
# The left/right lookup tests are known failures on PostGIS 2.0/2.0.1
# http://trac.osgeo.org/postgis/ticket/2035
@ -313,7 +318,8 @@ class GeoLookupTest(TestCase):
c1 = City.objects.get(point=pnt)
c2 = City.objects.get(point__same_as=pnt)
c3 = City.objects.get(point__equals=pnt)
for c in [c1, c2, c3]: self.assertEqual('Houston', c.name)
for c in [c1, c2, c3]:
self.assertEqual('Houston', c.name)
@no_mysql
def test_null_geometries(self):
@ -476,7 +482,8 @@ class GeoQuerySetTest(TestCase):
@no_spatialite
def test_geohash(self):
"Testing GeoQuerySet.geohash()."
if not connection.ops.geohash: return
if not connection.ops.geohash:
return
# Reference query:
# SELECT ST_GeoHash(point) FROM geoapp_city WHERE name='Houston';
# SELECT ST_GeoHash(point, 5) FROM geoapp_city WHERE name='Houston';
@ -619,7 +626,8 @@ class GeoQuerySetTest(TestCase):
if not oracle:
# Oracle cannot count vertices in Point geometries.
for c in City.objects.num_points(): self.assertEqual(1, c.num_points)
for c in City.objects.num_points():
self.assertEqual(1, c.num_points)
@no_mysql
def test_point_on_surface(self):

View File

@ -6,14 +6,18 @@ class City(models.Model):
name = models.CharField(max_length=30)
point = models.PointField(geography=True)
objects = models.GeoManager()
def __str__(self): return self.name
def __str__(self):
return self.name
@python_2_unicode_compatible
class Zipcode(models.Model):
code = models.CharField(max_length=10)
poly = models.PolygonField(geography=True)
objects = models.GeoManager()
def __str__(self): return self.code
def __str__(self):
return self.code
@python_2_unicode_compatible
class County(models.Model):
@ -21,4 +25,6 @@ class County(models.Model):
state = models.CharField(max_length=20)
mpoly = models.MultiPolygonField(geography=True)
objects = models.GeoManager()
def __str__(self): return ' County, '.join([self.name, self.state])
def __str__(self):
return ' County, '.join([self.name, self.state])

View File

@ -208,7 +208,8 @@ class LayerMapTest(TestCase):
def test_test_fid_range_step(self):
"Tests the `fid_range` keyword and the `step` keyword of .save()."
# Function for clearing out all the counties before testing.
def clear_counties(): County.objects.all().delete()
def clear_counties():
County.objects.all().delete()
State.objects.bulk_create([
State(name='Colorado'), State(name='Hawaii'), State(name='Texas')

View File

@ -5,7 +5,9 @@ from django.utils.encoding import python_2_unicode_compatible
class Location(models.Model):
point = models.PointField()
objects = models.GeoManager()
def __str__(self): return self.point.wkt
def __str__(self):
return self.point.wkt
@python_2_unicode_compatible
class City(models.Model):
@ -13,7 +15,9 @@ class City(models.Model):
state = models.CharField(max_length=2)
location = models.ForeignKey(Location)
objects = models.GeoManager()
def __str__(self): return self.name
def __str__(self):
return self.name
class AugmentedLocation(Location):
extra_text = models.TextField(blank=True)
@ -34,7 +38,9 @@ class Parcel(models.Model):
border1 = models.PolygonField()
border2 = models.PolygonField(srid=2276)
objects = models.GeoManager()
def __str__(self): return self.name
def __str__(self):
return self.name
# These use the GeoManager but do not have any geographic fields.
class Author(models.Model):

View File

@ -79,7 +79,8 @@ class RelatedGeoModelTest(TestCase):
# between the Oracle and PostGIS spatial backends on the extent calculation.
tol = 4
for ref, e in [(all_extent, e1), (txpa_extent, e2), (all_extent, e3)]:
for ref_val, e_val in zip(ref, e): self.assertAlmostEqual(ref_val, e_val, tol)
for ref_val, e_val in zip(ref, e):
self.assertAlmostEqual(ref_val, e_val, tol)
@no_mysql
def test04b_related_union_aggregate(self):

View File

@ -16,10 +16,17 @@ def no_backend(test_func, backend):
# Decorators to disable entire test functions for specific
# spatial backends.
def no_oracle(func): return no_backend(func, 'oracle')
def no_postgis(func): return no_backend(func, 'postgis')
def no_mysql(func): return no_backend(func, 'mysql')
def no_spatialite(func): return no_backend(func, 'spatialite')
def no_oracle(func):
return no_backend(func, 'oracle')
def no_postgis(func):
return no_backend(func, 'postgis')
def no_mysql(func):
return no_backend(func, 'mysql')
def no_spatialite(func):
return no_backend(func, 'spatialite')
# Shortcut booleans to omit only portions of tests.
_default_db = settings.DATABASES[DEFAULT_DB_ALIAS]['ENGINE'].rsplit('.')[-1]

View File

@ -21,11 +21,20 @@ from django.utils.encoding import force_text
# LayerMapping exceptions.
class LayerMapError(Exception): pass
class InvalidString(LayerMapError): pass
class InvalidDecimal(LayerMapError): pass
class InvalidInteger(LayerMapError): pass
class MissingForeignKey(LayerMapError): pass
class LayerMapError(Exception):
pass
class InvalidString(LayerMapError):
pass
class InvalidDecimal(LayerMapError):
pass
class InvalidInteger(LayerMapError):
pass
class MissingForeignKey(LayerMapError):
pass
class LayerMapping(object):
"A class that maps OGR Layers to GeoDjango Models."
@ -263,10 +272,12 @@ class LayerMapping(object):
if isinstance(unique, (list, tuple)):
# List of fields to determine uniqueness with
for attr in unique:
if not attr in self.mapping: raise ValueError
if not attr in self.mapping:
raise ValueError
elif isinstance(unique, six.string_types):
# Only a single field passed in.
if unique not in self.mapping: raise ValueError
if unique not in self.mapping:
raise ValueError
else:
raise TypeError('Unique keyword argument must be set with a tuple, list, or string.')
@ -413,7 +424,8 @@ class LayerMapping(object):
# Transforming the geometry with our Coordinate Transformation object,
# but only if the class variable `transform` is set w/a CoordTransform
# object.
if self.transform: g.transform(self.transform)
if self.transform:
g.transform(self.transform)
# Returning the WKT of the geometry.
return g.wkt
@ -512,7 +524,8 @@ class LayerMapping(object):
kwargs = self.feature_kwargs(feat)
except LayerMapError as msg:
# Something borked the validation
if strict: raise
if strict:
raise
elif not silent:
stream.write('Ignoring Feature ID %s because: %s\n' % (feat.fid, msg))
else:
@ -534,7 +547,8 @@ class LayerMapping(object):
# just-updated geometry WKT.
geom = getattr(m, self.geom_field).ogr
new = OGRGeometry(kwargs[self.geom_field])
for g in new: geom.add(g)
for g in new:
geom.add(g)
setattr(m, self.geom_field, geom.wkt)
except ObjectDoesNotExist:
# No unique model exists yet, create.
@ -546,7 +560,8 @@ class LayerMapping(object):
# Attempting to save.
m.save(using=self.using)
num_saved += 1
if verbose: stream.write('%s: %s\n' % ('Updated' if is_update else 'Saved', m))
if verbose:
stream.write('%s: %s\n' % ('Updated' if is_update else 'Saved', m))
except Exception as msg:
if strict:
# Bailing out if the `strict` keyword is set.
@ -580,8 +595,10 @@ class LayerMapping(object):
for i, end in enumerate(indices):
# Constructing the slice to use for this step; the last slice is
# special (e.g, [100:] instead of [90:100]).
if i+1 == n_i: step_slice = slice(beg, None)
else: step_slice = slice(beg, end)
if i+1 == n_i:
step_slice = slice(beg, None)
else:
step_slice = slice(beg, end)
try:
num_feat, num_saved = _save(step_slice, num_feat, num_saved)

View File

@ -37,11 +37,14 @@ def mapping(data_source, geom_name='geom', layer_key=0, multi_geom=False):
# Generating the field name for each field in the layer.
for field in data_source[layer_key].fields:
mfield = field.lower()
if mfield[-1:] == '_': mfield += 'field'
if mfield[-1:] == '_':
mfield += 'field'
_mapping[mfield] = field
gtype = data_source[layer_key].geom_type
if multi_geom and gtype.num in (1, 2, 3): prefix = 'MULTI'
else: prefix = ''
if multi_geom and gtype.num in (1, 2, 3):
prefix = 'MULTI'
else:
prefix = ''
_mapping[geom_name] = prefix + str(gtype).upper()
return _mapping
@ -151,10 +154,14 @@ def _ogrinspect(data_source, model_name, geom_name='geom', layer_key=0, srid=Non
# Gets the `null` and `blank` keywords for the given field name.
def get_kwargs_str(field_name):
kwlist = []
if field_name.lower() in null_fields: kwlist.append('null=True')
if field_name.lower() in blank_fields: kwlist.append('blank=True')
if kwlist: return ', ' + ', '.join(kwlist)
else: return ''
if field_name.lower() in null_fields:
kwlist.append('null=True')
if field_name.lower() in blank_fields:
kwlist.append('blank=True')
if kwlist:
return ', ' + ', '.join(kwlist)
else:
return ''
# For those wishing to disable the imports.
if imports:
@ -167,7 +174,8 @@ def _ogrinspect(data_source, model_name, geom_name='geom', layer_key=0, srid=Non
for field_name, width, precision, field_type in zip(ogr_fields, layer.field_widths, layer.field_precisions, layer.field_types):
# The model field name.
mfield = field_name.lower()
if mfield[-1:] == '_': mfield += 'field'
if mfield[-1:] == '_':
mfield += 'field'
# Getting the keyword args string.
kwargs_str = get_kwargs_str(field_name)

View File

@ -27,7 +27,8 @@ def color_style():
DJANGO_COLORS = os.environ.get('DJANGO_COLORS', '')
color_settings = termcolors.parse_color_setting(DJANGO_COLORS)
if color_settings:
class dummy: pass
class dummy:
pass
style = dummy()
# The nocolor palette has all available roles.
# Use that palette as the basis for populating

View File

@ -48,7 +48,8 @@ class ErrorDict(dict):
return self.as_ul()
def as_ul(self):
if not self: return ''
if not self:
return ''
return format_html('<ul class="errorlist">{0}</ul>',
format_html_join('', '<li>{0}{1}</li>',
((k, force_text(v))
@ -67,7 +68,8 @@ class ErrorList(list):
return self.as_ul()
def as_ul(self):
if not self: return ''
if not self:
return ''
return format_html('<ul class="errorlist">{0}</ul>',
format_html_join('', '<li>{0}</li>',
((force_text(e),) for e in self)
@ -75,7 +77,8 @@ class ErrorList(list):
)
def as_text(self):
if not self: return ''
if not self:
return ''
return '\n'.join('* %s' % force_text(e) for e in self)
def __repr__(self):

View File

@ -273,7 +273,8 @@ class PasswordInput(TextInput):
self.render_value = render_value
def render(self, name, value, attrs=None):
if not self.render_value: value=None
if not self.render_value:
value=None
return super(PasswordInput, self).render(name, value, attrs)
class HiddenInput(Input):
@ -291,7 +292,8 @@ class MultipleHiddenInput(HiddenInput):
self.choices = choices
def render(self, name, value, attrs=None, choices=()):
if value is None: value = []
if value is None:
value = []
final_attrs = self.build_attrs(attrs, type=self.input_type, name=name)
id_ = final_attrs.get('id', None)
inputs = []
@ -394,7 +396,8 @@ class Textarea(Widget):
super(Textarea, self).__init__(default_attrs)
def render(self, name, value, attrs=None):
if value is None: value = ''
if value is None:
value = ''
final_attrs = self.build_attrs(attrs, name=name)
return format_html('<textarea{0}>\r\n{1}</textarea>',
flatatt(final_attrs),
@ -469,7 +472,8 @@ class Select(Widget):
self.choices = list(choices)
def render(self, name, value, attrs=None, choices=()):
if value is None: value = ''
if value is None:
value = ''
final_attrs = self.build_attrs(attrs, name=name)
output = [format_html('<select{0}>', flatatt(final_attrs))]
options = self.render_options(choices, [value])
@ -539,7 +543,8 @@ class SelectMultiple(Select):
allow_multiple_selected = True
def render(self, name, value, attrs=None, choices=()):
if value is None: value = []
if value is None:
value = []
final_attrs = self.build_attrs(attrs, name=name)
output = [format_html('<select multiple="multiple"{0}>', flatatt(final_attrs))]
options = self.render_options(choices, value)

View File

@ -234,8 +234,10 @@ def get_text_list(list_, last_word=ugettext_lazy('or')):
>>> get_text_list([])
''
"""
if len(list_) == 0: return ''
if len(list_) == 1: return force_text(list_[0])
if len(list_) == 0:
return ''
if len(list_) == 1:
return force_text(list_[0])
return '%s %s %s' % (
# Translators: This string is used as a separator between list elements
_(', ').join(force_text(i) for i in list_[:-1]),

View File

@ -7,7 +7,8 @@ from django.utils.encoding import force_text
from django.utils.safestring import mark_safe, SafeData
def ngettext(singular, plural, number):
if number == 1: return singular
if number == 1:
return singular
return plural
ngettext_lazy = ngettext

View File

@ -7,7 +7,8 @@ from xml.sax.saxutils import XMLGenerator
class SimplerXMLGenerator(XMLGenerator):
def addQuickElement(self, name, contents=None, attrs=None):
"Convenience method for adding an element with no children"
if attrs is None: attrs = {}
if attrs is None:
attrs = {}
self.startElement(name, attrs)
if contents is not None:
self.characters(contents)

View File

@ -4,7 +4,7 @@ install-script = scripts/rpm-install.sh
[flake8]
exclude=./django/utils/dictconfig.py,./django/contrib/comments/*,./django/utils/unittest.py,./tests/comment_tests/*,./django/test/_doctest.py
ignore=E123,E124,E125,E126,E127,E128,E225,E226,E241,E251,E302,E501,E121,E122,E203,E221,E227,E231,E261,E301,E303,E502,E701,F401,F403,F841,W601
ignore=E123,E124,E125,E126,E127,E128,E225,E226,E241,E251,E302,E501,E121,E122,E203,E221,E227,E231,E261,E301,E303,E502,F401,F403,F841,W601
[metadata]
license-file = LICENSE

View File

@ -94,8 +94,11 @@ class DecoratorsTest(TestCase):
callback = user_passes_test(test1)(callback)
callback = user_passes_test(test2)(callback)
class DummyUser(object): pass
class DummyRequest(object): pass
class DummyUser(object):
pass
class DummyRequest(object):
pass
request = DummyRequest()
request.user = DummyUser()

View File

@ -224,7 +224,8 @@ class FormsErrorMessagesTestCase(TestCase, AssertFormErrorsMixin):
return self.as_divs()
def as_divs(self):
if not self: return ''
if not self:
return ''
return mark_safe('<div class="error">%s</div>' % ''.join('<p>%s</p>' % e for e in self))
# This form should print errors the default way.

View File

@ -727,7 +727,8 @@ class FormsExtraTestCase(TestCase, AssertFormErrorsMixin):
return self.as_divs()
def as_divs(self):
if not self: return ''
if not self:
return ''
return '<div class="errorlist">%s</div>' % ''.join('<div class="error">%s</div>' % force_text(e) for e in self)
class CommentForm(Form):

View File

@ -49,7 +49,8 @@ class FormsUtilTestCase(TestCase):
@python_2_unicode_compatible
class VeryBadError:
def __str__(self): return "A very bad error."
def __str__(self):
return "A very bad error."
# Can take a non-string.
self.assertHTMLEqual(str(ErrorList(ValidationError(VeryBadError()).messages)),