summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2013-03-13 09:50:45 +0100
committerClaude Paroz <claude@2xlibre.net>2014-09-11 20:54:33 +0200
commitba2be2761341a6b3d8d578f16c92fa278c0a42bc (patch)
tree89fe3cd408414ccec0a43221e3682a64b9089f8d
parent065caafa70b6c422f73e364a4c241b6538969d7b (diff)
[1.4.x] Fixed #20036 -- Improved GEOS version string parsing
Thanks chikiro.spam at gmail.com for the report.
-rw-r--r--django/contrib/gis/geos/libgeos.py13
-rw-r--r--django/contrib/gis/geos/tests/test_geos.py18
-rw-r--r--docs/releases/1.4.16.txt6
3 files changed, 24 insertions, 13 deletions
diff --git a/django/contrib/gis/geos/libgeos.py b/django/contrib/gis/geos/libgeos.py
index a4f5adf4d0..433a7d84c0 100644
--- a/django/contrib/gis/geos/libgeos.py
+++ b/django/contrib/gis/geos/libgeos.py
@@ -101,8 +101,11 @@ geos_version.argtypes = None
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
@@ -112,8 +115,10 @@ def geos_version_info():
"""
ver = geos_version()
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()
diff --git a/django/contrib/gis/geos/tests/test_geos.py b/django/contrib/gis/geos/tests/test_geos.py
index ddd5d58226..2cb6aff9f4 100644
--- a/django/contrib/gis/geos/tests/test_geos.py
+++ b/django/contrib/gis/geos/tests/test_geos.py
@@ -1050,15 +1050,17 @@ class GEOSTest(unittest.TestCase, TestDataMixin):
print "\nEND - expecting GEOS_NOTICE; safe to ignore.\n"
def test28_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():
diff --git a/docs/releases/1.4.16.txt b/docs/releases/1.4.16.txt
index 7c6e2675a0..b10a72d264 100644
--- a/docs/releases/1.4.16.txt
+++ b/docs/releases/1.4.16.txt
@@ -4,10 +4,14 @@ Django 1.4.16 release notes
*Under development*
-Django 1.4.16 fixes a regression in the 1.4.14 security release.
+Django 1.4.16 fixes a regression in the 1.4.14 security release and a bug
+preventing the use of some GEOS versions with GeoDjango.
Bugfixes
========
* Allowed inline and hidden references to admin fields
(`#23431 <http://code.djangoproject.com/ticket/23431>`_).
+
+* Fixed parsing of the GEOS version string
+ (`#20036 <http://code.djangoproject.com/ticket/20036>`_).