Skip to content

Commit 78f472c

Browse files
committed
Renamed languages to locales in code
1 parent b23f223 commit 78f472c

File tree

6 files changed

+76
-77
lines changed

6 files changed

+76
-77
lines changed

geoip2/database.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ class Reader(object):
4040
4141
"""
4242

43-
def __init__(self, filename, languages=None):
44-
if languages is None:
45-
languages = ['en']
43+
def __init__(self, filename, locales=None):
44+
if locales is None:
45+
locales = ['en']
4646
self.db_reader = maxminddb.Reader(filename)
47-
self.languages = languages
47+
self.locales = locales
4848

4949
def country(self, ip_address):
5050
"""Get the Country record object for the IP address
@@ -102,7 +102,7 @@ def _model_for(self, model_class, ip_address):
102102
raise geoip2.errors.AddressNotFoundError(
103103
"The address %s is not in the database." % (ip_address))
104104
record.setdefault('traits', {})['ip_address'] = ip_address
105-
return model_class(record, languages=self.languages)
105+
return model_class(record, locales=self.locales)
106106

107107
def close(self):
108108
"""Closes the GeoIP2 database"""

geoip2/models.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,21 +65,21 @@ class Country(object):
6565
6666
"""
6767

68-
def __init__(self, raw_response, languages=None):
69-
if languages is None:
70-
languages = ['en']
68+
def __init__(self, raw_response, locales=None):
69+
if locales is None:
70+
locales = ['en']
7171
self.continent = \
72-
geoip2.records.Continent(languages,
72+
geoip2.records.Continent(locales,
7373
**raw_response.get('continent', {}))
7474
self.country = \
75-
geoip2.records.Country(languages,
75+
geoip2.records.Country(locales,
7676
**raw_response.get('country', {}))
7777
self.registered_country = \
78-
geoip2.records.Country(languages,
78+
geoip2.records.Country(locales,
7979
**raw_response.get('registered_country',
8080
{}))
8181
self.represented_country \
82-
= geoip2.records.RepresentedCountry(languages,
82+
= geoip2.records.RepresentedCountry(locales,
8383
**raw_response.get(
8484
'represented_country', {}))
8585

@@ -155,16 +155,16 @@ class City(Country):
155155
156156
"""
157157

