Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed #20036 -- Improved GEOS version string parsing

Thanks chikiro.spam at gmail.com for the report.
  • Loading branch information...
commit 747f7d25490abc3d7fdb119f0ce3708d450eb4c2 1 parent d3f00bd
Claude Paroz claudep authored
13 django/contrib/gis/geos/libgeos.py
View
@@ -108,8 +108,11 @@ def get_pointer_arr(n):
geos_version.restype = c_char_p
# Regular expression should be able to parse version strings such as
-# '3.0.0rc4-CAPI-1.3.3', '3.0.0-CAPI-1.4.1' or '3.4.0dev-CAPI-1.8.0'
-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+)$')
+# '3.0.0rc4-CAPI-1.3.3', '3.0.0-CAPI-1.4.1', '3.4.0dev-CAPI-1.8.0' or '3.4.0dev-CAPI-1.8.0 r0'
+version_regex = re.compile(
+ r'^(?P<version>(?P<major>\d+)\.(?P<minor>\d+)\.(?P<subminor>\d+))'
+ r'((rc(?P<release_candidate>\d+))|dev)?-CAPI-(?P<capi_version>\d+\.\d+\.\d+)( r\d+)?$'
+)
def geos_version_info():
"""
Returns a dictionary containing the various version metadata parsed from
@@ -119,8 +122,10 @@ def geos_version_info():
"""
ver = geos_version().decode()
m = version_regex.match(ver)
- if not m: raise GEOSException('Could not parse version info string "%s"' % ver)
- return dict((key, m.group(key)) for key in ('version', 'release_candidate', 'capi_version', 'major', 'minor', 'subminor'))
+ if not m:
+ raise GEOSException('Could not parse version info string "%s"' % ver)
+ return dict((key, m.group(key)) for key in (
+ 'version', 'release_candidate', 'capi_version', 'major', 'minor', 'subminor'))
# Version numbers and whether or not prepared geometry support is available.
_verinfo = geos_version_info()
18 django/contrib/gis/geos/tests/test_geos.py
View
@@ -1080,15 +1080,17 @@ def test_linearref(self):
self.assertEqual(mls.interpolate(17), Point(10, 7))
def test_geos_version(self):
- "Testing the GEOS version regular expression."
+ """Testing the GEOS version regular expression."""
from django.contrib.gis.geos.libgeos import version_regex
- versions = [ ('3.0.0rc4-CAPI-1.3.3', '3.0.0'),
- ('3.0.0-CAPI-1.4.1', '3.0.0'),
- ('3.4.0dev-CAPI-1.8.0', '3.4.0') ]
- for v, expected in versions:
- m = version_regex.match(v)
- self.assertTrue(m)
- self.assertEqual(m.group('version'), expected)
+ versions = [('3.0.0rc4-CAPI-1.3.3', '3.0.0', '1.3.3'),
+ ('3.0.0-CAPI-1.4.1', '3.0.0', '1.4.1'),
+ ('3.4.0dev-CAPI-1.8.0', '3.4.0', '1.8.0'),
+ ('3.4.0dev-CAPI-1.8.0 r0', '3.4.0', '1.8.0')]
+ for v_init, v_geos, v_capi in versions:
+ m = version_regex.match(v_init)
+ self.assertTrue(m, msg="Unable to parse the version string '%s'" % v_init)
+ self.assertEqual(m.group('version'), v_geos)
+ self.assertEqual(m.group('capi_version'), v_capi)
def suite():
Please sign in to comment.
Something went wrong with that request. Please try again.