Skip to content

Commit

Permalink
Fixed #20384 -- Forced GeoIP_open path argument to bytestring
Browse files Browse the repository at this point in the history
Thanks Julian Wachholz for the report.
  • Loading branch information
claudep committed May 10, 2013
1 parent 9a3708c commit 465a29a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions django/contrib/gis/geoip/base.py
Expand Up @@ -11,6 +11,7 @@
GeoIP_country_name_by_addr, GeoIP_country_name_by_name) GeoIP_country_name_by_addr, GeoIP_country_name_by_name)


from django.utils import six from django.utils import six
from django.utils.encoding import force_bytes


# Regular expressions for recognizing the GeoIP free database editions. # Regular expressions for recognizing the GeoIP free database editions.
free_regex = re.compile(r'^GEO-\d{3}FREE') free_regex = re.compile(r'^GEO-\d{3}FREE')
Expand Down Expand Up @@ -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. # 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')) country_db = os.path.join(path, country or GEOIP_SETTINGS.get('GEOIP_COUNTRY', 'GeoIP.dat'))
if os.path.isfile(country_db): 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 self._country_file = country_db


city_db = os.path.join(path, city or GEOIP_SETTINGS.get('GEOIP_CITY', 'GeoLiteCity.dat')) city_db = os.path.join(path, city or GEOIP_SETTINGS.get('GEOIP_CITY', 'GeoLiteCity.dat'))
if os.path.isfile(city_db): 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 self._city_file = city_db
elif os.path.isfile(path): elif os.path.isfile(path):
# Otherwise, some detective work will be needed to figure # Otherwise, some detective work will be needed to figure
# out whether the given database path is for the GeoIP country # out whether the given database path is for the GeoIP country
# or city databases. # or city databases.
ptr = GeoIP_open(path, cache) ptr = GeoIP_open(force_bytes(path), cache)
info = GeoIP_database_info(ptr) info = GeoIP_database_info(ptr)
if lite_regex.match(info): if lite_regex.match(info):
# GeoLite City database detected. # GeoLite City database detected.
Expand Down
4 changes: 2 additions & 2 deletions django/contrib/gis/geoip/tests.py
Expand Up @@ -103,8 +103,8 @@ def test04_city(self):
def test05_unicode_response(self): def test05_unicode_response(self):
"Testing that GeoIP strings are properly encoded, see #16553." "Testing that GeoIP strings are properly encoded, see #16553."
g = GeoIP() g = GeoIP()
d = g.city('62.224.93.23') d = g.city("www.osnabrueck.de")
self.assertEqual('Schümberg', d['city']) self.assertEqual('Osnabrück', d['city'])


def test06_unicode_query(self): def test06_unicode_query(self):
"Testing that GeoIP accepts unicode string queries, see #17059." "Testing that GeoIP accepts unicode string queries, see #17059."
Expand Down

0 comments on commit 465a29a

Please sign in to comment.