Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #20384 -- Forced GeoIP_open path argument to bytestring

Thanks Julian Wachholz for the report.
  • Loading branch information...
commit 465a29abe09012059b4a8ff34f1020f48879ad71 1 parent 9a3708c
@claudep claudep authored
View
7 django/contrib/gis/geoip/base.py
@@ -11,6 +11,7 @@
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 @@ def __init__(self, path=None, cache=0, country=None, city=None):
# 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.
View
4 django/contrib/gis/geoip/tests.py
@@ -103,8 +103,8 @@ def test04_city(self):
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."
Please sign in to comment.
Something went wrong with that request. Please try again.