Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #17212 -- Made GEOS version regular expression more robust. Tha…

…nks, strk.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@17682 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 771fce45b40deec44b47014829c1f7e973fc7fd7 1 parent bf1112d
Justin Bronn authored March 12, 2012
4  django/contrib/gis/geos/libgeos.py
@@ -101,8 +101,8 @@ def get_pointer_arr(n):
101 101
 geos_version.restype = c_char_p
102 102
 
103 103
 # Regular expression should be able to parse version strings such as
104  
-# '3.0.0rc4-CAPI-1.3.3', or '3.0.0-CAPI-1.4.1'
105  
-version_regex = re.compile(r'^(?P<version>(?P<major>\d+)\.(?P<minor>\d+)\.(?P<subminor>\d+))(rc(?P<release_candidate>\d+))?-CAPI-(?P<capi_version>\d+\.\d+\.\d+)$')
  104
+# '3.0.0rc4-CAPI-1.3.3', '3.0.0-CAPI-1.4.1' or '3.4.0dev-CAPI-1.8.0'
  105
+version_regex = re.compile(r'^(?P<version>(?P<major>\d+)\.(?P<minor>\d+)\.(?P<subminor>\d+))((rc(?P<release_candidate>\d+))|dev)?-CAPI-(?P<capi_version>\d+\.\d+\.\d+)$')
106 106
 def geos_version_info():
107 107
     """
108 108
     Returns a dictionary containing the various version metadata parsed from
14  django/contrib/gis/geos/tests/test_geos.py
@@ -901,7 +901,7 @@ def test23_transform_nosrid(self):
901 901
             # Keeping line-noise down by only printing the relevant
902 902
             # warnings once.
903 903
             warnings.simplefilter('once', UserWarning)
904  
-            warnings.simplefilter('once', FutureWarning)    
  904
+            warnings.simplefilter('once', FutureWarning)
905 905
 
906 906
             g = GEOSGeometry('POINT (-104.609 38.255)', srid=None)
907 907
             g.transform(2774)
@@ -1049,6 +1049,18 @@ def test27_valid_reason(self):
1049 1049
 
1050 1050
         print "\nEND - expecting GEOS_NOTICE; safe to ignore.\n"
1051 1051
 
  1052
+    def test28_geos_version(self):
  1053
+        "Testing the GEOS version regular expression."
  1054
+        from django.contrib.gis.geos.libgeos import version_regex
  1055
+        versions = [ ('3.0.0rc4-CAPI-1.3.3', '3.0.0'),
  1056
+                     ('3.0.0-CAPI-1.4.1', '3.0.0'),
  1057
+                     ('3.4.0dev-CAPI-1.8.0', '3.4.0') ]
  1058
+        for v, expected in versions:
  1059
+            m = version_regex.match(v)
  1060
+            self.assertTrue(m)
  1061
+            self.assertEqual(m.group('version'), expected)
  1062
+
  1063
+
1052 1064
 def suite():
1053 1065
     s = unittest.TestSuite()
1054 1066
     s.addTest(unittest.makeSuite(GEOSTest))

0 notes on commit 771fce4

Please sign in to comment.
Something went wrong with that request. Please try again.