summaryrefslogtreecommitdiff
path: root/lib/python2.7/site-packages/django/contrib/gis/geometry
diff options
context:
space:
mode:
Diffstat (limited to 'lib/python2.7/site-packages/django/contrib/gis/geometry')
-rw-r--r--lib/python2.7/site-packages/django/contrib/gis/geometry/__init__.py0
-rw-r--r--lib/python2.7/site-packages/django/contrib/gis/geometry/backend/__init__.py21
-rw-r--r--lib/python2.7/site-packages/django/contrib/gis/geometry/backend/geos.py2
-rw-r--r--lib/python2.7/site-packages/django/contrib/gis/geometry/regex.py12
-rw-r--r--lib/python2.7/site-packages/django/contrib/gis/geometry/test_data.py106
5 files changed, 141 insertions, 0 deletions
diff --git a/lib/python2.7/site-packages/django/contrib/gis/geometry/__init__.py b/lib/python2.7/site-packages/django/contrib/gis/geometry/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/lib/python2.7/site-packages/django/contrib/gis/geometry/__init__.py
diff --git a/lib/python2.7/site-packages/django/contrib/gis/geometry/backend/__init__.py b/lib/python2.7/site-packages/django/contrib/gis/geometry/backend/__init__.py
new file mode 100644
index 0000000..52fa0de
--- /dev/null
+++ b/lib/python2.7/site-packages/django/contrib/gis/geometry/backend/__init__.py
@@ -0,0 +1,21 @@
+from django.conf import settings
+from django.core.exceptions import ImproperlyConfigured
+from django.utils.importlib import import_module
+
+geom_backend = getattr(settings, 'GEOMETRY_BACKEND', 'geos')
+
+try:
+ module = import_module('django.contrib.gis.geometry.backend.%s' % geom_backend)
+except ImportError:
+ try:
+ module = import_module(geom_backend)
+ except ImportError:
+ raise ImproperlyConfigured('Could not import user-defined GEOMETRY_BACKEND '
+ '"%s".' % geom_backend)
+
+try:
+ Geometry = module.Geometry
+ GeometryException = module.GeometryException
+except AttributeError:
+ raise ImproperlyConfigured('Cannot import Geometry from the "%s" '
+ 'geometry backend.' % geom_backend)
diff --git a/lib/python2.7/site-packages/django/contrib/gis/geometry/backend/geos.py b/lib/python2.7/site-packages/django/contrib/gis/geometry/backend/geos.py
new file mode 100644
index 0000000..cdc40ed
--- /dev/null
+++ b/lib/python2.7/site-packages/django/contrib/gis/geometry/backend/geos.py
@@ -0,0 +1,2 @@
+from django.contrib.gis.geos import (
+ GEOSGeometry as Geometry, GEOSException as GeometryException)
diff --git a/lib/python2.7/site-packages/django/contrib/gis/geometry/regex.py b/lib/python2.7/site-packages/django/contrib/gis/geometry/regex.py
new file mode 100644
index 0000000..22d16cb
--- /dev/null
+++ b/lib/python2.7/site-packages/django/contrib/gis/geometry/regex.py
@@ -0,0 +1,12 @@
+import re
+
+# Regular expression for recognizing HEXEWKB and WKT. A prophylactic measure
+# to prevent potentially malicious input from reaching the underlying C
+# library. Not a substitute for good Web security programming practices.
+hex_regex = re.compile(r'^[0-9A-F]+$', re.I)
+wkt_regex = re.compile(r'^(SRID=(?P<srid>\-?\d+);)?'
+ r'(?P<wkt>'
+ r'(?P<type>POINT|LINESTRING|LINEARRING|POLYGON|MULTIPOINT|MULTILINESTRING|MULTIPOLYGON|GEOMETRYCOLLECTION)'
+ r'[ACEGIMLONPSRUTYZ\d,\.\-\(\) ]+)$',
+ re.I)
+json_regex = re.compile(r'^(\s+)?\{[\s\w,\[\]\{\}\-\."\':]+\}(\s+)?$')
diff --git a/lib/python2.7/site-packages/django/contrib/gis/geometry/test_data.py b/lib/python2.7/site-packages/django/contrib/gis/geometry/test_data.py
new file mode 100644
index 0000000..e13e858
--- /dev/null
+++ b/lib/python2.7/site-packages/django/contrib/gis/geometry/test_data.py
@@ -0,0 +1,106 @@
+"""
+This module has the mock object definitions used to hold reference geometry
+for the GEOS and GDAL tests.
+"""
+import json
+import os
+
+from django.contrib import gis
+from django.utils import six
+from django.utils._os import upath
+
+
+# This global used to store reference geometry data.
+GEOMETRIES = None
+
+# Path where reference test data is located.
+TEST_DATA = os.path.join(os.path.dirname(upath(gis.__file__)), 'tests', 'data')
+
+
+def tuplize(seq):
+ "Turn all nested sequences to tuples in given sequence."
+ if isinstance(seq, (list, tuple)):
+ return tuple([tuplize(i) for i in seq])
+ return seq
+
+
+def strconvert(d):
+ "Converts all keys in dictionary to str type."
+ return dict([(str(k), v) for k, v in six.iteritems(d)])
+
+
+def get_ds_file(name, ext):
+ return os.path.join(TEST_DATA,
+ name,
+ name + '.%s' % ext
+ )
+
+
+class TestObj(object):
+ """
+ Base testing object, turns keyword args into attributes.
+ """
+ def __init__(self, **kwargs):
+ for key, value in kwargs.items():
+ setattr(self, key, value)
+
+
+class TestDS(TestObj):
+ """
+ Object for testing GDAL data sources.
+ """
+ def __init__(self, name, **kwargs):
+ # Shapefile is default extension, unless specified otherwise.
+ ext = kwargs.pop('ext', 'shp')
+ self.ds = get_ds_file(name, ext)
+ super(TestDS, self).__init__(**kwargs)
+
+
+class TestGeom(TestObj):
+ """
+ Testing object used for wrapping reference geometry data
+ in GEOS/GDAL tests.
+ """
+ def __init__(self, **kwargs):
+ # Converting lists to tuples of certain keyword args
+ # so coordinate test cases will match (JSON has no
+ # concept of tuple).
+ coords = kwargs.pop('coords', None)
+ if coords:
+ self.coords = tuplize(coords)
+
+ centroid = kwargs.pop('centroid', None)
+ if centroid:
+ self.centroid = tuple(centroid)
+
+ ext_ring_cs = kwargs.pop('ext_ring_cs', None)
+ if ext_ring_cs:
+ ext_ring_cs = tuplize(ext_ring_cs)
+ self.ext_ring_cs = ext_ring_cs
+
+ super(TestGeom, self).__init__(**kwargs)
+
+
+class TestGeomSet(object):
+ """
+ Each attribute of this object is a list of `TestGeom` instances.
+ """
+ def __init__(self, **kwargs):
+ for key, value in kwargs.items():
+ setattr(self, key, [TestGeom(**strconvert(kw)) for kw in value])
+
+
+class TestDataMixin(object):
+ """
+ Mixin used for GEOS/GDAL test cases that defines a `geometries`
+ property, which returns and/or loads the reference geometry data.
+ """
+ @property
+ def geometries(self):
+ global GEOMETRIES
+ if GEOMETRIES is None:
+ # Load up the test geometry data from fixture into global.
+ with open(os.path.join(TEST_DATA, 'geometries.json')) as f:
+ geometries = json.load(f)
+ GEOMETRIES = TestGeomSet(**strconvert(geometries))
+ return GEOMETRIES