Skip to content

Commit a0a8857

Browse files
committed
Tidy with a recent yapf
1 parent 5fb855b commit a0a8857

File tree

5 files changed

+47
-41
lines changed

5 files changed

+47
-41
lines changed

geoip2/database.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,9 @@ def isp(self, ip_address):
182182
def _get(self, database_type, ip_address):
183183
if database_type not in self.metadata().database_type:
184184
caller = inspect.stack()[2][3]
185-
raise TypeError("The %s method cannot be used with the "
186-
"%s database" % (caller,
187-
self.metadata().database_type))
185+
raise TypeError(
186+
"The %s method cannot be used with the "
187+
"%s database" % (caller, self.metadata().database_type))
188188
record = self._db_reader.get(ip_address)
189189
if record is None:
190190
raise geoip2.errors.AddressNotFoundError(

geoip2/webservice.py

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,10 @@ def _handle_success(self, response, uri):
176176
try:
177177
return response.json()
178178
except ValueError as ex:
179-
raise GeoIP2Error('Received a 200 response for %(uri)s'
180-
' but could not decode the response as '
181-
'JSON: ' % locals() + ', '.join(ex.args), 200,
182-
uri)
179+
raise GeoIP2Error(
180+
'Received a 200 response for %(uri)s'
181+
' but could not decode the response as '
182+
'JSON: ' % locals() + ', '.join(ex.args), 200, uri)
183183

184184
def _exception_for_error(self, response, uri):
185185
status = response.status_code
@@ -192,25 +192,27 @@ def _exception_for_error(self, response, uri):
192192

193193
def _exception_for_4xx_status(self, response, status, uri):
194194
if not response.content:
195-
return HTTPError('Received a %(status)i error for %(uri)s '
196-
'with no body.' % locals(), status, uri)
195+
return HTTPError(
196+
'Received a %(status)i error for %(uri)s '
197+
'with no body.' % locals(), status, uri)
197198
elif response.headers['Content-Type'].find('json') == -1:
198-
return HTTPError('Received a %i for %s with the following '
199-
'body: %s' % (status, uri, response.content),
200-
status, uri)
199+
return HTTPError(
200+
'Received a %i for %s with the following '
201+
'body: %s' % (status, uri, response.content), status, uri)
201202
try:
202203
body = response.json()
203204
except ValueError as ex:
204205
return HTTPError(
205206
'Received a %(status)i error for %(uri)s but it did'
206-
' not include the expected JSON body: ' % locals() +
207-
', '.join(ex.args), status, uri)
207+
' not include the expected JSON body: ' % locals() + ', '.join(
208+
ex.args), status, uri)
208209
else:
209210
if 'code' in body and 'error' in body:
210211
return self._exception_for_web_service_error(
211212
body.get('error'), body.get('code'), status, uri)
212-
return HTTPError('Response contains JSON but it does not specify '
213-
'code or error keys', status, uri)
213+
return HTTPError(
214+
'Response contains JSON but it does not specify '
215+
'code or error keys', status, uri)
214216

215217
def _exception_for_web_service_error(self, message, code, status, uri):
216218
if code in ('IP_ADDRESS_NOT_FOUND', 'IP_ADDRESS_RESERVED'):
@@ -227,9 +229,11 @@ def _exception_for_web_service_error(self, message, code, status, uri):
227229
return InvalidRequestError(message, code, status, uri)
228230

229231
def _exception_for_5xx_status(self, status, uri):
230-
return HTTPError('Received a server error (%(status)i) for '
231-
'%(uri)s' % locals(), status, uri)
232+
return HTTPError(
233+
'Received a server error (%(status)i) for '
234+
'%(uri)s' % locals(), status, uri)
232235

233236
def _exception_for_non_200_status(self, status, uri):
234-
return HTTPError('Received a very surprising HTTP status '
235-
'(%(status)i) for %(uri)s' % locals(), status, uri)
237+
return HTTPError(
238+
'Received a very surprising HTTP status '
239+
'(%(status)i) for %(uri)s' % locals(), status, uri)

