@@ -48,7 +48,7 @@ def __init__(
4848 database : Union [AnyStr , int , PathLike , IO ],
4949 mode : int = MODE_AUTO ,
5050 ) -> None :
51- """Reader for the MaxMind DB file format
51+ """Reader for the MaxMind DB file format.
5252
5353 Arguments:
5454 database -- A path to a valid MaxMind DB file such as a GeoIP2 database
@@ -132,11 +132,11 @@ def __init__(
132132 self ._ipv4_start = ipv4_start
133133
134134 def metadata (self ) -> "Metadata" :
135- """Return the metadata associated with the MaxMind DB file"""
135+ """Return the metadata associated with the MaxMind DB file. """
136136 return self ._metadata
137137
138138 def get (self , ip_address : Union [str , IPv6Address , IPv4Address ]) -> Optional [Record ]:
139- """Return the record for the ip_address in the MaxMind DB
139+ """Return the record for the ip_address in the MaxMind DB.
140140
141141 Arguments:
142142 ip_address -- an IP address in the standard string notation
@@ -149,7 +149,7 @@ def get_with_prefix_len(
149149 self ,
150150 ip_address : Union [str , IPv6Address , IPv4Address ],
151151 ) -> Tuple [Optional [Record ], int ]:
152- """Return a tuple with the record and the associated prefix length
152+ """Return a tuple with the record and the associated prefix length.
153153
154154 Arguments:
155155 ip_address -- an IP address in the standard string notation
@@ -245,20 +245,22 @@ def _read_node(self, node_number: int, index: int) -> int:
245245 offset = base_offset + index * 4
246246 node_bytes = self ._buffer [offset : offset + 4 ]
247247 else :
248- raise InvalidDatabaseError (f"Unknown record size: { record_size } " )
248+ msg = f"Unknown record size: { record_size } "
249+ raise InvalidDatabaseError (msg )
249250 return struct .unpack (b"!I" , node_bytes )[0 ]
250251
251252 def _resolve_data_pointer (self , pointer : int ) -> Record :
252253 resolved = pointer - self ._metadata .node_count + self ._metadata .search_tree_size
253254
254255 if resolved >= self ._buffer_size :
255- raise InvalidDatabaseError ("The MaxMind DB file's search tree is corrupt" )
256+ msg = "The MaxMind DB file's search tree is corrupt"
257+ raise InvalidDatabaseError (msg )
256258
257259 (data , _ ) = self ._decoder .decode (resolved )
258260 return data
259261
260262 def close (self ) -> None :
261- """Closes the MaxMind DB file and returns the resources to the system"""
263+ """Closes the MaxMind DB file and returns the resources to the system. """
262264 try :
263265 self ._buffer .close () # type: ignore
264266 except AttributeError :
@@ -270,13 +272,14 @@ def __exit__(self, *args) -> None:
270272
271273 def __enter__ (self ) -> "Reader" :
272274 if self .closed :
273- raise ValueError ("Attempt to reopen a closed MaxMind DB" )
275+ msg = "Attempt to reopen a closed MaxMind DB"
276+ raise ValueError (msg )
274277 return self
275278
276279
277280# pylint: disable=too-many-instance-attributes,R0801
278281class Metadata :
279- """Metadata for the MaxMind DB reader"""
282+ """Metadata for the MaxMind DB reader. """
280283
281284 binary_format_major_version : int
282285 """
@@ -328,7 +331,7 @@ class Metadata:
328331 """
329332
330333 def __init__ (self , ** kwargs ) -> None :
331- """Creates new Metadata object. kwargs are key/value pairs from spec"""
334+ """Creates new Metadata object. kwargs are key/value pairs from spec. """
332335 # Although I could just update __dict__, that is less obvious and it
333336 # doesn't work well with static analysis tools and some IDEs
334337 self .node_count = kwargs ["node_count" ]
@@ -343,20 +346,20 @@ def __init__(self, **kwargs) -> None:
343346
344347 @property
345348 def node_byte_size (self ) -> int :
346- """The size of a node in bytes
349+ """The size of a node in bytes.
347350
348351 :type: int
349352 """
350353 return self .record_size // 4
351354
352355 @property
353356 def search_tree_size (self ) -> int :
354- """The size of the search tree
357+ """The size of the search tree.
355358
356359 :type: int
357360 """
358361 return self .node_count * self .node_byte_size
359362
360- def __repr__ (self ):
363+ def __repr__ (self ) -> str :
361364 args = ", " .join (f"{ k } ={ v !r} " for k , v in self .__dict__ .items ())
362365 return f"{ self .__module__ } .{ self .__class__ .__name__ } ({ args } )"
0 commit comments