From 465a29abe09012059b4a8ff34f1020f48879ad71 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Fri, 10 May 2013 12:47:03 +0200 Subject: [PATCH] Fixed #20384 -- Forced GeoIP_open path argument to bytestring Thanks Julian Wachholz for the report. --- django/contrib/gis/geoip/base.py | 7 ++++--- django/contrib/gis/geoip/tests.py | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/django/contrib/gis/geoip/base.py b/django/contrib/gis/geoip/base.py index 4b8b6e1ed3..4b114f8b2b 100644 --- a/django/contrib/gis/geoip/base.py +++ b/django/contrib/gis/geoip/base.py @@ -11,6 +11,7 @@ from django.contrib.gis.geoip.prototypes import ( GeoIP_country_name_by_addr, GeoIP_country_name_by_name) from django.utils import six +from django.utils.encoding import force_bytes # Regular expressions for recognizing the GeoIP free database editions. free_regex = re.compile(r'^GEO-\d{3}FREE') @@ -97,18 +98,18 @@ class GeoIP(object): # and/or city datasets exist, then try and open them. country_db = os.path.join(path, country or GEOIP_SETTINGS.get('GEOIP_COUNTRY', 'GeoIP.dat')) if os.path.isfile(country_db): - self._country = GeoIP_open(country_db, cache) + self._country = GeoIP_open(force_bytes(country_db), cache) self._country_file = country_db city_db = os.path.join(path, city or GEOIP_SETTINGS.get('GEOIP_CITY', 'GeoLiteCity.dat')) if os.path.isfile(city_db): - self._city = GeoIP_open(city_db, cache) + self._city = GeoIP_open(force_bytes(city_db), cache) self._city_file = city_db elif os.path.isfile(path): # Otherwise, some detective work will be needed to figure # out whether the given database path is for the GeoIP country # or city databases. - ptr = GeoIP_open(path, cache) + ptr = GeoIP_open(force_bytes(path), cache) info = GeoIP_database_info(ptr) if lite_regex.match(info): # GeoLite City database detected. diff --git a/django/contrib/gis/geoip/tests.py b/django/contrib/gis/geoip/tests.py index c890c4f4ba..458c947a27 100644 --- a/django/contrib/gis/geoip/tests.py +++ b/django/contrib/gis/geoip/tests.py @@ -103,8 +103,8 @@ class GeoIPTest(unittest.TestCase): def test05_unicode_response(self): "Testing that GeoIP strings are properly encoded, see #16553." g = GeoIP() - d = g.city('62.224.93.23') - self.assertEqual('Schümberg', d['city']) + d = g.city("www.osnabrueck.de") + self.assertEqual('Osnabrück', d['city']) def test06_unicode_query(self): "Testing that GeoIP accepts unicode string queries, see #17059."