Changeset 5795
- Timestamp:
- 08/03/07 19:27:59 (1 year ago)
- Files:
-
- django/branches/gis/django/contrib/gis/geos/base.py (modified) (4 diffs)
- django/branches/gis/django/contrib/gis/oldforms/__init__.py (modified) (2 diffs)
- django/branches/gis/django/contrib/gis/tests/__init__.py (modified) (2 diffs)
- django/branches/gis/django/contrib/gis/utils/__init__.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/gis/django/contrib/gis/geos/base.py
r5786 r5795 8 8 byref, string_at, create_string_buffer, pointer, \ 9 9 c_char_p, c_double, c_int, c_size_t 10 from types import StringType, IntType, FloatType10 from types import StringType, UnicodeType, IntType, FloatType 11 11 12 12 # Python and GEOS-related dependencies. … … 18 18 if HAS_NUMPY: from numpy import ndarray, array 19 19 20 # Regular expression for recognizing HEXEWKB. 21 hex_regex = re.compile(r'^[0-9A-Fa-f]+$') 20 # Regular expression for recognizing HEXEWKB and WKT. A prophylactic measure 21 # to prevent potentially malicious input from reaching the underlying C 22 # library. Not a substitute for good web security programming practices. 23 hex_regex = re.compile(r'^[0-9A-F]+$', re.I) 24 wkt_regex = re.compile(r'^(POINT|LINESTRING|LINEARRING|POLYGON|MULTIPOINT|MULTILINESTRING|MULTIPOLYGON|GEOMETRYCOLLECTION)[ACEGIMLONPSRUTY\d,\.\-\(\) ]+$', re.I) 22 25 23 26 class GEOSGeometry(object): … … 39 42 self._ptr = GEOSPointer(0) 40 43 44 if isinstance(geo_input, UnicodeType): 45 # Encoding to ASCII, WKT or HEXEWKB doesn't need any more. 46 geo_input = geo_input.encode('ascii') 47 41 48 if isinstance(geo_input, StringType): 42 49 if input_type: warn('input_type keyword is deprecated') … … 47 54 buf = create_string_buffer(geo_input) 48 55 g = lgeos.GEOSGeomFromHEX_buf(buf, sz) 49 el se:56 elif wkt_regex.match(geo_input): 50 57 # Otherwise, the geometry is in WKT form. 51 58 g = lgeos.GEOSGeomFromWKT(c_char_p(geo_input)) 59 else: 60 raise GEOSException, 'given string input "%s" unrecognized as WKT or HEXEWKB.' % geo_input 52 61 53 62 elif isinstance(geo_input, (IntType, GEOSPointer)): django/branches/gis/django/contrib/gis/oldforms/__init__.py
r5336 r5795 1 1 from django.oldforms import LargeTextField 2 from django.contrib.gis.geos import hex_to_wkt3 2 4 3 class WKTField(LargeTextField): … … 6 5 7 6 def render(self, data): 8 # PostGIS uses EWKBHEX to store its values internally, converting 9 # to WKT for the admin first -- unless there's no data, then just 10 # pass None to LargeTextField's render. 7 # Returns the WKT value for the geometry field. When no such data 8 # is present, return None to LargeTextField's render. 11 9 if not data: 12 10 return super(WKTField, self).render(None) 13 11 else: 14 return super(WKTField, self).render( hex_to_wkt(data))12 return super(WKTField, self).render(data.wkt) 15 13 16 14 django/branches/gis/django/contrib/gis/tests/__init__.py
r5786 r5795 1 1 from copy import copy 2 2 from unittest import TestSuite, TextTestRunner 3 from django.contrib.gis.db.backend import create_spatial_db4 from django.db import connection5 from django.test.utils import destroy_test_db6 3 7 4 # Tests that do not require setting up and tearing down a spatial database. … … 55 52 """ 56 53 from django.conf import settings 54 from django.contrib.gis.db.backend import create_spatial_db 55 from django.db import connection 56 from django.test.utils import destroy_test_db 57 57 58 58 # Getting initial values. django/branches/gis/django/contrib/gis/utils/__init__.py
r5761 r5795 1 1 from LayerMapping import LayerMapping 2 2 from inspect_data import sample 3 from spatial_db import create_spatial_db 3
