Django

Code

Changeset 5795

Show
Ignore:
Timestamp:
08/03/07 19:27:59 (1 year ago)
Author:
jbronn
Message:

gis: wktfield now takes advantage of lazy geometries; geos may take unicode input; fixed utils module

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/gis/django/contrib/gis/geos/base.py

    r5786 r5795  
    88     byref, string_at, create_string_buffer, pointer, \ 
    99     c_char_p, c_double, c_int, c_size_t 
    10 from types import StringType, IntType, FloatType 
     10from types import StringType, UnicodeType, IntType, FloatType 
    1111 
    1212# Python and GEOS-related dependencies. 
     
    1818if HAS_NUMPY: from numpy import ndarray, array 
    1919 
    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. 
     23hex_regex = re.compile(r'^[0-9A-F]+$', re.I) 
     24wkt_regex = re.compile(r'^(POINT|LINESTRING|LINEARRING|POLYGON|MULTIPOINT|MULTILINESTRING|MULTIPOLYGON|GEOMETRYCOLLECTION)[ACEGIMLONPSRUTY\d,\.\-\(\) ]+$', re.I) 
    2225 
    2326class GEOSGeometry(object): 
     
    3942        self._ptr = GEOSPointer(0) 
    4043 
     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 
    4148        if isinstance(geo_input, StringType): 
    4249            if input_type: warn('input_type keyword is deprecated') 
     
    4754                buf = create_string_buffer(geo_input) 
    4855                g = lgeos.GEOSGeomFromHEX_buf(buf, sz) 
    49             else
     56            elif wkt_regex.match(geo_input)
    5057                # Otherwise, the geometry is in WKT form. 
    5158                g = lgeos.GEOSGeomFromWKT(c_char_p(geo_input)) 
     59            else: 
     60                raise GEOSException, 'given string input "%s" unrecognized as WKT or HEXEWKB.' % geo_input 
    5261 
    5362        elif isinstance(geo_input, (IntType, GEOSPointer)): 
  • django/branches/gis/django/contrib/gis/oldforms/__init__.py

    r5336 r5795  
    11from django.oldforms import LargeTextField 
    2 from django.contrib.gis.geos import hex_to_wkt 
    32 
    43class WKTField(LargeTextField): 
     
    65     
    76    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. 
    119        if not data: 
    1210            return super(WKTField, self).render(None) 
    1311        else: 
    14             return super(WKTField, self).render(hex_to_wkt(data)
     12            return super(WKTField, self).render(data.wkt
    1513     
    1614                                         
  • django/branches/gis/django/contrib/gis/tests/__init__.py

    r5786 r5795  
    11from copy import copy 
    22from unittest import TestSuite, TextTestRunner 
    3 from django.contrib.gis.db.backend import create_spatial_db 
    4 from django.db import connection 
    5 from django.test.utils import destroy_test_db 
    63 
    74# Tests that do not require setting up and tearing down a spatial database. 
     
    5552    """ 
    5653    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 
    5757 
    5858    # Getting initial values. 
  • django/branches/gis/django/contrib/gis/utils/__init__.py

    r5761 r5795  
    11from LayerMapping import LayerMapping 
    22from inspect_data import sample 
    3 from spatial_db import create_spatial_db 
     3