Skip to content

Commit bc2259e

Browse files
committed
We renamed 'name' to 'names' in the REST hash to be more consistent with the APIs. I updated to API to reflect this. I also made some PEP8 and misc. whitespace changes
1 parent 34b3e82 commit bc2259e

File tree

5 files changed

+34
-31
lines changed

5 files changed

+34
-31
lines changed

geoip2/errors.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ class GeoIP2Error(RuntimeError):
1717
class GeoIP2HTTPError(GeoIP2Error):
1818
"""There was an error when making your HTTP request.
1919
20-
This class represents an HTTP transport error. It extends
20+
This class represents an HTTP transport error. It extends
2121
:py:exc:`GeoIP2Error` and adds attributes of its own.
2222
2323
:ivar http_status: The HTTP status code returned
2424
:ivar uri: The URI queried
25+
2526
"""
2627
def __init__(self, message, http_status=None, uri=None):
2728
super(GeoIP2HTTPError, self).__init__(message)

geoip2/records.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,10 @@ class PlaceRecord(Record):
2121
"""All records with :py:attr:`names` subclass :py:class:`PlaceRecord`"""
2222
__metaclass__ = ABCMeta
2323

24-
# XXX - why did we name it 'name' instead of 'names'?
2524
def __init__(self, languages=None, **kwargs):
2625
if languages is None:
2726
languages = []
2827
object.__setattr__(self, 'languages', languages)
29-
kwargs['names'] = kwargs.pop('name', [])
3028
super(PlaceRecord, self).__init__(**kwargs)
3129

3230
@property
@@ -53,6 +51,7 @@ class City(PlaceRecord):
5351
passed to the constructor. This attribute is returned by all end points.
5452
:ivar names: This returns a dictionary where the keys are language codes
5553
and the values are names. This attribute is returned by all end points.
54+
5655
"""
5756
_valid_attributes = set(['confidence', 'geoname_id', 'names'])
5857

@@ -76,6 +75,7 @@ class Continent(PlaceRecord):
7675
passed to the constructor. This attribute is returned by all end points.
7776
:ivar names: This returns a dictionary where the keys are language codes
7877
and the values are names. This attribute is returned by all end points.
78+
7979
"""
8080
_valid_attributes = set(['continent_code', 'geoname_id', 'names'])
8181

