Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

More attacking E302 violators

  • Loading branch information...
commit 7548aa8ffd46eb6e0f73730d1b2eb515ba581f95 1 parent 65c4ac3
@alex alex authored
Showing with 433 additions and 1 deletion.
  1. +2 −0  django/contrib/gis/db/backends/spatialite/operations.py
  2. +1 −0  django/contrib/gis/gdal/error.py
  3. +8 −0 django/contrib/gis/gdal/geometries.py
  4. +1 −1  django/contrib/gis/gdal/geomtype.py
  5. +8 −0 django/contrib/gis/gdal/libgdal.py
  6. +11 −0 django/contrib/gis/gdal/prototypes/errcheck.py
  7. +9 −0 django/contrib/gis/gdal/prototypes/generation.py
  8. +3 −0  django/contrib/gis/gdal/prototypes/geom.py
  9. +2 −0  django/contrib/gis/gdal/prototypes/srs.py
  10. +7 −0 django/contrib/gis/geoip/prototypes.py
  11. +4 −0 django/contrib/gis/geos/collections.py
  12. +1 −0  django/contrib/gis/geos/coordseq.py
  13. +2 −0  django/contrib/gis/geos/error.py
  14. +11 −0 django/contrib/gis/geos/libgeos.py
  15. +2 −0  django/contrib/gis/geos/linestring.py
  16. +1 −0  django/contrib/gis/geos/point.py
  17. +6 −0 django/contrib/gis/geos/prototypes/coordseq.py
  18. +8 −0 django/contrib/gis/geos/prototypes/errcheck.py
  19. +7 −0 django/contrib/gis/geos/prototypes/geom.py
  20. +18 −0 django/contrib/gis/geos/prototypes/io.py
  21. +1 −0  django/contrib/gis/geos/prototypes/misc.py
  22. +2 −0  django/contrib/gis/geos/prototypes/predicates.py
  23. +1 −0  django/contrib/gis/geos/prototypes/prepared.py
  24. +3 −0  django/contrib/gis/geos/prototypes/threadsafe.py
  25. +1 −0  django/contrib/gis/geos/prototypes/topology.py
  26. +13 −0 django/contrib/gis/geos/tests/test_geos_mutation.py
  27. +4 −0 django/contrib/gis/geos/tests/test_mutable_list.py
  28. +1 −0  django/contrib/gis/management/commands/inspectdb.py
  29. +3 −0  django/contrib/gis/management/commands/ogrinspect.py
  30. +2 −0  django/contrib/gis/maps/google/gmap.py
  31. +4 −0 django/contrib/gis/maps/google/overlays.py
  32. +1 −0  django/contrib/gis/maps/google/zoom.py
  33. +3 −0  django/contrib/gis/sitemaps/views.py
  34. +7 −0 django/contrib/gis/tests/distapp/models.py
  35. +10 −0 django/contrib/gis/tests/geo3d/models.py
  36. +1 −0  django/contrib/gis/tests/geoadmin/models.py
  37. +6 −0 django/contrib/gis/tests/geoapp/feeds.py
  38. +6 −0 django/contrib/gis/tests/geoapp/models.py
  39. +3 −0  django/contrib/gis/tests/geogapp/models.py
  40. +1 −0  django/contrib/gis/tests/inspectapp/models.py
  41. +9 −0 django/contrib/gis/tests/layermap/models.py
  42. +1 −0  django/contrib/gis/tests/layermap/tests.py
  43. +8 −0 django/contrib/gis/tests/relatedapp/models.py
  44. +2 −0  django/contrib/gis/tests/test_measure.py
  45. +3 −0  django/contrib/gis/tests/test_spatialrefsys.py
  46. +5 −0 django/contrib/gis/utils/layermapping.py
  47. +1 −0  django/contrib/gis/utils/ogrinfo.py
  48. +3 −0  django/contrib/gis/utils/ogrinspect.py
  49. +1 −0  django/contrib/gis/utils/srs.py
  50. +1 −0  django/contrib/gis/utils/wkt.py
  51. +1 −0  django/contrib/messages/storage/cookie.py
  52. +1 −0  django/contrib/messages/storage/fallback.py
  53. +1 −0  django/contrib/messages/tests/test_mixins.py
  54. +4 −0 django/contrib/messages/tests/urls.py
  55. +1 −0  django/contrib/redirects/models.py
  56. +2 −0  django/contrib/sessions/backends/base.py
  57. +1 −0  django/contrib/sessions/backends/db.py
  58. +1 −0  django/contrib/sessions/backends/file.py
  59. +1 −0  django/contrib/sessions/middleware.py
  60. +1 −0  django/contrib/sitemaps/tests/test_flatpages.py
  61. +1 −0  django/contrib/sitemaps/tests/test_https.py
  62. +1 −0  django/contrib/sitemaps/tests/urls/https.py
  63. +3 −0  django/contrib/sitemaps/views.py
  64. +1 −0  django/contrib/sites/managers.py
  65. +1 −0  django/contrib/staticfiles/management/commands/findstatic.py
  66. +1 −0  django/contrib/staticfiles/management/commands/runserver.py
  67. +3 −0  django/contrib/staticfiles/utils.py
  68. +1 −0  django/contrib/staticfiles/views.py
  69. +4 −0 django/contrib/webdesign/lorem_ipsum.py
  70. +2 −0  django/contrib/webdesign/templatetags/webdesign.py
  71. +3 −0  django/core/cache/backends/db.py
  72. +2 −0  django/core/cache/backends/dummy.py
  73. +1 −0  django/core/cache/backends/filebased.py
  74. +2 −0  django/core/cache/backends/memcached.py
  75. +2 −0  django/core/checks/compatibility/django_1_6_0.py
  76. +6 −0 django/core/context_processors.py
  77. +2 −0  django/core/files/base.py
  78. +1 −0  django/core/files/locks.py
  79. +2 −0  django/core/files/move.py
  80. +4 −0 django/core/files/storage.py
  81. +7 −0 django/core/files/uploadhandler.py
  82. +1 −0  django/core/mail/backends/base.py
  83. +1 −0  django/core/mail/backends/console.py
  84. +1 −0  django/core/mail/backends/dummy.py
  85. +1 −0  django/core/mail/backends/filebased.py
  86. +1 −0  django/core/mail/backends/locmem.py
  87. +8 −0 django/core/management/__init__.py
  88. +3 −0  django/core/management/color.py
  89. +2 −0  django/core/management/commands/compilemessages.py
  90. +1 −0  django/core/management/commands/dbshell.py
  91. +2 −0  django/core/management/commands/diffsettings.py
  92. +1 −0  django/core/management/commands/dumpdata.py
  93. +1 −0  django/core/management/commands/makemessages.py
  94. +1 −0  django/core/management/commands/runfcgi.py
  95. +1 −0  django/core/management/commands/sql.py
  96. +1 −0  django/core/management/commands/sqlclear.py
  97. +1 −0  django/core/management/commands/sqlcustom.py
  98. +1 −0  django/core/management/commands/sqldropindexes.py
  99. +1 −0  django/core/management/commands/sqlflush.py
  100. +1 −0  django/core/management/commands/sqlindexes.py
  101. +1 −0  django/core/management/commands/sqlinitialdata.py
  102. +1 −0  django/core/management/commands/sqlsequencereset.py
  103. +1 −0  django/core/management/commands/testserver.py
  104. +1 −0  django/core/management/utils.py
  105. +7 −0 django/core/serializers/__init__.py
  106. +7 −0 django/core/serializers/base.py
  107. +1 −0  django/core/serializers/json.py
  108. +1 −0  django/core/serializers/python.py
  109. +2 −0  django/core/serializers/pyyaml.py
  110. +2 −0  django/core/serializers/xml_serializer.py
  111. +2 −0  django/core/servers/fastcgi.py
  112. +18 −0 django/core/urlresolvers.py
  113. +1 −0  django/db/migrations/optimizer.py
  114. +1 −0  django/db/models/fields/related.py
  115. +2 −0  django/db/models/loading.py
  116. +2 −0  django/db/models/options.py
  117. +4 −0 django/dispatch/saferef.py
  118. +1 −0  django/forms/forms.py
  119. +4 −0 django/forms/formsets.py
  120. +5 −0 django/forms/utils.py
  121. +2 −0  django/forms/widgets.py
  122. +3 −0  django/http/multipartparser.py
  123. +2 −0  django/middleware/cache.py
  124. +1 −0  django/middleware/clickjacking.py
  125. +1 −0  django/middleware/csrf.py
  126. +1 −0  django/middleware/gzip.py
  127. +1 −0  django/middleware/http.py
  128. +1 −0  django/middleware/transaction.py
  129. +7 −0 django/shortcuts/__init__.py
  130. +4 −0 django/template/base.py
  131. +1 −0  django/template/context.py
  132. +2 −0  django/template/debug.py
  133. +1 −0  django/template/defaultfilters.py
  134. +1 −0  django/template/smartif.py
  135. +1 −0  django/templatetags/cache.py
  136. +2 −0  django/utils/_os.py
  137. +1 −0  django/utils/autoreload.py
  138. +1 −0  django/utils/baseconv.py
  139. +1 −0  django/utils/checksums.py
  140. +2 −0  django/utils/datetime_safe.py
  141. +2 −0  django/utils/encoding.py
  142. +1 −0  django/utils/feedgenerator.py
  143. +2 −0  django/utils/html.py
  144. +3 −0  django/utils/ipv6.py
  145. +4 −0 django/utils/regex_helper.py
  146. +3 −0  django/utils/safestring.py
  147. +1 −0  django/utils/tree.py
  148. +1 −0  django/utils/tzinfo.py
  149. +2 −0  django/utils/version.py
  150. +1 −0  django/utils/xmlutils.py