158-
def __init__(self, raw_response, languages=None):
159-
super(City, self).__init__(raw_response, languages)
158+
def __init__(self, raw_response, locales=None):
159+
super(City, self).__init__(raw_response, locales)
160160
self.city = \
161-
geoip2.records.City(languages, **raw_response.get('city', {}))
161+
geoip2.records.City(locales, **raw_response.get('city', {}))
162162
self.location = \
163163
geoip2.records.Location(**raw_response.get('location', {}))
164164
self.postal = \
165165
geoip2.records.Postal(**raw_response.get('postal', {}))
166166
self.subdivisions = \
167-
geoip2.records.Subdivisions(languages,
167+
geoip2.records.Subdivisions(locales,
168168
*raw_response.get('subdivisions', []))
169169

170170

geoip2/records.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,19 @@ class PlaceRecord(Record):
2828
"""All records with :py:attr:`names` subclass :py:class:`PlaceRecord`"""
2929
__metaclass__ = ABCMeta
3030

31-
def __init__(self, languages=None, **kwargs):
32-
if languages is None:
33-
languages = ['en']
31+
def __init__(self, locales=None, **kwargs):
32+
if locales is None:
33+
locales = ['en']
3434
if kwargs.get('names') is None:
3535
kwargs['names'] = {}
36-
object.__setattr__(self, '_languages', languages)
36+
object.__setattr__(self, '_locales', locales)
3737
super(PlaceRecord, self).__init__(**kwargs)
3838

3939
@property
4040
def name(self):
4141
"""Dict with locale codes as keys and localized name as value"""
4242
# pylint:disable=E1101
43-
return next((self.names.get(x) for x in self._languages if x in
43+
return next((self.names.get(x) for x in self._locales if x in
4444
self.names), None)
4545

4646

@@ -71,8 +71,8 @@ class City(PlaceRecord):
7171
7272
.. attribute:: name
7373
74-
The name of the city based on the languages list
75-
passed to the constructor. This attribute is returned by all end points.
74+
The name of the city based on the locales list passed to the
75+
constructor. This attribute is returned by all end points.
7676
7777
:type: unicode
7878
@@ -115,8 +115,8 @@ class Continent(PlaceRecord):
115115
116116
.. attribute:: name
117117
118-
Returns the name of the continent based on the languages list
119-
passed to the constructor. This attribute is returned by all end points.
118+
Returns the name of the continent based on the locales list passed to
119+
the constructor. This attribute is returned by all end points.
120120
121121
:type: unicode
122122
@@ -167,8 +167,8 @@ class Country(PlaceRecord):
167167
168168
.. attribute:: name
169169
170-
The name of the country based on the languages list
171-
passed to the constructor. This attribute is returned by all end points.
170+
The name of the country based on the locales list passed to the
171+
constructor. This attribute is returned by all end points.
172172
173173
:type: unicode
174174
@@ -221,8 +221,8 @@ class RepresentedCountry(Country):
221221
222222
.. attribute:: name
223223
224-
The name of the country based on the languages list
225-
passed to the constructor. This attribute is returned by all end points.
224+
The name of the country based on the locales list passed to the
225+
constructor. This attribute is returned by all end points.
226226
227227
:type: unicode
228228
@@ -395,8 +395,8 @@ class Subdivision(PlaceRecord):
395395
396396
.. attribute:: name
397397
398-
The name of the subdivision based on the languages list
399-
passed to the constructor. This attribute is returned by all end points.
398+
The name of the subdivision based on the locales list passed to the
399+
constructor. This attribute is returned by all end points.
400400
401401
:type: unicode
402402
@@ -427,10 +427,10 @@ class Subdivisions(tuple):
427427
428428
"""
429429
# pylint:disable=R0924,W0212,W0142
430-
def __new__(cls, languages, *subdivisions):
431-
subdivisions = [Subdivision(languages, **x) for x in subdivisions]
430+
def __new__(cls, locales, *subdivisions):
431+
subdivisions = [Subdivision(locales, **x) for x in subdivisions]
432432
obj = super(cls, Subdivisions).__new__(cls, subdivisions)
433-
obj._languages = languages
433+
obj._locales = locales
434434
return obj
435435

436436
@property
@@ -445,7 +445,7 @@ def most_specific(self):
445445
try:
446446
return self[-1]
447447
except IndexError:
448-
return Subdivision(self._languages)
448+
return Subdivision(self._locales)
449449

450450

451451
class Traits(Record):

geoip2/webservice.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,16 @@ class Client(object):
5959
:param host: The hostname to make a request against. This defaults to
6060
"geoip.maxmind.com". In most cases, you should not need to set this
6161
explicitly.
62-
:param languages: This is list of locale codes. This argument will be
62+
:param locales: This is list of locale codes. This argument will be
6363
passed on to record classes to use when their name properties are
6464
called. The default value is ['en'].
6565
66-
The order of the languages is significant. When a record class has
66+
The order of the locales is significant. When a record class has
6767
multiple names (country, city, etc.), its name property will return
68-
the name in the first language that has one.
68+
the name in the first locale that has one.
6969
70-
Note that the only language which is always present in the GeoIP2
71-
data is "en". If you do not include this language, the name property
70+
Note that the only locale which is always present in the GeoIP2
71+
data is "en". If you do not include this locale, the name property
7272
may end up returning None even when the record has an English name.
7373
7474
Currently, the valid locale codes are:
@@ -87,10 +87,10 @@ class Client(object):
8787
"""
8888

8989
def __init__(self, user_id, license_key, host='geoip.maxmind.com',
90-
languages=None):
91-
if languages is None:
92-
languages = ['en']
93-
self.languages = languages
90+
locales=None):
91+
if locales is None:
92+
locales = ['en']
93+
self.locales = locales
9494
self.user_id = user_id
9595
self.license_key = license_key
9696
self._base_uri = 'https://%s/geoip/v2.0' % (host)
@@ -154,7 +154,7 @@ def _response_for(self, path, model_class, ip_address):
154154
'User-Agent': self._user_agent()})
155155
if (response.status_code == 200): # pylint:disable=E1103
156156
body = self._handle_success(response, uri)
157-
return model_class(body, languages=self.languages)
157+
return model_class(body, locales=self.locales)
158158
else:
159159
self._handle_error(response, uri)
160160

tests/database_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
class TestReader(unittest.TestCase):
2222

23-
def test_default_language(self):
23+
def test_default_locale(self):
2424
reader = geoip2.database.Reader(
2525
'tests/data/test-data/GeoIP2-City-Test.mmdb')
2626
record = reader.city('81.2.69.160')

0 commit comments

Comments
 (0)