Ticket #9566: geojson_regex.diff

File geojson_regex.diff, 5.0 KB (added by jbronn, 16 years ago)
  • django/contrib/gis/geos/base.py

     
    2121# try/except since this package may be used outside GeoDjango.
    2222try:
    2323    from django.contrib.gis.gdal import OGRGeometry, SpatialReference, GEOJSON
     24    from django.contrib.gis.gdal.geometries import json_regex
    2425    HAS_GDAL = True
    2526except:
    2627    HAS_GDAL, GEOJSON = False, False
     
    3031# library.  Not a substitute for good web security programming practices.
    3132hex_regex = re.compile(r'^[0-9A-F]+$', re.I)
    3233wkt_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'^\{.+\}$')
    3434
    3535class GEOSGeometry(object):
    3636    "A class that, generally, encapsulates a GEOS geometry."
  • django/contrib/gis/tests/test_geos.py

     
    102102        if not HAS_GDAL or not GEOJSON: return
    103103        for g in json_geoms:
    104104            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)
    107108            self.assertEqual(GEOSGeometry(g.wkt), GEOSGeometry(geom.json))
    108109
    109110    def test01j_eq(self):
  • django/contrib/gis/tests/geometries.py

     
    154154json_geoms = (TestGeom('POINT(100 0)', json='{ "type": "Point", "coordinates": [ 100.000000, 0.000000 ] }'),
    155155              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 ] ] ] }'),
    156156              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                       ),
    157173              )
  • django/contrib/gis/tests/test_gdal_geom.py

     
    7979        if not GEOJSON: return
    8080        for g in json_geoms:
    8181            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)
    8485            self.assertEqual(OGRGeometry(g.wkt), OGRGeometry(geom.json))
    8586
    8687    def test02_points(self):
  • django/contrib/gis/gdal/geometries.py

     
    6161# Regular expressions for recognizing HEXEWKB and WKT.
    6262hex_regex = re.compile(r'^[0-9A-F]+$', re.I)
    6363wkt_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,\-\.\"\'\:\[\]]+\}$')
     64json_regex = re.compile(r'^(\s+)?\{[\s\w,\[\]\{\}\-\."\':]+\}(\s+)?$')
    6565
    6666#### OGRGeometry Class ####
    6767class OGRGeometry(object):
Back to Top