View
2  django/contrib/gis/db/backends/spatialite/operations.py
@@ -53,6 +53,8 @@ def __init__(self, pattern):
# Valid distance types and substitutions
dtypes = (Decimal, Distance, float) + six.integer_types
+
+
def get_dist_ops(operator):
"Returns operations for regular distances; spherical distances are not currently supported."
return (SpatiaLiteDistance(operator),)
View
1  django/contrib/gis/gdal/error.py
@@ -4,6 +4,7 @@
OGR methods.
"""
+
#### OGR & SRS Exceptions ####
class GDALException(Exception):
pass
View
8 django/contrib/gis/gdal/geometries.py
@@ -522,6 +522,7 @@ def union(self, other):
"""
return self._geomgen(capi.geom_union, other)
+
# The subclasses for OGR Geometry.
class Point(OGRGeometry):
@@ -550,6 +551,7 @@ def tuple(self):
return (self.x, self.y, self.z)
coords = tuple
+
class LineString(OGRGeometry):
def __getitem__(self, index):
@@ -605,10 +607,12 @@ def z(self):
if self.coord_dim == 3:
return self._listarr(capi.getz)
+
# LinearRings are used in Polygons.
class LinearRing(LineString):
pass
+
class Polygon(OGRGeometry):
def __len__(self):
@@ -654,6 +658,7 @@ def centroid(self):
capi.get_centroid(self.ptr, p.ptr)
return p
+
# Geometry Collection base class.
class GeometryCollection(OGRGeometry):
"The Geometry Collection class."
@@ -700,13 +705,16 @@ def tuple(self):
return tuple(self[i].tuple for i in xrange(self.geom_count))
coords = tuple
+
# Multiple Geometry types.
class MultiPoint(GeometryCollection):
pass
+
class MultiLineString(GeometryCollection):
pass
+
class MultiPolygon(GeometryCollection):
pass
View
2  django/contrib/gis/gdal/geomtype.py
@@ -2,7 +2,7 @@
from django.utils import six
-#### OGRGeomType ####
+
class OGRGeomType(object):
"Encapulates OGR Geometry Types."
View
8 django/contrib/gis/gdal/libgdal.py
@@ -55,6 +55,7 @@
from ctypes import WinDLL
lwingdal = WinDLL(lib_path)
+
def std_call(func):
"""
Returns the correct STDCALL function for certain OSR routines on Win32
@@ -72,15 +73,19 @@ def std_call(func):
_version_info.argtypes = [c_char_p]
_version_info.restype = c_char_p
+
def gdal_version():
"Returns only the GDAL version number information."
return _version_info(b'RELEASE_NAME')
+
def gdal_full_version():
"Returns the full GDAL version information."
return _version_info('')
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)
@@ -97,10 +102,13 @@ def gdal_version_info():
# Set library error handling so as errors are logged
CPLErrorHandler = CFUNCTYPE(None, c_int, c_int, c_char_p)
+
+
def err_handler(error_class, error_number, message):
logger.error('GDAL_ERROR %d: %s' % (error_number, message))
err_handler = CPLErrorHandler(err_handler)
+
def function(name, args, restype):
func = std_call(name)
func.argtypes = args
View
11 django/contrib/gis/gdal/prototypes/errcheck.py
@@ -15,10 +15,12 @@ def arg_byref(args, offset=-1):
"Returns the pointer argument's by-refernece value."
return args[offset]._obj.value
+
def ptr_byref(args, offset=-1):
"Returns the pointer argument passed in by-reference."
return args[offset]._obj
+
### String checking Routines ###
def check_const_string(result, func, cargs, offset=None):
"""
@@ -31,6 +33,7 @@ def check_const_string(result, func, cargs, offset=None):
else:
return result
+
def check_string(result, func, cargs, offset=-1, str_result=False):
"""
Checks the string output returned from the given function, and frees
@@ -61,12 +64,14 @@ def check_string(result, func, cargs, offset=-1, str_result=False):
### DataSource, Layer error-checking ###
+
### Envelope checking ###
def check_envelope(result, func, cargs, offset=-1):
"Checks a function that returns an OGR Envelope by reference."
env = ptr_byref(cargs, offset)
return env
+
### Geometry error-checking routines ###
def check_geom(result, func, cargs):
"Checks a function that returns a geometry."
@@ -78,12 +83,14 @@ def check_geom(result, func, cargs):
raise OGRException('Invalid geometry pointer returned from "%s".' % func.__name__)
return result
+
def check_geom_offset(result, func, cargs, offset=-1):
"Chcks the geometry at the given offset in the C parameter list."
check_err(result)
geom = ptr_byref(cargs, offset=offset)
return check_geom(geom, func, cargs)
+
### Spatial Reference error-checking routines ###
def check_srs(result, func, cargs):
if isinstance(result, six.integer_types):
@@ -92,6 +99,7 @@ def check_srs(result, func, cargs):
raise SRSException('Invalid spatial reference pointer returned from "%s".' % func.__name__)
return result
+
### Other error-checking routines ###
def check_arg_errcode(result, func, cargs):
"""
@@ -101,12 +109,14 @@ def check_arg_errcode(result, func, cargs):
check_err(arg_byref(cargs))
return result
+
def check_errcode(result, func, cargs):
"""
Check the error code returned (c_int).
"""
check_err(result)
+
def check_pointer(result, func, cargs):
"Makes sure the result pointer is valid."
if isinstance(result, six.integer_types):
@@ -116,6 +126,7 @@ def check_pointer(result, func, cargs):
else:
raise OGRException('Invalid pointer returned from "%s"' % func.__name__)
+
def check_str_arg(result, func, cargs):
"""
This is for the OSRGet[Angular|Linear]Units functions, which
View
9 django/contrib/gis/gdal/prototypes/generation.py
@@ -8,9 +8,11 @@
check_arg_errcode, check_errcode, check_geom, check_geom_offset,
check_pointer, check_srs, check_str_arg, check_string, check_const_string)
+
class gdal_char_p(c_char_p):
pass
+
def double_output(func, argtypes, errcheck=False, strarg=False):
"Generates a ctypes function that returns a double value."
func.argtypes = argtypes
@@ -21,6 +23,7 @@ def double_output(func, argtypes, errcheck=False, strarg=False):
func.errcheck = check_str_arg
return func
+
def geom_output(func, argtypes, offset=None):
"""
Generates a function that returns a Geometry either by reference
@@ -43,12 +46,14 @@ def geomerrcheck(result, func, cargs):
return func
+
def int_output(func, argtypes):
"Generates a ctypes function that returns an integer value."
func.argtypes = argtypes
func.restype = c_int
return func
+
def srs_output(func, argtypes):
"""
Generates a ctypes prototype for the given function with
@@ -60,6 +65,7 @@ def srs_output(func, argtypes):
func.errcheck = check_srs
return func
+
def const_string_output(func, argtypes, offset=None, decoding=None):
func.argtypes = argtypes
if offset:
@@ -76,6 +82,7 @@ def _check_const(result, func, cargs):
return func
+
def string_output(func, argtypes, offset=-1, str_result=False, decoding=None):
"""
Generates a ctypes prototype for the given function with the
@@ -104,6 +111,7 @@ def _check_str(result, func, cargs):
func.errcheck = _check_str
return func
+
def void_output(func, argtypes, errcheck=True):
"""
For functions that don't only return an error code that needs to
@@ -121,6 +129,7 @@ def void_output(func, argtypes, errcheck=True):
return func
+
def voidptr_output(func, argtypes):
"For functions that return c_void_p."
func.argtypes = argtypes
View
3  django/contrib/gis/gdal/prototypes/geom.py
@@ -5,6 +5,7 @@
from django.contrib.gis.gdal.prototypes.generation import (const_string_output,
double_output, geom_output, int_output, srs_output, string_output, void_output)
+
### Generation routines specific to this module ###
def env_func(f, argtypes):
"For getting OGREnvelopes."
@@ -13,10 +14,12 @@ def env_func(f, argtypes):
f.errcheck = check_envelope
return f
+
def pnt_func(f):
"For accessing point information."
return double_output(f, [c_void_p, c_int])
+
def topology_func(f):
f.argtypes = [c_void_p, c_void_p]
f.restype = c_int
View
2  django/contrib/gis/gdal/prototypes/srs.py
@@ -3,6 +3,7 @@
from django.contrib.gis.gdal.prototypes.generation import (const_string_output,
double_output, int_output, srs_output, string_output, void_output)
+
## Shortcut generation for routines with known parameters.
def srs_double(f):
"""
@@ -11,6 +12,7 @@ def srs_double(f):
"""
return double_output(f, [c_void_p, POINTER(c_int)], errcheck=True)
+
def units_func(f):
"""
Creates a ctypes function prototype for OSR units functions, e.g.,
View
7 django/contrib/gis/geoip/prototypes.py
@@ -1,6 +1,7 @@
from ctypes import c_char_p, c_float, c_int, string_at, Structure, POINTER
from django.contrib.gis.geoip.libgeoip import lgeoip, free
+
#### GeoIP C Structure definitions ####
class GeoIPRecord(Structure):
@@ -27,6 +28,7 @@ class GeoIPRecord(Structure):
1: 'utf8',
}
+
class GeoIPTag(Structure):
pass
@@ -48,6 +50,7 @@ class GeoIPTag(Structure):
GeoIPRecord_delete.argtypes = [RECTYPE]
GeoIPRecord_delete.restype = None
+
# For retrieving records by name or address.
def check_record(result, func, cargs):
if result:
@@ -68,6 +71,7 @@ def check_record(result, func, cargs):
else:
return None
+
def record_output(func):
func.argtypes = [DBTYPE, c_char_p]
func.restype = RECTYPE
@@ -84,10 +88,12 @@ def record_output(func):
GeoIP_delete.argtypes = [DBTYPE]
GeoIP_delete.restype = None
+
# This is so the string pointer can be freed within Python.
class geoip_char_p(c_char_p):
pass
+
def check_string(result, func, cargs):
if result:
s = string_at(result)
@@ -100,6 +106,7 @@ def check_string(result, func, cargs):
GeoIP_database_info.restype = geoip_char_p
GeoIP_database_info.errcheck = check_string
+
# String output routines.
def string_output(func):
def _err_check(result, func, cargs):
View
4 django/contrib/gis/geos/collections.py
@@ -12,6 +12,7 @@
from django.contrib.gis.geos import prototypes as capi
from django.utils.six.moves import xrange
+
class GeometryCollection(GEOSGeometry):
_typeid = 7
@@ -91,11 +92,13 @@ def tuple(self):
return tuple(g.tuple for g in self)
coords = tuple
+
# MultiPoint, MultiLineString, and MultiPolygon class definitions.
class MultiPoint(GeometryCollection):
_allowed = Point
_typeid = 4
+
class MultiLineString(GeometryCollection):
_allowed = (LineString, LinearRing)
_typeid = 5
@@ -108,6 +111,7 @@ def merged(self):
"""
return self._topology(capi.geos_linemerge(self.ptr))
+
class MultiPolygon(GeometryCollection):
_allowed = Polygon
_typeid = 6
View
1  django/contrib/gis/geos/coordseq.py
@@ -10,6 +10,7 @@
from django.contrib.gis.geos import prototypes as capi
from django.utils.six.moves import xrange
+
class GEOSCoordSeq(GEOSBase):
"The internal representation of a list of coordinates inside a Geometry."
View
2  django/contrib/gis/geos/error.py
@@ -3,10 +3,12 @@
GEOSGeometryIndexError.
"""
+
class GEOSException(Exception):
"The base GEOS exception, indicates a GEOS-related error."
pass
+
class GEOSIndexError(GEOSException, KeyError):
"""
This exception is raised when an invalid index is encountered, and has
View
11 django/contrib/gis/geos/libgeos.py
@@ -62,6 +62,8 @@
# Supposed to mimic the GEOS message handler (C below):
# typedef void (*GEOSMessageHandler)(const char *fmt, ...);
NOTICEFUNC = CFUNCTYPE(None, c_char_p, c_char_p)
+
+
def notice_h(fmt, lst):
fmt, lst = fmt.decode(), lst.decode()
try:
@@ -72,6 +74,8 @@ def notice_h(fmt, lst):
notice_h = NOTICEFUNC(notice_h)
ERRORFUNC = CFUNCTYPE(None, c_char_p, c_char_p)
+
+
def error_h(fmt, lst):
fmt, lst = fmt.decode(), lst.decode()
try:
@@ -83,16 +87,20 @@ def error_h(fmt, lst):
#### 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
@@ -102,6 +110,7 @@ class GEOSContextHandle_t(Structure):
CS_PTR = POINTER(GEOSCoordSeq_t)
CONTEXT_PTR = POINTER(GEOSContextHandle_t)
+
# Used specifically by the GEOSGeom_createPolygon and GEOSGeom_createCollection
# GEOS routines
def get_pointer_arr(n):
@@ -121,6 +130,8 @@ def get_pointer_arr(n):
r'^(?P<version>(?P<major>\d+)\.(?P<minor>\d+)\.(?P<subminor>\d+))'
r'((rc(?P<release_candidate>\d+))|dev)?-CAPI-(?P<capi_version>\d+\.\d+\.\d+)( r\d+)?$'
)
+
+
def geos_version_info():
"""
Returns a dictionary containing the various version metadata parsed from
View
2  django/contrib/gis/geos/linestring.py
@@ -6,6 +6,7 @@
from django.contrib.gis.geos import prototypes as capi
from django.utils.six.moves import xrange
+
class LineString(GEOSGeometry):
_init_func = capi.create_linestring
_minlength = 2
@@ -161,6 +162,7 @@ def z(self):
else:
return self._listarr(self._cs.getZ)
+
# LinearRings are LineStrings used within Polygons.
class LinearRing(LineString):
_minLength = 4
View
1  django/contrib/gis/geos/point.py
@@ -5,6 +5,7 @@
from django.utils import six
from django.utils.six.moves import xrange
+
class Point(GEOSGeometry):
_minlength = 2
_maxlength = 3
View
6 django/contrib/gis/geos/prototypes/coordseq.py
@@ -3,6 +3,7 @@
from django.contrib.gis.geos.prototypes.errcheck import last_arg_byref, GEOSException
from django.contrib.gis.geos.prototypes.threadsafe import GEOSFunc
+
## Error-checking routines specific to coordinate sequences. ##
def check_cs_ptr(result, func, cargs):
"Error checking on routines that return Geometries."
@@ -10,6 +11,7 @@ def check_cs_ptr(result, func, cargs):
raise GEOSException('Error encountered checking Coordinate Sequence returned from GEOS C function "%s".' % func.__name__)
return result
+
def check_cs_op(result, func, cargs):
"Checks the status code of a coordinate sequence operation."
if result == 0:
@@ -17,12 +19,14 @@ def check_cs_op(result, func, cargs):
else:
return result
+
def check_cs_get(result, func, cargs):
"Checking the coordinate sequence retrieval."
check_cs_op(result, func, cargs)
# Object in by reference, return its value.
return last_arg_byref(cargs)
+
## Coordinate sequence prototype generation functions. ##
def cs_int(func):
"For coordinate sequence routines that return an integer."
@@ -31,6 +35,7 @@ def cs_int(func):
func.errcheck = check_cs_get
return func
+
def cs_operation(func, ordinate=False, get=False):
"For coordinate sequence operations."
if get:
@@ -50,6 +55,7 @@ def cs_operation(func, ordinate=False, get=False):
func.restype = c_int
return func
+
def cs_output(func, argtypes):
"For routines that return a coordinate sequence."
func.argtypes = argtypes
View
8 django/contrib/gis/geos/prototypes/errcheck.py
@@ -25,11 +25,13 @@
libc = CDLL(None)
free = libc.free
+
### ctypes error checking routines ###
def last_arg_byref(args):
"Returns the last C argument's value by reference."
return args[-1]._obj.value
+
def check_dbl(result, func, cargs):
"Checks the status code and returns the double value passed in by reference."
# Checking the status code
@@ -38,12 +40,14 @@ def check_dbl(result, func, cargs):
# Double passed in by reference, return its value.
return last_arg_byref(cargs)
+
def check_geom(result, func, cargs):
"Error checking on routines that return Geometries."
if not result:
raise GEOSException('Error encountered checking Geometry returned from GEOS C function "%s".' % func.__name__)
return result
+
def check_minus_one(result, func, cargs):
"Error checking on routines that should not return -1."
if result == -1:
@@ -51,6 +55,7 @@ def check_minus_one(result, func, cargs):
else:
return result
+
def check_predicate(result, func, cargs):
"Error checking for unary/binary predicate functions."
val = ord(result) # getting the ordinal from the character
@@ -61,6 +66,7 @@ def check_predicate(result, func, cargs):
else:
raise GEOSException('Error encountered on GEOS C predicate function "%s".' % func.__name__)
+
def check_sized_string(result, func, cargs):
"""
Error checking for routines that return explicitly sized strings.
@@ -77,6 +83,7 @@ def check_sized_string(result, func, cargs):
free(result)
return s
+
def check_string(result, func, cargs):
"""
Error checking for routines that return strings.
@@ -91,6 +98,7 @@ def check_string(result, func, cargs):
free(result)
return s
+
def check_zero(result, func, cargs):
"Error checking on routines that should not return 0."
if result == 0:
View
7 django/contrib/gis/geos/prototypes/geom.py
@@ -7,6 +7,7 @@
# This is the return type used by binary output (WKB, HEX) routines.
c_uchar_p = POINTER(c_ubyte)
+
# We create a simple subclass of c_char_p here because when the response
# type is set to c_char_p, you get a _Python_ string and there's no way
# to access the string's address inside the error checking function.
@@ -17,6 +18,7 @@
class geos_char_p(c_char_p):
pass
+
### ctypes generation functions ###
def bin_constructor(func):
"Generates a prototype for binary construction (HEX, WKB) GEOS routines."
@@ -25,6 +27,7 @@ def bin_constructor(func):
func.errcheck = check_geom
return func
+
# HEX & WKB output
def bin_output(func):
"Generates a prototype for the routines that return a sized string."
@@ -33,6 +36,7 @@ def bin_output(func):
func.restype = c_uchar_p
return func
+
def geom_output(func, argtypes):
"For GEOS routines that return a geometry."
if argtypes:
@@ -41,10 +45,12 @@ def geom_output(func, argtypes):
func.errcheck = check_geom
return func
+
def geom_index(func):
"For GEOS routines that return geometries from an index."
return geom_output(func, [GEOM_PTR, c_int])
+
def int_from_geom(func, zero=False):
"Argument is a geometry, return type is an integer."
func.argtypes = [GEOM_PTR]
@@ -55,6 +61,7 @@ def int_from_geom(func, zero=False):
func.errcheck = check_minus_one
return func
+
def string_from_geom(func):
"Argument is a Geometry, return type is a string."
func.argtypes = [GEOM_PTR]
View
18 django/contrib/gis/geos/prototypes/io.py
@@ -10,16 +10,20 @@
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
@@ -71,6 +75,7 @@ class WKBWriter_st(Structure):
wkb_reader_destroy = GEOSFunc('GEOSWKBReader_destroy')
wkb_reader_destroy.argtypes = [WKB_READ_PTR]
+
def wkb_read_func(func):
# Although the function definitions take `const unsigned char *`
# as their parameter, we use c_char_p here so the function may
@@ -92,6 +97,7 @@ def wkb_read_func(func):
wkb_writer_destroy = GEOSFunc('GEOSWKBWriter_destroy')
wkb_writer_destroy.argtypes = [WKB_WRITE_PTR]
+
# WKB Writing prototypes.
def wkb_write_func(func):
func.argtypes = [WKB_WRITE_PTR, GEOM_PTR, POINTER(c_size_t)]
@@ -102,12 +108,14 @@ def wkb_write_func(func):
wkb_writer_write = wkb_write_func(GEOSFunc('GEOSWKBWriter_write'))
wkb_writer_write_hex = wkb_write_func(GEOSFunc('GEOSWKBWriter_writeHEX'))
+
# WKBWriter property getter/setter prototypes.
def wkb_writer_get(func, restype=c_int):
func.argtypes = [WKB_WRITE_PTR]
func.restype = restype
return func
+
def wkb_writer_set(func, argtype=c_int):
func.argtypes = [WKB_WRITE_PTR, argtype]
return func
@@ -119,6 +127,7 @@ def wkb_writer_set(func, argtype=c_int):
wkb_writer_get_include_srid = wkb_writer_get(GEOSFunc('GEOSWKBWriter_getIncludeSRID'), restype=c_char)
wkb_writer_set_include_srid = wkb_writer_set(GEOSFunc('GEOSWKBWriter_setIncludeSRID'), argtype=c_char)
+
### Base I/O Class ###
class IOBase(GEOSBase):
"Base class for GEOS I/O objects."
@@ -133,6 +142,7 @@ def __del__(self):
### Base WKB/WKT Reading and Writing objects ###
+
# Non-public WKB/WKT reader classes for internal use because
# their `read` methods return _pointers_ instead of GEOSGeometry
# objects.
@@ -146,6 +156,7 @@ def read(self, wkt):
raise TypeError
return wkt_reader_read(self.ptr, force_bytes(wkt))
+
class _WKBReader(IOBase):
_constructor = wkb_reader_create
_destructor = wkb_reader_destroy
@@ -161,6 +172,7 @@ def read(self, wkb):
else:
raise TypeError
+
### WKB/WKT Writer Classes ###
class WKTWriter(IOBase):
_constructor = wkt_writer_create
@@ -232,6 +244,7 @@ def _set_include_srid(self, include):
srid = property(_get_include_srid, _set_include_srid)
+
# `ThreadLocalIO` object holds instances of the WKT and WKB reader/writer
# objects that are local to the thread. The `GEOSGeometry` internals
# access these instances by calling the module-level functions, defined
@@ -245,6 +258,7 @@ class ThreadLocalIO(threading.local):
thread_context = ThreadLocalIO()
+
# These module-level routines return the I/O object that is local to the
# thread. If the I/O object does not exist yet it will be initialized.
def wkt_r():
@@ -252,23 +266,27 @@ def wkt_r():
thread_context.wkt_r = _WKTReader()
return thread_context.wkt_r
+
def wkt_w(dim=2):
if not thread_context.wkt_w:
thread_context.wkt_w = WKTWriter()
thread_context.wkt_w.outdim = dim
return thread_context.wkt_w
+
def wkb_r():
if not thread_context.wkb_r:
thread_context.wkb_r = _WKBReader()
return thread_context.wkb_r
+
def wkb_w(dim=2):
if not thread_context.wkb_w:
thread_context.wkb_w = WKBWriter()
thread_context.wkb_w.outdim = dim
return thread_context.wkb_w
+
def ewkb_w(dim=2):
if not thread_context.ewkb_w:
thread_context.ewkb_w = WKBWriter()
View
1  django/contrib/gis/geos/prototypes/misc.py
@@ -11,6 +11,7 @@
__all__ = ['geos_area', 'geos_distance', 'geos_length']
+
### ctypes generator function ###
def dbl_from_geom(func, num_geom=1):
"""
View
2  django/contrib/gis/geos/prototypes/predicates.py
@@ -7,6 +7,7 @@
from django.contrib.gis.geos.prototypes.errcheck import check_predicate
from django.contrib.gis.geos.prototypes.threadsafe import GEOSFunc
+
## Binary & unary predicate functions ##
def binary_predicate(func, *args):
"For GEOS binary predicate functions."
@@ -18,6 +19,7 @@ def binary_predicate(func, *args):
func.errcheck = check_predicate
return func
+
def unary_predicate(func):
"For GEOS unary predicate functions."
func.argtypes = [GEOM_PTR]
View
1  django/contrib/gis/geos/prototypes/prepared.py
@@ -12,6 +12,7 @@
prepared_destroy.argtpes = [PREPGEOM_PTR]
prepared_destroy.restype = None
+
# Prepared geometry binary predicate support.
def prepared_predicate(func):
func.argtypes = [PREPGEOM_PTR, GEOM_PTR]
View
3  django/contrib/gis/geos/prototypes/threadsafe.py
@@ -1,6 +1,7 @@
import threading
from django.contrib.gis.geos.libgeos import lgeos, notice_h, error_h, CONTEXT_PTR
+
class GEOSContextHandle(object):
"""
Python object representing a GEOS context handle.
@@ -14,6 +15,7 @@ def __del__(self):
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.
class GEOSContext(threading.local):
@@ -21,6 +23,7 @@ class GEOSContext(threading.local):
thread_context = GEOSContext()
+
class GEOSFunc(object):
"""
Class that serves as a wrapper for GEOS C Functions, and will
View
1  django/contrib/gis/geos/prototypes/topology.py
@@ -13,6 +13,7 @@
from django.contrib.gis.geos.prototypes.geom import geos_char_p
from django.contrib.gis.geos.prototypes.threadsafe import GEOSFunc
+
def topology(func, *args, **kwargs):
"For GEOS unary topology functions."
argtypes = [GEOM_PTR]
View
13 django/contrib/gis/geos/tests/test_geos_mutation.py
@@ -16,42 +16,55 @@
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
View
4 django/contrib/gis/geos/tests/test_mutable_list.py
@@ -39,18 +39,21 @@ def _set_list(self, length, items):
def _get_single_external(self, index):
return self._list[index]
+
class UserListB(UserListA):
_mytype = list
def _set_single(self, index, value):
self._list[index] = value
+
def nextRange(length):
nextRange.start += 100
return range(nextRange.start, nextRange.start + length)
nextRange.start = 0
+
class ListMixinTest(unittest.TestCase):
"""
Tests base class ListMixin by comparing a list clone which is
@@ -418,5 +421,6 @@ def test_12_arithmetic(self):
self.assertTrue(pl < ul, 'cmp for lt self')
self.assertTrue(pl < ul, 'cmp for lt self')
+
class ListMixinTestSingle(ListMixinTest):
listType = UserListB
View
1  django/contrib/gis/management/commands/inspectdb.py
@@ -1,5 +1,6 @@
from django.core.management.commands.inspectdb import Command as InspectDBCommand
+
class Command(InspectDBCommand):
db_module = 'django.contrib.gis.db'
gis_tables = {}
View
3  django/contrib/gis/management/commands/ogrinspect.py
@@ -2,6 +2,7 @@
from django.contrib.gis import gdal
from django.core.management.base import LabelCommand, CommandError
+
def layer_option(option, opt, value, parser):
"""
Callback for `make_option` for the `ogrinspect` `layer_key`
@@ -13,6 +14,7 @@ def layer_option(option, opt, value, parser):
dest = value
setattr(parser.values, option.dest, dest)
+
def list_option(option, opt, value, parser):
"""
Callback for `make_option` for `ogrinspect` keywords that require
@@ -25,6 +27,7 @@ def list_option(option, opt, value, parser):
dest = [s for s in value.split(',')]
setattr(parser.values, option.dest, dest)
+
class Command(LabelCommand):
help = ('Inspects the given OGR-compatible data source (e.g., a shapefile) and outputs\n'
'a GeoDjango model with the given model name. For example:\n'
View
2  django/contrib/gis/maps/google/gmap.py
@@ -6,6 +6,7 @@
from django.contrib.gis.maps.google.overlays import GPolygon, GPolyline, GMarker
+
class GoogleMapException(Exception):
pass
@@ -154,6 +155,7 @@ def icons(self):
"Returns a sequence of GIcon objects in this map."
return set(marker.icon for marker in self.markers if marker.icon)
+
class GoogleMapSet(GoogleMap):
def __init__(self, *args, **kwargs):
View
4 django/contrib/gis/maps/google/overlays.py
@@ -54,6 +54,7 @@ def __str__(self):
"Returns the parameter part of a GEvent."
return mark_safe('"%s", %s' % (self.event, self.action))
+
@python_2_unicode_compatible
class GOverlayBase(object):
def __init__(self):
@@ -71,6 +72,7 @@ def __str__(self):
"The string representation is the JavaScript API call."
return mark_safe('%s(%s)' % (self.__class__.__name__, self.js_params))
+
class GPolygon(GOverlayBase):
"""
A Python wrapper for the Google GPolygon object. For more information
@@ -130,6 +132,7 @@ def js_params(self):
return '%s, "%s", %s, %s, "%s", %s' % (self.points, self.stroke_color, self.stroke_weight, self.stroke_opacity,
self.fill_color, self.fill_opacity)
+
class GPolyline(GOverlayBase):
"""
A Python wrapper for the Google GPolyline object. For more information
@@ -253,6 +256,7 @@ def __hash__(self):
# equal hash(GIcon('varname')).
return hash(self.__class__) ^ hash(self.varname)
+
class GMarker(GOverlayBase):
"""
A Python wrapper for the Google GMarker object. For more information
View
1  django/contrib/gis/maps/google/zoom.py
@@ -7,6 +7,7 @@
DTOR = pi / 180.
RTOD = 180. / pi
+
class GoogleZoom(object):
"""
GoogleZoom is a utility for performing operations related to the zoom
View
3  django/contrib/gis/sitemaps/views.py
@@ -37,6 +37,7 @@ def index(request, sitemaps):
xml = loader.render_to_string('sitemap_index.xml', {'sitemaps': sites})
return HttpResponse(xml, content_type='application/xml')
+
def sitemap(request, sitemaps, section=None):
"""
This view generates a sitemap with additional geographic
@@ -65,6 +66,7 @@ def sitemap(request, sitemaps, section=None):
xml = loader.render_to_string('gis/sitemaps/geo_sitemap.xml', {'urlset': urls})
return HttpResponse(xml, content_type='application/xml')
+
def kml(request, label, model, field_name=None, compress=False, using=DEFAULT_DB_ALIAS):
"""
This view generates KML for the given app label, model, and field name.
@@ -109,6 +111,7 @@ def kml(request, label, model, field_name=None, compress=False, using=DEFAULT_DB
render = render_to_kml
return render('gis/kml/placemarks.kml', {'places': placemarks})
+
def kmz(request, label, model, field_name=None, using=DEFAULT_DB_ALIAS):
"""
This view returns KMZ for the given app label, model, and field name.
View
7 django/contrib/gis/tests/distapp/models.py
@@ -1,6 +1,7 @@
from django.contrib.gis.db import models
from django.utils.encoding import python_2_unicode_compatible
+
@python_2_unicode_compatible
class SouthTexasCity(models.Model):
"City model on projected coordinate system for South Texas."
@@ -11,6 +12,7 @@ class SouthTexasCity(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class SouthTexasCityFt(models.Model):
"Same City model as above, but U.S. survey feet are the units."
@@ -21,6 +23,7 @@ class SouthTexasCityFt(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class AustraliaCity(models.Model):
"City model for Australia, using WGS84."
@@ -31,6 +34,7 @@ class AustraliaCity(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class CensusZipcode(models.Model):
"Model for a few South Texas ZIP codes (in original Census NAD83)."
@@ -41,6 +45,7 @@ class CensusZipcode(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class SouthTexasZipcode(models.Model):
"Model for a few South Texas ZIP codes."
@@ -51,6 +56,7 @@ class SouthTexasZipcode(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Interstate(models.Model):
"Geodetic model for U.S. Interstates."
@@ -61,6 +67,7 @@ class Interstate(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class SouthTexasInterstate(models.Model):
"Projected model for South Texas Interstates."
View
10 django/contrib/gis/tests/geo3d/models.py
@@ -1,6 +1,7 @@
from django.contrib.gis.db import models
from django.utils.encoding import python_2_unicode_compatible
+
@python_2_unicode_compatible
class City3D(models.Model):
name = models.CharField(max_length=30)
@@ -10,6 +11,7 @@ class City3D(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Interstate2D(models.Model):
name = models.CharField(max_length=30)
@@ -19,6 +21,7 @@ class Interstate2D(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Interstate3D(models.Model):
name = models.CharField(max_length=30)
@@ -28,6 +31,7 @@ class Interstate3D(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class InterstateProj2D(models.Model):
name = models.CharField(max_length=30)
@@ -37,6 +41,7 @@ class InterstateProj2D(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class InterstateProj3D(models.Model):
name = models.CharField(max_length=30)
@@ -46,6 +51,7 @@ class InterstateProj3D(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Polygon2D(models.Model):
name = models.CharField(max_length=30)
@@ -55,6 +61,7 @@ class Polygon2D(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Polygon3D(models.Model):
name = models.CharField(max_length=30)
@@ -64,14 +71,17 @@ class Polygon3D(models.Model):
def __str__(self):
return self.name
+
class Point2D(models.Model):
point = models.PointField()
objects = models.GeoManager()
+
class Point3D(models.Model):
point = models.PointField(dim=3)
objects = models.GeoManager()
+
class MultiPoint3D(models.Model):
mpoint = models.MultiPointField(dim=3)
objects = models.GeoManager()
View
1  django/contrib/gis/tests/geoadmin/models.py
@@ -2,6 +2,7 @@
from django.contrib.gis import admin
from django.utils.encoding import python_2_unicode_compatible
+
@python_2_unicode_compatible
class City(models.Model):
name = models.CharField(max_length=30)
View
6 django/contrib/gis/tests/geoapp/feeds.py
@@ -18,6 +18,7 @@ def item_link(self, item):
def item_geometry(self, item):
return item.point
+
class TestGeoRSS2(TestGeoRSS1):
def geometry(self, obj):
# This should attach a <georss:box> element for the extent of
@@ -30,9 +31,11 @@ def item_geometry(self, item):
# Returning a simple tuple for the geometry.
return item.point.x, item.point.y
+
class TestGeoAtom1(TestGeoRSS1):
feed_type = feeds.GeoAtom1Feed
+
class TestGeoAtom2(TestGeoRSS2):
feed_type = feeds.GeoAtom1Feed
@@ -40,13 +43,16 @@ def geometry(self, obj):
# This time we'll use a 2-tuple of coordinates for the box.
return ((-123.30, -41.32), (174.78, 48.46))
+
class TestW3CGeo1(TestGeoRSS1):
feed_type = feeds.W3CGeoFeed
+
# The following feeds are invalid, and will raise exceptions.
class TestW3CGeo2(TestGeoRSS2):
feed_type = feeds.W3CGeoFeed
+
class TestW3CGeo3(TestGeoRSS1):
feed_type = feeds.W3CGeoFeed
View
6 django/contrib/gis/tests/geoapp/models.py
@@ -5,6 +5,7 @@
# MySQL spatial indices can't handle NULL geometries.
null_flag = not mysql
+
@python_2_unicode_compatible
class Country(models.Model):
name = models.CharField(max_length=30)
@@ -14,6 +15,7 @@ class Country(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class City(models.Model):
name = models.CharField(max_length=30)
@@ -23,12 +25,14 @@ class City(models.Model):
def __str__(self):
return self.name
+
# This is an inherited model from City
class PennsylvaniaCity(City):
county = models.CharField(max_length=30)
founded = models.DateTimeField(null=True)
objects = models.GeoManager() # TODO: This should be implicitly inherited.
+
@python_2_unicode_compatible
class State(models.Model):
name = models.CharField(max_length=30)
@@ -38,6 +42,7 @@ class State(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Track(models.Model):
name = models.CharField(max_length=30)
@@ -47,6 +52,7 @@ class Track(models.Model):
def __str__(self):
return self.name
+
class Truth(models.Model):
val = models.BooleanField(default=False)
objects = models.GeoManager()
View
3  django/contrib/gis/tests/geogapp/models.py
@@ -1,6 +1,7 @@
from django.contrib.gis.db import models
from django.utils.encoding import python_2_unicode_compatible
+
@python_2_unicode_compatible
class City(models.Model):
name = models.CharField(max_length=30)
@@ -10,6 +11,7 @@ class City(models.Model):
def __str__(self):
return self.name
+
@python_2_unicode_compatible
class Zipcode(models.Model):
code = models.CharField(max_length=10)
@@ -19,6 +21,7 @@ class Zipcode(models.Model):
def __str__(self):
return self.code
+
@python_2_unicode_compatible
class County(models.Model):
name = models.CharField(max_length=25)
View
1  django/contrib/gis/tests/inspectapp/models.py
@@ -1,5 +1,6 @@
from django.contrib.gis.db import models
+
class AllOGRFields(models.Model):
f_decimal = models.FloatField()
f_float = models.FloatField()
View
9 django/contrib/gis/tests/layermap/models.py
@@ -1,20 +1,24 @@
from django.contrib.gis.db import models
+
class State(models.Model):
name = models.CharField(max_length=20)
objects = models.GeoManager()
+
class County(models.Model):
name = models.CharField(max_length=25)
state = models.ForeignKey(State)
mpoly = models.MultiPolygonField(srid=4269) # Multipolygon in NAD83
objects = models.GeoManager()
+
class CountyFeat(models.Model):
name = models.CharField(max_length=25)
poly = models.PolygonField(srid=4269)
objects = models.GeoManager()
+
class City(models.Model):
name = models.CharField(max_length=25)
name_txt = models.TextField(default='')
@@ -24,12 +28,14 @@ class City(models.Model):
point = models.PointField()
objects = models.GeoManager()
+
class Interstate(models.Model):
name = models.CharField(max_length=20)
length = models.DecimalField(max_digits=6, decimal_places=2)
path = models.LineStringField()
objects = models.GeoManager()
+
# Same as `City` above, but for testing model inheritance.
class CityBase(models.Model):
name = models.CharField(max_length=25)
@@ -38,12 +44,15 @@ class CityBase(models.Model):
point = models.PointField()
objects = models.GeoManager()
+
class ICity1(CityBase):
dt = models.DateField()
+
class ICity2(ICity1):
dt_time = models.DateTimeField(auto_now=True)
+
class Invalid(models.Model):
point = models.PointField()
View
1  django/contrib/gis/tests/layermap/tests.py
@@ -304,6 +304,7 @@ def test_encoded_name(self):
self.assertEqual(City.objects.count(), 1)
self.assertEqual(City.objects.all()[0].name, "Zürich")
+
class OtherRouter(object):
def db_for_read(self, model, **hints):
return 'other'
View
8 django/contrib/gis/tests/relatedapp/models.py
@@ -1,6 +1,7 @@
from django.contrib.gis.db import models
from django.utils.encoding import python_2_unicode_compatible
+
@python_2_unicode_compatible
class Location(models.Model):
point = models.PointField()
@@ -9,6 +10,7 @@ class Location(models.Model):
def __str__(self):
return self.point.wkt
+
@python_2_unicode_compatible
class City(models.Model):
name = models.CharField(max_length=50)
@@ -19,15 +21,18 @@ class City(models.Model):
def __str__(self):
return self.name
+
class AugmentedLocation(Location):
extra_text = models.TextField(blank=True)
objects = models.GeoManager()
+
class DirectoryEntry(models.Model):
listing_text = models.CharField(max_length=50)
location = models.ForeignKey(AugmentedLocation)
objects = models.GeoManager()
+
@python_2_unicode_compatible
class Parcel(models.Model):
name = models.CharField(max_length=30)
@@ -42,17 +47,20 @@ class Parcel(models.Model):
def __str__(self):
return self.name
+
# These use the GeoManager but do not have any geographic fields.
class Author(models.Model):
name = models.CharField(max_length=100)
dob = models.DateField()
objects = models.GeoManager()
+
class Article(models.Model):
title = models.CharField(max_length=100)
author = models.ForeignKey(Author, unique=True)
objects = models.GeoManager()
+
class Book(models.Model):
title = models.CharField(max_length=100)
author = models.ForeignKey(Author, related_name='books', null=True)
View
2  django/contrib/gis/tests/test_measure.py
@@ -264,12 +264,14 @@ def testUnitsStr(self):
self.assertEqual(repr(a1), 'Area(sq_m=100.0)')
self.assertEqual(repr(a2), 'Area(sq_km=3.5)')
+
def suite():
s = unittest.TestSuite()
s.addTest(unittest.makeSuite(DistanceTest))
s.addTest(unittest.makeSuite(AreaTest))
return s
+
def run(verbosity=2):
unittest.TextTestRunner(verbosity=verbosity).run(suite())
View
3  django/contrib/gis/tests/test_spatialrefsys.py
@@ -32,6 +32,7 @@
},
)
+
@unittest.skipUnless(HAS_GDAL and HAS_SPATIALREFSYS,
"SpatialRefSysTest needs gdal support and a spatial database")
class SpatialRefSysTest(unittest.TestCase):
@@ -94,10 +95,12 @@ def test03_ellipsoid(self):
for i in range(3):
self.assertAlmostEqual(ellps1[i], ellps2[i], prec[i])
+
def suite():
s = unittest.TestSuite()
s.addTest(unittest.makeSuite(SpatialRefSysTest))
return s
+
def run(verbosity=2):
unittest.TextTestRunner(verbosity=verbosity).run(suite())
View
5 django/contrib/gis/utils/layermapping.py
@@ -24,18 +24,23 @@
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."
View
1  django/contrib/gis/utils/ogrinfo.py
@@ -7,6 +7,7 @@
from django.contrib.gis.gdal import DataSource
from django.contrib.gis.gdal.geometries import GEO_CLASSES
+
def ogrinfo(data_source, num_features=10):
"""
Walks the available layers in the supplied `data_source`, displaying
View
3  django/contrib/gis/utils/ogrinspect.py
@@ -9,6 +9,7 @@
from django.contrib.gis.gdal.field import OFTDate, OFTDateTime, OFTInteger, OFTReal, OFTString, OFTTime
from django.utils import six
+
def mapping(data_source, geom_name='geom', layer_key=0, multi_geom=False):
"""
Given a DataSource, generates a dictionary that may be used
@@ -48,6 +49,7 @@ def mapping(data_source, geom_name='geom', layer_key=0, multi_geom=False):
_mapping[geom_name] = prefix + str(gtype).upper()
return _mapping
+
def ogrinspect(*args, **kwargs):
"""
Given a data source (either a string or a DataSource object) and a string
@@ -118,6 +120,7 @@ def ogrinspect(*args, **kwargs):
"""
return '\n'.join(s for s in _ogrinspect(*args, **kwargs))
+
def _ogrinspect(data_source, model_name, geom_name='geom', layer_key=0, srid=None,
multi_geom=False, name_field=None, imports=True,
decimal=False, blank=False, null=False):
View
1  django/contrib/gis/utils/srs.py
@@ -1,5 +1,6 @@
from django.contrib.gis.gdal import SpatialReference
+
def add_srs_entry(srs, auth_name='EPSG', auth_srid=None, ref_sys_name=None,
database=None):
"""
View
1  django/contrib/gis/utils/wkt.py
@@ -4,6 +4,7 @@
from django.utils import six
+
def precision_wkt(geom, prec):
"""
Returns WKT text of the geometry according to the given precision (an
View
1  django/contrib/messages/storage/cookie.py
@@ -46,6 +46,7 @@ def decode(self, s, **kwargs):
decoded = super(MessageDecoder, self).decode(s, **kwargs)
return self.process_messages(decoded)
+
class CookieStorage(BaseStorage):
"""
Stores messages in a cookie.
View
1  django/contrib/messages/storage/fallback.py
@@ -2,6 +2,7 @@
from django.contrib.messages.storage.cookie import CookieStorage
from django.contrib.messages.storage.session import SessionStorage
+
class FallbackStorage(BaseStorage):
"""
Tries to store all messages in the first backend, storing any unstored
View
1  django/contrib/messages/tests/test_mixins.py
@@ -2,6 +2,7 @@
from django.contrib.messages.tests.urls import ContactFormViewWithMsg
from django.core.urlresolvers import reverse
+
class SuccessMessageMixinTests(TestCase):
urls = 'django.contrib.messages.tests.urls'
View
4 django/contrib/messages/tests/urls.py
@@ -20,6 +20,7 @@
{% endif %}
"""
+
@never_cache
def add(request, message_type):
# don't default to False here, because we want to test that it defaults
@@ -35,6 +36,7 @@ def add(request, message_type):
show_url = reverse('django.contrib.messages.tests.urls.show')
return HttpResponseRedirect(show_url)
+
@never_cache
def add_template_response(request, message_type):
for msg in request.POST.getlist('messages'):
@@ -43,11 +45,13 @@ def add_template_response(request, message_type):
show_url = reverse('django.contrib.messages.tests.urls.show_template_response')
return HttpResponseRedirect(show_url)
+
@never_cache
def show(request):
t = Template(TEMPLATE)
return HttpResponse(t.render(RequestContext(request)))
+
@never_cache
def show_template_response(request):
return TemplateResponse(request, Template(TEMPLATE))
View
1  django/contrib/redirects/models.py
@@ -3,6 +3,7 @@
from django.utils.translation import ugettext_lazy as _
from django.utils.encoding import python_2_unicode_compatible
+
@python_2_unicode_compatible
class Redirect(models.Model):
site = models.ForeignKey(Site)
View
2  django/contrib/sessions/backends/base.py
@@ -20,6 +20,7 @@
# on case insensitive file systems.
VALID_KEY_CHARS = string.ascii_lowercase + string.digits
+
class CreateError(Exception):
"""
Used internally as a consistent exception type to catch from save (see the
@@ -27,6 +28,7 @@ class CreateError(Exception):
"""
pass
+
class SessionBase(object):
"""
Base class for all Session classes.
View
1  django/contrib/sessions/backends/db.py
@@ -6,6 +6,7 @@
from django.utils import timezone
from django.utils.encoding import force_text
+
class SessionStore(SessionBase):
"""
Implements database session store.
View
1  django/contrib/sessions/backends/file.py
@@ -13,6 +13,7 @@
from django.contrib.sessions.exceptions import InvalidSessionKey
+
class SessionStore(SessionBase):
"""
Implements a file based session store.
View
1  django/contrib/sessions/middleware.py
@@ -5,6 +5,7 @@
from django.utils.cache import patch_vary_headers
from django.utils.http import cookie_date
+
class SessionMiddleware(object):
def __init__(self):
engine = import_module(settings.SESSION_ENGINE)
View
1  django/contrib/sitemaps/tests/test_flatpages.py
@@ -6,6 +6,7 @@
from .base import SitemapTestsBase
+
class FlatpagesSitemapTests(SitemapTestsBase):
@skipUnless("django.contrib.flatpages" in settings.INSTALLED_APPS,
View
1  django/contrib/sitemaps/tests/test_https.py
@@ -6,6 +6,7 @@
from .base import SitemapTestsBase
+
class HTTPSSitemapTests(SitemapTestsBase):
protocol = 'https'
urls = 'django.contrib.sitemaps.tests.urls.https'
View
1  django/contrib/sitemaps/tests/urls/https.py
@@ -2,6 +2,7 @@
from .http import SimpleSitemap
+
class HTTPSSitemap(SimpleSitemap):
protocol = 'https'
View
3  django/contrib/sitemaps/views.py