4848from geoip2 .models import City , Country , Insights
4949from geoip2 .types import IPAddress
5050
51- _AIOHTTP_UA = "GeoIP2-Python-Client/%s %s" % (
52- geoip2 .__version__ ,
53- aiohttp .http .SERVER_SOFTWARE ,
51+ _AIOHTTP_UA = (
52+ f"GeoIP2-Python-Client/{ geoip2 .__version__ } { aiohttp .http .SERVER_SOFTWARE } "
5453)
55- _REQUEST_UA = "GeoIP2-Python-Client/%s %s" % (
56- geoip2 . __version__ ,
57- requests .utils .default_user_agent (),
54+
55+ _REQUEST_UA = (
56+ f"GeoIP2-Python-Client/ { geoip2 . __version__ } { requests .utils .default_user_agent ()} "
5857)
5958
6059
@@ -85,7 +84,7 @@ def __init__(
8584 account_id if isinstance (account_id , bytes ) else str (account_id )
8685 )
8786 self ._license_key = license_key
88- self ._base_uri = "https://%s /geoip/v2.1" % host
87+ self ._base_uri = f "https://{ host } /geoip/v2.1"
8988 self ._timeout = timeout
9089
9190 def _uri (self , path : str , ip_address : IPAddress ) -> str :
@@ -99,9 +98,9 @@ def _handle_success(body: str, uri: str) -> Any:
9998 return json .loads (body )
10099 except ValueError as ex :
101100 raise GeoIP2Error (
102- "Received a 200 response for %( uri)s "
101+ f "Received a 200 response for { uri } "
103102 " but could not decode the response as "
104- "JSON: " % locals () + ", " .join (ex .args ),
103+ "JSON: " + ", " .join (ex .args ),
105104 200 ,
106105 uri ,
107106 ) from ex
@@ -120,15 +119,14 @@ def _exception_for_4xx_status(
120119 ) -> GeoIP2Error :
121120 if not body :
122121 return HTTPError (
123- "Received a %( status)i error for %( uri)s " " with no body." % locals () ,
122+ f "Received a { status } error for { uri } with no body." ,
124123 status ,
125124 uri ,
126125 body ,
127126 )
128127 if content_type .find ("json" ) == - 1 :
129128 return HTTPError (
130- "Received a %i for %s with the following "
131- "body: %s" % (status , uri , str (content_type )),
129+ f"Received a { status } for { uri } with the following body: { body } " ,
132130 status ,
133131 uri ,
134132 body ,
@@ -137,8 +135,9 @@ def _exception_for_4xx_status(
137135 decoded_body = json .loads (body )
138136 except ValueError as ex :
139137 return HTTPError (
140- "Received a %(status)i error for %(uri)s but it did"
141- " not include the expected JSON body: " % locals () + ", " .join (ex .args ),
138+ f"Received a { status } error for { uri } but it did not include "
139+ + "the expected JSON body: "
140+ + ", " .join (ex .args ),
142141 status ,
143142 uri ,
144143 body ,
@@ -149,7 +148,7 @@ def _exception_for_4xx_status(
149148 decoded_body .get ("error" ), decoded_body .get ("code" ), status , uri
150149 )
151150 return HTTPError (
152- "Response contains JSON but it does not specify " " code or error keys" ,
151+ "Response contains JSON but it does not specify code or error keys" ,
153152 status ,
154153 uri ,
155154 body ,
@@ -188,7 +187,7 @@ def _exception_for_5xx_status(
188187 status : int , uri : str , body : Optional [str ]
189188 ) -> HTTPError :
190189 return HTTPError (
191- "Received a server error (%( status)i) for " "%( uri)s" % locals () ,
190+ f "Received a server error ({ status } ) for { uri } " ,
192191 status ,
193192 uri ,
194193 body ,
@@ -199,8 +198,7 @@ def _exception_for_non_200_status(
199198 status : int , uri : str , body : Optional [str ]
200199 ) -> HTTPError :
201200 return HTTPError (
202- "Received a very surprising HTTP status "
203- "(%(status)i) for %(uri)s" % locals (),
201+ f"Received a very surprising HTTP status ({ status } ) for { uri } " ,
204202 status ,
205203 uri ,
206204 body ,
0 commit comments