1
+ """C extension database reader and related classes."""
2
+
1
3
from ipaddress import IPv4Address , IPv6Address
2
4
from os import PathLike
3
5
from typing import IO , Any , AnyStr
@@ -7,24 +9,60 @@ from typing_extensions import Self
7
9
from maxminddb .types import Record
8
10
9
11
class Reader :
12
+ """A C extension implementation of a reader for the MaxMind DB format.
13
+
14
+ IP addresses can be looked up using the ``get`` method.
15
+ """
16
+
10
17
closed : bool = ...
11
18
12
19
def __init__ (
13
20
self ,
14
21
database : AnyStr | int | PathLike | IO ,
15
22
mode : int = ...,
16
- ) -> None : ...
17
- def close (self ) -> None : ...
18
- def get (self , ip_address : str | IPv6Address | IPv4Address ) -> Record | None : ...
23
+ ) -> None :
24
+ """Reader for the MaxMind DB file format.
25
+
26
+ Arguments:
27
+ database: A path to a valid MaxMind DB file such as a GeoIP2 database
28
+ file, or a file descriptor in the case of MODE_FD.
29
+ mode: mode to open the database with. The only supported modes are
30
+ MODE_AUTO and MODE_MMAP_EXT.
31
+
32
+ """
33
+
34
+ def close (self ) -> None :
35
+ """Close the MaxMind DB file and returns the resources to the system."""
36
+
37
+ def get (self , ip_address : str | IPv6Address | IPv4Address ) -> Record | None :
38
+ """Return the record for the ip_address in the MaxMind DB.
39
+
40
+ Arguments:
41
+ ip_address: an IP address in the standard string notation
42
+
43
+ """
44
+
19
45
def get_with_prefix_len (
20
46
self ,
21
47
ip_address : str | IPv6Address | IPv4Address ,
22
- ) -> tuple [Record | None , int ]: ...
23
- def metadata (self ) -> Metadata : ...
48
+ ) -> tuple [Record | None , int ]:
49
+ """Return a tuple with the record and the associated prefix length.
50
+
51
+ Arguments:
52
+ ip_address: an IP address in the standard string notation
53
+
54
+ """
55
+
56
+ def metadata (self ) -> Metadata :
57
+ """Return the metadata associated with the MaxMind DB file."""
58
+
24
59
def __enter__ (self ) -> Self : ...
25
60
def __exit__ (self , * args ) -> None : ... # noqa: ANN002
26
61
62
+ # pylint: disable=too-few-public-methods
27
63
class Metadata :
64
+ """Metadata for the MaxMind DB reader."""
65
+
28
66
binary_format_major_version : int
29
67
"""
30
68
The major version number of the binary format used when creating the
@@ -74,4 +112,5 @@ class Metadata:
74
112
The bit size of a record in the search tree.
75
113
"""
76
114
77
- def __init__ (self , ** kwargs : Any ) -> None : ... # noqa: ANN401
115
+ def __init__ (self , ** kwargs : Any ) -> None : # noqa: ANN401
116
+ """Create new Metadata object. kwargs are key/value pairs from spec."""
0 commit comments