@@ -132,7 +132,8 @@ class Location(Record):
132132
location is in the US. MaxMind returns the same metro codes as the
133133
Google AdWords API
134134
(https://developers.google.com/adwords/api/docs/appendix/cities-DMAregions).
135-
This attribute is returned by all end points except the Country end point.
135+
This attribute is returned by all end points except the Country end
136+
point.
136137
:ivar postal_code: This returns the postal code of the location. Postal
137138
codes are not available for all countries. In some countries, this will
138139
only contain part of the postal code. This attribute is returned by all
@@ -141,9 +142,9 @@ class Location(Record):
141142
MaxMind's confidence that the postal code is correct. This attribute is
142143
only available from the Omni end point.
143144
:ivar time_zone: This returns the time zone associated with location, as
144-
specified by the IANA Time Zone Database (http://www.iana.org/time-zones),
145-
e.g., "America/New_York". This attribute is returned by all end points
146-
except the Country end point.
145+
specified by the IANA Time Zone Database
146+
(http://www.iana.org/time-zones), e.g., "America/New_York". This
147+
attribute is returned by all end points except the Country end point.
147148
148149
"""
149150
_valid_attributes = set(['accuracy_radius', 'latitude', 'longitude'
@@ -166,7 +167,7 @@ class Region(PlaceRecord):
166167
:ivar geoname_id: This is a GeoName ID for the region. This attribute
167168
is returned by all end points.
168169
:ivar iso_3166_2: This is a string up to three characters long
169-
contain the region portion of the ISO 3166-2 code
170+
contain the region portion of the ISO 3166-2 code
170171
(http://en.wikipedia.org/wiki/ISO_3166-2). This attribute is returned
171172
by all end points.
172173
:ivar name: The name of the region based on the languages list
@@ -208,12 +209,13 @@ class Traits(Record):
208209
address locally assigned to it. This attribute is returned by all end
209210
points.
210211
:ivar is_anonymous_proxy: This returns true if the IP is an anonymous
211-
proxy. See http://dev.maxmind.com/faq/geoip#anonproxy for further details.
212-
This attribute is returned by all end points.
212+
proxy. See http://dev.maxmind.com/faq/geoip#anonproxy for further
213+
details. This attribute is returned by all end points.
213214
:ivar is_transparent_proxy: This returns true if the IP is a transparent
214215
proxy. This attribute is returned by all end points.
215216
:ivar isp: This returns the name of the ISP associated the IP address.
216-
This attribute is only available from the City/ISP/Org and Omni end points.
217+
This attribute is only available from the City/ISP/Org and Omni end
218+
points.
217219
:ivar organization: This returns the name of the organization associated
218220
the IP address. This attribute is only available from the City/ISP/Org
219221
and Omni end points.

geoip2/webservices.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
See http://dev.maxmind.com/geoip/precision for details on what data each end
8787
point may return.
8888
89-
The only piece of data which is always returned is the :py:attr:`ip_address`
89+
The only piece of data which is always returned is the :py:attr:`ip_address`
9090
attribute in the :py:class:`geoip2.records.Traits` record.
9191
9292
Every record class attribute has a corresponding predicate method so you can
@@ -123,7 +123,7 @@ class Client(object):
123123
the name in the first language that has one.
124124
125125
Note that the only language which is always present in the GeoIP2
126-
Precision data in "en". If you do not include this language, the
126+
Precision data in "en". If you do not include this language, the
127127
name property may end up returning None even when the record hass
128128
an English name.
129129

tests/models_test.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python
2-
# -*- coding: utf-8 -*-
2+
# -*- coding: utf-8 -*-
33

44
from __future__ import unicode_literals
55

@@ -17,19 +17,19 @@ def test_omni_full(self):
1717
'city': {
1818
'confidence': 76,
1919
'geoname_id': 9876,
20-
'name': {'en': 'Minneapolis'},
20+
'names': {'en': 'Minneapolis'},
2121
},
2222
'continent': {
2323
'continent_code': 'NA',
2424
'geoname_id': 42,
25-
'name': {'en': 'North America'},
25+
'names': {'en': 'North America'},
2626
},
2727
'country': {
2828
'confidence': 99,
2929
'geoname_id': 1,
3030
'iso_3166_1_alpha_2': 'US',
3131
'iso_3166_1_alpha_3': 'USA',
32-
'name': {'en': 'United States of America'},
32+
'names': {'en': 'United States of America'},
3333
},
3434
'location': {
3535
'accuracy_radius': 1500,
@@ -44,13 +44,13 @@ def test_omni_full(self):
4444
'confidence': 88,
4545
'geoname_id': 574635,
4646
'iso_3166_2': 'MN',
47-
'name': {'en': 'Minnesota'},
47+
'names': {'en': 'Minnesota'},
4848
},
4949
'registered_country': {
5050
'geoname_id': 2,
5151
'iso_3166_1_alpha_2': 'CA',
5252
'iso_3166_1_alpha_3': 'CAN',
53-
'name': {'en': 'Canada'},
53+
'names': {'en': 'Canada'},
5454
},
5555
'traits': {
5656
'autonomous_system_number': 1234,
@@ -112,19 +112,19 @@ def test_city_full(self):
112112
'continent': {
113113
'continent_code': 'NA',
114114
'geoname_id': 42,
115-
'name': {'en': 'North America'},
115+
'names': {'en': 'North America'},
116116
},
117117
'country': {
118118
'geoname_id': 1,
119119
'iso_3166_1_alpha_2': 'US',
120120
'iso_3166_1_alpha_3': 'USA',
121-
'name': {'en': 'United States of America'},
121+
'names': {'en': 'United States of America'},
122122
},
123123
'registered_country': {
124124
'geoname_id': 2,
125125
'iso_3166_1_alpha_2': 'CA',
126126
'iso_3166_1_alpha_3': 'CAN',
127-
'name': {'en': 'Canada'},
127+
'names': {'en': 'Canada'},
128128
},
129129
'traits': {
130130
'ip_address': '1.2.3.4',
@@ -193,17 +193,17 @@ def test_names(self):
193193
raw = {
194194
'continent': {
195195
'continent_code': 'NA',
196-
'geoname_id': 42,
197-
'name': {
196+
'geoname_id': 42,
197+
'names': {
198198
'en': 'North America',
199199
'zh-CN': '北美洲',
200200
},
201201
},
202202
'country': {
203-
'geoname_id': 1,
203+
'geoname_id': 1,
204204
'iso_3166_1_alpha_2': 'US',
205205
'iso_3166_1_alpha_3': 'USA',
206-
'name': {
206+
'names': {
207207
'en': 'United States of America',
208208
'fr': 'États-Unis',
209209
'zh-CN': '美国',
@@ -231,7 +231,7 @@ def test_names(self):
231231
'continent name is undef (no German available)')
232232
self.assertEqual(model.country.name, None,
233233
'country name is in None (no German available)')
234-
234+
235235

236236
if __name__ == '__main__':
237237
unittest.main()

tests/webservices_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python
2-
# -*- coding: utf-8 -*-
2+
# -*- coding: utf-8 -*-
33

44
import sys
55
sys.path.append('..')
@@ -34,13 +34,13 @@ def setUp(self):
3434
'continent': {
3535
'continent_code': 'NA',
3636
'geoname_id': 42,
37-
'name': { 'en': 'North America' }
37+
'names': { 'en': 'North America' }
3838
},
3939
'country': {
4040
'geoname_id': 1,
4141
'iso_3166_1_alpha_2': 'US',
4242
'iso_3166_1_alpha_3': 'USA',
43-
'name': { 'en': 'United States of America'}
43+
'names': { 'en': 'United States of America'}
4444
},
4545
'traits': {'ip_address': '1.2.3.4',},
4646
}
@@ -134,7 +134,7 @@ def test_no_body_error(self, get):
134134
with self.assertRaisesRegex(GeoIP2HTTPError,
135135
'Received a 400 error for .* with no body'):
136136
self.client.country('1.2.3.7')
137-
137+
138138
def test_weird_body_error(self, get):
139139
self._setup_get(get, status=400, body={ 'weird': 42 },)
140140
with self.assertRaisesRegex(GeoIP2HTTPError,

0 commit comments

Comments
 (0)