tests/database_test.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,27 +37,28 @@ def test_language_list(self):
3737
def test_unknown_address(self):
3838
reader = geoip2.database.Reader(
3939
'tests/data/test-data/GeoIP2-City-Test.mmdb')
40-
with self.assertRaisesRegex(geoip2.errors.AddressNotFoundError,
41-
'The address 10.10.10.10 is not in the '
42-
'database.'):
40+
with self.assertRaisesRegex(
41+
geoip2.errors.AddressNotFoundError,
42+
'The address 10.10.10.10 is not in the '
43+
'database.'):
4344
reader.city('10.10.10.10')
4445
reader.close()
4546

4647
def test_wrong_database(self):
4748
reader = geoip2.database.Reader(
4849
'tests/data/test-data/GeoIP2-City-Test.mmdb')
49-
with self.assertRaisesRegex(TypeError,
50-
'The country method cannot be used with '
51-
'the GeoIP2-City database'):
50+
with self.assertRaisesRegex(
51+
TypeError, 'The country method cannot be used with '
52+
'the GeoIP2-City database'):
5253
reader.country('1.1.1.1')
5354
reader.close()
5455

5556
def test_invalid_address(self):
5657
reader = geoip2.database.Reader(
5758
'tests/data/test-data/GeoIP2-City-Test.mmdb')
58-
with self.assertRaisesRegex(ValueError,
59-
"u?'invalid' does not appear to be an "
60-
"IPv4 or IPv6 address"):
59+
with self.assertRaisesRegex(
60+
ValueError, "u?'invalid' does not appear to be an "
61+
"IPv4 or IPv6 address"):
6162
reader.city('invalid')
6263
reader.close()
6364

tests/models_test.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -366,9 +366,10 @@ def test_three_locales(self):
366366

367367
def test_two_locales(self):
368368
model = geoip2.models.Country(self.raw, locales=['ak', 'fr'])
369-
self.assertEqual(model.continent.name, None,
370-
'continent name is undef (no Akan or French '
371-
'available)')
369+
self.assertEqual(
370+
model.continent.name, None,
371+
'continent name is undef (no Akan or French '
372+
'available)')
372373
self.assertEqual(model.country.name, 'États-Unis',
373374
'country name is in French')
374375

tests/webservice_test.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ def test_200_error(self, mock):
120120
self.client.country('1.1.1.1')
121121

122122
def test_bad_ip_address(self):
123-
with self.assertRaisesRegex(ValueError,
124-
"'1.2.3' does not appear to be an IPv4 "
125-
"or IPv6 address"):
123+
with self.assertRaisesRegex(
124+
ValueError, "'1.2.3' does not appear to be an IPv4 "
125+
"or IPv6 address"):
126126
self.client.country('1.2.3')
127127

128128
@requests_mock.mock()
@@ -143,9 +143,9 @@ def test_weird_body_error(self, mock):
143143
text='{"wierd": 42}',
144144
status_code=400,
145145
headers={'Content-Type': self._content_type('country')})
146-
with self.assertRaisesRegex(HTTPError,
147-
'Response contains JSON but it does not '
148-
'specify code or error keys'):
146+
with self.assertRaisesRegex(
147+
HTTPError, 'Response contains JSON but it does not '
148+
'specify code or error keys'):
149149
self.client.country('1.2.3.8')
150150

151151
@requests_mock.mock()
@@ -172,9 +172,9 @@ def test_300_error(self, mock):
172172
self.base_uri + 'country/' + '1.2.3.11',
173173
status_code=300,
174174
headers={'Content-Type': self._content_type('country')})
175-
with self.assertRaisesRegex(HTTPError,
176-
'Received a very surprising HTTP status '
177-
'\(300\) for'):
175+
with self.assertRaisesRegex(
176+
HTTPError, 'Received a very surprising HTTP status '
177+
'\(300\) for'):
178178

179179
self.client.country('1.2.3.11')
180180

0 commit comments

Comments
 (0)