Ticket #9566: geojson_regex.diff
File geojson_regex.diff, 5.0 KB (added by , 16 years ago) |
---|
-
django/contrib/gis/geos/base.py
21 21 # try/except since this package may be used outside GeoDjango. 22 22 try: 23 23 from django.contrib.gis.gdal import OGRGeometry, SpatialReference, GEOJSON 24 from django.contrib.gis.gdal.geometries import json_regex 24 25 HAS_GDAL = True 25 26 except: 26 27 HAS_GDAL, GEOJSON = False, False … … 30 31 # library. Not a substitute for good web security programming practices. 31 32 hex_regex = re.compile(r'^[0-9A-F]+$', re.I) 32 33 wkt_regex = re.compile(r'^(SRID=(?P<srid>\d+);)?(?P<wkt>(POINT|LINESTRING|LINEARRING|POLYGON|MULTIPOINT|MULTILINESTRING|MULTIPOLYGON|GEOMETRYCOLLECTION)[ACEGIMLONPSRUTY\d,\.\-\(\) ]+)$', re.I) 33 json_regex = re.compile(r'^\{.+\}$')34 34 35 35 class GEOSGeometry(object): 36 36 "A class that, generally, encapsulates a GEOS geometry." -
django/contrib/gis/tests/test_geos.py
102 102 if not HAS_GDAL or not GEOJSON: return 103 103 for g in json_geoms: 104 104 geom = GEOSGeometry(g.wkt) 105 self.assertEqual(g.json, geom.json) 106 self.assertEqual(g.json, geom.geojson) 105 if not hasattr(g, 'not_equal'): 106 self.assertEqual(g.json, geom.json) 107 self.assertEqual(g.json, geom.geojson) 107 108 self.assertEqual(GEOSGeometry(g.wkt), GEOSGeometry(geom.json)) 108 109 109 110 def test01j_eq(self): -
django/contrib/gis/tests/geometries.py
154 154 json_geoms = (TestGeom('POINT(100 0)', json='{ "type": "Point", "coordinates": [ 100.000000, 0.000000 ] }'), 155 155 TestGeom('POLYGON((0 0, -10 0, -10 -10, 0 -10, 0 0))', json='{ "type": "Polygon", "coordinates": [ [ [ 0.000000, 0.000000 ], [ -10.000000, 0.000000 ], [ -10.000000, -10.000000 ], [ 0.000000, -10.000000 ], [ 0.000000, 0.000000 ] ] ] }'), 156 156 TestGeom('MULTIPOLYGON(((102 2, 103 2, 103 3, 102 3, 102 2)), ((100.0 0.0, 101.0 0.0, 101.0 1.0, 100.0 1.0, 100.0 0.0), (100.2 0.2, 100.8 0.2, 100.8 0.8, 100.2 0.8, 100.2 0.2)))', json='{ "type": "MultiPolygon", "coordinates": [ [ [ [ 102.000000, 2.000000 ], [ 103.000000, 2.000000 ], [ 103.000000, 3.000000 ], [ 102.000000, 3.000000 ], [ 102.000000, 2.000000 ] ] ], [ [ [ 100.000000, 0.000000 ], [ 101.000000, 0.000000 ], [ 101.000000, 1.000000 ], [ 100.000000, 1.000000 ], [ 100.000000, 0.000000 ] ], [ [ 100.200000, 0.200000 ], [ 100.800000, 0.200000 ], [ 100.800000, 0.800000 ], [ 100.200000, 0.800000 ], [ 100.200000, 0.200000 ] ] ] ] }'), 157 TestGeom('GEOMETRYCOLLECTION(POINT(100 0),LINESTRING(101.0 0.0, 102.0 1.0))', 158 json='{ "type": "GeometryCollection", "geometries": [ { "type": "Point", "coordinates": [ 100.000000, 0.000000 ] }, { "type": "LineString", "coordinates": [ [ 101.000000, 0.000000 ], [ 102.000000, 1.000000 ] ] } ] }', 159 ), 160 TestGeom('MULTILINESTRING((100.0 0.0, 101.0 1.0),(102.0 2.0, 103.0 3.0))', 161 json=""" 162 163 { "type": "MultiLineString", 164 "coordinates": [ 165 [ [100.0, 0.0], [101.0, 1.0] ], 166 [ [102.0, 2.0], [103.0, 3.0] ] 167 ] 168 } 169 170 """, 171 not_equal=True, 172 ), 157 173 ) -
django/contrib/gis/tests/test_gdal_geom.py
79 79 if not GEOJSON: return 80 80 for g in json_geoms: 81 81 geom = OGRGeometry(g.wkt) 82 self.assertEqual(g.json, geom.json) 83 self.assertEqual(g.json, geom.geojson) 82 if not hasattr(g, 'not_equal'): 83 self.assertEqual(g.json, geom.json) 84 self.assertEqual(g.json, geom.geojson) 84 85 self.assertEqual(OGRGeometry(g.wkt), OGRGeometry(geom.json)) 85 86 86 87 def test02_points(self): -
django/contrib/gis/gdal/geometries.py
61 61 # Regular expressions for recognizing HEXEWKB and WKT. 62 62 hex_regex = re.compile(r'^[0-9A-F]+$', re.I) 63 63 wkt_regex = re.compile(r'^(?P<type>POINT|LINESTRING|LINEARRING|POLYGON|MULTIPOINT|MULTILINESTRING|MULTIPOLYGON|GEOMETRYCOLLECTION)[ACEGIMLONPSRUTY\d,\.\-\(\) ]+$', re.I) 64 json_regex = re.compile(r'^ \{[\s\w,\-\.\"\'\:\[\]]+\}$')64 json_regex = re.compile(r'^(\s+)?\{[\s\w,\[\]\{\}\-\."\':]+\}(\s+)?$') 65 65 66 66 #### OGRGeometry Class #### 67 67 class OGRGeometry(object):