Skip to content

Commit ec3c20c

Browse files
committed
Run recent version of yapf against code
1 parent a916e73 commit ec3c20c

File tree

7 files changed

+154
-99
lines changed

7 files changed

+154
-99
lines changed

geoip2/compat.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
# pylint: skip-file
77

88
if sys.version_info[0] == 2:
9+
910
def compat_ip_address(address):
1011
"""Intended for internal use only."""
1112
if isinstance(address, bytes):
1213
address = address.decode()
1314
return ipaddress.ip_address(address)
1415
else:
16+
1517
def compat_ip_address(address):
1618
"""Intended for internal use only."""
1719
return ipaddress.ip_address(address)

geoip2/database.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ def _get(self, database_type, ip_address):
179179
if database_type not in self.metadata().database_type:
180180
caller = inspect.stack()[2][3]
181181
raise TypeError("The %s method cannot be used with the "
182-
"%s database" %
183-
(caller, self.metadata().database_type))
182+
"%s database" % (caller,
183+
self.metadata().database_type))
184184
record = self._db_reader.get(ip_address)
185185
if record is None:
186186
raise geoip2.errors.AddressNotFoundError(

geoip2/records.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,8 @@ def __init__(self, locales=None, **kwargs):
5050
def name(self):
5151
"""Dict with locale codes as keys and localized name as value."""
5252
# pylint:disable=E1101
53-
return next(
54-
(self.names.get(x) for x in self._locales
55-
if x in self.names), None)
53+
return next((self.names.get(x) for x in self._locales
54+
if x in self.names), None)
5655

5756

5857
class City(PlaceRecord):
@@ -243,8 +242,8 @@ class RepresentedCountry(Country):
243242
244243
"""
245244

246-
_valid_attributes = set(['confidence', 'geoname_id', 'iso_code', 'names',
247-
'type'])
245+
_valid_attributes = set(
246+
['confidence', 'geoname_id', 'iso_code', 'names', 'type'])
248247

249248

250249
class Location(Record):
@@ -314,9 +313,11 @@ class Location(Record):
314313
315314
"""
316315

317-
_valid_attributes = set(['average_income', 'accuracy_radius', 'latitude',
318-
'longitude', 'metro_code', 'population_density',
319-
'postal_code', 'postal_confidence', 'time_zone'])
316+
_valid_attributes = set([
317+
'average_income', 'accuracy_radius', 'latitude', 'longitude',
318+
'metro_code', 'population_density', 'postal_code', 'postal_confidence',
319+
'time_zone'
320+
])
320321

321322

322323
class MaxMind(Record):
@@ -594,14 +595,17 @@ class Traits(Record):
594595
595596
"""
596597

597-
_valid_attributes = set(
598-
['autonomous_system_number', 'autonomous_system_organization',
599-
'connection_type', 'domain', 'is_anonymous_proxy',
600-
'is_legitimate_proxy', 'is_satellite_provider', 'isp', 'ip_address',
601-
'organization', 'user_type'])
598+
_valid_attributes = set([
599+
'autonomous_system_number', 'autonomous_system_organization',
600+
'connection_type', 'domain', 'is_anonymous_proxy',
601+
'is_legitimate_proxy', 'is_satellite_provider', 'isp', 'ip_address',
602+
'organization', 'user_type'
603+
])
602604

603605
def __init__(self, **kwargs):
604-
for k in ['is_anonymous_proxy', 'is_legitimate_proxy',
605-
'is_satellite_provider']:
606+
for k in [
607+
'is_anonymous_proxy', 'is_legitimate_proxy',
608+
'is_satellite_provider'
609+
]:
606610
kwargs[k] = bool(kwargs.get(k, False))
607611
super(Traits, self).__init__(**kwargs)

geoip2/webservice.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,14 @@ def _response_for(self, path, model_class, ip_address):
141141
if ip_address != 'me':
142142
ip_address = str(compat_ip_address(ip_address))
143143
uri = '/'.join([self._base_uri, path, ip_address])
144-
response = requests.get(uri,
145-
auth=(self._user_id, self._license_key),
146-
headers={
147-
'Accept': 'application/json',
148-
'User-Agent': self._user_agent()
149-
},
150-
timeout=self._timeout)
144+
response = requests.get(
145+
uri,
146+
auth=(self._user_id, self._license_key),
147+
headers={
148+
'Accept': 'application/json',
149+
'User-Agent': self._user_agent()
150+
},
151+
timeout=self._timeout)
151152
if response.status_code == 200:
152153
body = self._handle_success(response, uri)
153154
return model_class(body, locales=self._locales)

tests/database_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626

2727
class BaseTestReader(object):
28-
2928
def test_language_list(self):
3029
reader = geoip2.database.Reader(
3130
'tests/data/test-data/GeoIP2-Country-Test.mmdb',
@@ -121,7 +120,8 @@ def test_connection_type(self):
121120
str(record), r'ConnectionType\(\{.*Cable/DSL.*\}\)',
122121
'ConnectionType str representation is reasonable')
123122

124-
self.assertEqual(record, eval(repr(record)),
123+
self.assertEqual(record,
124+
eval(repr(record)),
125125
"ConnectionType repr can be eval'd")
126126

127127
reader.close()
@@ -147,8 +147,8 @@ def test_domain(self):
147147
str(record), r'Domain\(\{.*maxmind.com.*\}\)',
148148
'Domain str representation is reasonable')
149149

150-
self.assertEqual(record, eval(repr(record)),
151-
"Domain repr can be eval'd")
150+
self.assertEqual(record,
151+
eval(repr(record)), "Domain repr can be eval'd")
152152

153153
reader.close()
154154

tests/models_test.py

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,24 @@ def test_insights_full(self):
2424
'city': {
2525
'confidence': 76,
2626
'geoname_id': 9876,
27-
'names': {'en': 'Minneapolis'},
27+
'names': {
28+
'en': 'Minneapolis'
29+
},
2830
},
2931
'continent': {
3032
'code': 'NA',
3133
'geoname_id': 42,
32-
'names': {'en': 'North America'},
34+
'names': {
35+
'en': 'North America'
36+
},
3337
},
3438
'country': {
3539
'confidence': 99,
3640
'geoname_id': 1,
3741
'iso_code': 'US',
38-
'names': {'en': 'United States of America'},
42+
'names': {
43+
'en': 'United States of America'
44+
},
3945
},
4046
'location': {
4147
'average_income': 24626,
@@ -54,21 +60,29 @@ def test_insights_full(self):
5460
'confidence': 88,
5561
'geoname_id': 574635,
5662
'iso_code': 'MN',
57-
'names': {'en': 'Minnesota'},
63+
'names': {
64+
'en': 'Minnesota'
65+
},
5866
}, {
5967
'geoname_id': 123,
6068
'iso_code': 'HP',
61-
'names': {'en': 'Hennepin'},
69+
'names': {
70+
'en': 'Hennepin'
71+
},
6272
}],
6373
'registered_country': {
6474
'geoname_id': 2,
6575
'iso_code': 'CA',
66-
'names': {'en': 'Canada'},
76+
'names': {
77+
'en': 'Canada'
78+
},
6779
},
6880
'represented_country': {
6981
'geoname_id': 3,
7082
'iso_code': 'GB',
71-
'names': {'en': 'United Kingdom'},
83+
'names': {
84+
'en': 'United Kingdom'
85+
},
7286
'type': 'military',
7387
},
7488
'traits': {
@@ -144,14 +158,15 @@ def test_insights_full(self):
144158
r'^geoip2.models.Insights\(\{.*geoname_id.*\}, \[.*en.*\]\)',
145159
'Insights str representation looks reasonable')
146160

147-
self.assertEqual(model, eval(repr(model)),
148-
"Insights repr can be eval'd")
161+
self.assertEqual(model,
162+
eval(repr(model)), "Insights repr can be eval'd")
149163

150164
self.assertRegex(
151165
str(model.location), r'^geoip2.records.Location\(.*longitude=.*\)',
152166
'Location str representation is reasonable')
153167

154-
self.assertEqual(model.location, eval(repr(model.location)),
168+
self.assertEqual(model.location,
169+
eval(repr(model.location)),
155170
"Location repr can be eval'd")
156171

157172
def test_insights_min(self):
@@ -189,17 +204,23 @@ def test_city_full(self):
189204
'continent': {
190205
'code': 'NA',
191206
'geoname_id': 42,
192-
'names': {'en': 'North America'},
207+
'names': {
208+
'en': 'North America'
209+
},
193210
},
194211
'country': {
195212
'geoname_id': 1,
196213
'iso_code': 'US',
197-
'names': {'en': 'United States of America'},
214+
'names': {
215+
'en': 'United States of America'
216+
},
198217
},
199218
'registered_country': {
200219
'geoname_id': 2,
201220
'iso_code': 'CA',
202-
'names': {'en': 'Canada'},
221+
'names': {
222+
'en': 'Canada'
223+
},
203224
},
204225
'traits': {
205226
'ip_address': '1.2.3.4',
@@ -266,9 +287,15 @@ def test_city_full(self):
266287
'__eq__ does not blow up on weird input')
267288

268289
def test_unknown_keys(self):
269-
model = geoip2.models.City({'traits': {'ip_address': '1.2.3.4',
270-
'invalid': 'blah'},
271-
'unk_base': {'blah': 1}})
290+
model = geoip2.models.City({
291+
'traits': {
292+
'ip_address': '1.2.3.4',
293+
'invalid': 'blah'
294+
},
295+
'unk_base': {
296+
'blah': 1
297+
}
298+
})
272299
with self.assertRaises(AttributeError):
273300
model.unk_base
274301
with self.assertRaises(AttributeError):

0 commit comments

Comments
 (0)