summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2014-02-10 15:55:57 +0100
committerClaude Paroz <claude@2xlibre.net>2014-02-10 16:12:22 +0100
commit76700c5437d4b5187f58a3f99104f45002d1524e (patch)
treed10e68e1ed68b36d138c6b136f92256ebddf2962
parente9ffe7e3c8e8fefa1f5675a30016740d6c812cca (diff)
[1.6.x] Fixed #21996 -- Used proper encoding for GeoIP content
Thanks Florent Messa for the report. Backport of fb1e3435a4 from master.
-rw-r--r--django/contrib/gis/geoip/prototypes.py5
-rw-r--r--django/contrib/gis/geoip/tests.py2
-rw-r--r--docs/releases/1.6.3.txt4
3 files changed, 8 insertions, 3 deletions
diff --git a/django/contrib/gis/geoip/prototypes.py b/django/contrib/gis/geoip/prototypes.py
index 283d721395..a5db5e7ecc 100644
--- a/django/contrib/gis/geoip/prototypes.py
+++ b/django/contrib/gis/geoip/prototypes.py
@@ -22,6 +22,7 @@ class GeoIPRecord(Structure):
('continent_code', c_char_p),
]
geoip_char_fields = [name for name, ctype in GeoIPRecord._fields_ if ctype is c_char_p]
+GEOIP_DEFAULT_ENCODING = 'iso-8859-1'
geoip_encodings = { 0: 'iso-8859-1',
1: 'utf8',
}
@@ -92,7 +93,7 @@ def check_string(result, func, cargs):
free(result)
else:
s = ''
- return s.decode()
+ return s.decode(GEOIP_DEFAULT_ENCODING)
GeoIP_database_info = lgeoip.GeoIP_database_info
GeoIP_database_info.restype = geoip_char_p
@@ -102,7 +103,7 @@ GeoIP_database_info.errcheck = check_string
def string_output(func):
def _err_check(result, func, cargs):
if result:
- return result.decode()
+ return result.decode(GEOIP_DEFAULT_ENCODING)
return result
func.restype = c_char_p
func.errcheck = _err_check
diff --git a/django/contrib/gis/geoip/tests.py b/django/contrib/gis/geoip/tests.py
index d17f878702..0a99a97dc3 100644
--- a/django/contrib/gis/geoip/tests.py
+++ b/django/contrib/gis/geoip/tests.py
@@ -118,3 +118,5 @@ class GeoIPTest(unittest.TestCase):
g = GeoIP()
d = g.city("www.osnabrueck.de")
self.assertEqual('Osnabrück', d['city'])
+ d = g.country('200.7.49.81')
+ self.assertEqual('Curaçao', d['country_name'])
diff --git a/docs/releases/1.6.3.txt b/docs/releases/1.6.3.txt
index e3fccafd5d..45a1ad0c19 100644
--- a/docs/releases/1.6.3.txt
+++ b/docs/releases/1.6.3.txt
@@ -7,4 +7,6 @@ Django 1.6.3 release notes
This is Django 1.6.3, a bugfix release for Django 1.6. Django 1.6.3 fixes
several bugs in 1.6.2:
-* ...
+* Content retrieved from the GeoIP library is now properly decoded from its
+ default ``iso-8859-1`` encoding
+ (`#21996 <http://code.djangoproject.com/ticket/21996>`_).