|
| 1 | +""" |
| 2 | +maxminddb.extension |
| 3 | +~~~~~~~~~~~~~~~~ |
| 4 | +
|
| 5 | +This module contains the C extension database reader and related classes. |
| 6 | +
|
| 7 | +""" |
| 8 | + |
1 | 9 | from ipaddress import IPv4Address, IPv6Address |
2 | 10 | from os import PathLike |
3 | | -from typing import Any, AnyStr, IO, Mapping, Optional, Sequence, Text, Tuple, Union |
4 | | - |
| 11 | +from typing import Any, AnyStr, Dict, IO, List, Optional, Tuple, Union |
5 | 12 | from maxminddb import MODE_AUTO |
6 | | -from maxminddb.errors import InvalidDatabaseError as InvalidDatabaseError |
7 | 13 | from maxminddb.types import Record |
8 | 14 |
|
9 | 15 | class Reader: |
| 16 | + """ |
| 17 | + A C extension implementation of a reader for the MaxMind DB format. IP |
| 18 | + addresses can be looked up using the ``get`` method. |
| 19 | + """ |
| 20 | + |
10 | 21 | closed: bool = ... |
| 22 | + |
11 | 23 | def __init__( |
12 | 24 | self, database: Union[AnyStr, int, PathLike, IO], mode: int = MODE_AUTO |
13 | | - ) -> None: ... |
14 | | - def close(self) -> None: ... |
15 | | - def get( |
16 | | - self, ip_address: Union[str, IPv6Address, IPv4Address] |
17 | | - ) -> Optional[Record]: ... |
| 25 | + ) -> None: |
| 26 | + """Reader for the MaxMind DB file format |
| 27 | +
|
| 28 | + Arguments: |
| 29 | + database -- A path to a valid MaxMind DB file such as a GeoIP2 database |
| 30 | + file, or a file descriptor in the case of MODE_FD. |
| 31 | + mode -- mode to open the database with. The only supported modes are |
| 32 | + MODE_AUTO and MODE_MMAP_EXT. |
| 33 | + """ |
| 34 | + |
| 35 | + def close(self) -> None: |
| 36 | + """Closes the MaxMind DB file and returns the resources to the system""" |
| 37 | + |
| 38 | + def get(self, ip_address: Union[str, IPv6Address, IPv4Address]) -> Optional[Record]: |
| 39 | + """Return the record for the ip_address in the MaxMind DB |
| 40 | +
|
| 41 | +
|
| 42 | + Arguments: |
| 43 | + ip_address -- an IP address in the standard string notation |
| 44 | + """ |
| 45 | + |
18 | 46 | def get_with_prefix_len( |
19 | 47 | self, ip_address: Union[str, IPv6Address, IPv4Address] |
20 | | - ) -> Tuple[Optional[Record], int]: ... |
21 | | - def metadata(self) -> "Metadata": ... |
| 48 | + ) -> Tuple[Optional[Record], int]: |
| 49 | + """Return a tuple with the record and the associated prefix length |
| 50 | +
|
| 51 | +
|
| 52 | + Arguments: |
| 53 | + ip_address -- an IP address in the standard string notation |
| 54 | + """ |
| 55 | + |
| 56 | + def metadata(self) -> "Metadata": |
| 57 | + """Return the metadata associated with the MaxMind DB file""" |
| 58 | + |
22 | 59 | def __enter__(self) -> "Reader": ... |
23 | 60 | def __exit__(self, *args) -> None: ... |
24 | 61 |
|
| 62 | +# pylint: disable=too-few-public-methods |
25 | 63 | class Metadata: |
26 | | - @property |
27 | | - def node_count(self) -> int: ... |
28 | | - @property |
29 | | - def record_size(self) -> int: ... |
30 | | - @property |
31 | | - def ip_version(self) -> int: ... |
32 | | - @property |
33 | | - def database_type(self) -> Text: ... |
34 | | - @property |
35 | | - def languages(self) -> Sequence[Text]: ... |
36 | | - @property |
37 | | - def binary_format_major_version(self) -> int: ... |
38 | | - @property |
39 | | - def binary_format_minor_version(self) -> int: ... |
40 | | - @property |
41 | | - def build_epoch(self) -> int: ... |
42 | | - @property |
43 | | - def description(self) -> Mapping[Text, Text]: ... |
44 | | - def __init__(self, **kwargs: Any) -> None: ... |
| 64 | + """Metadata for the MaxMind DB reader""" |
| 65 | + |
| 66 | + binary_format_major_version: int |
| 67 | + """ |
| 68 | + The major version number of the binary format used when creating the |
| 69 | + database. |
| 70 | + """ |
| 71 | + |
| 72 | + binary_format_minor_version: int |
| 73 | + """ |
| 74 | + The minor version number of the binary format used when creating the |
| 75 | + database. |
| 76 | + """ |
| 77 | + |
| 78 | + build_epoch: int |
| 79 | + """ |
| 80 | + The Unix epoch for the build time of the database. |
| 81 | + """ |
| 82 | + |
| 83 | + database_type: str |
| 84 | + """ |
| 85 | + A string identifying the database type, e.g., "GeoIP2-City". |
| 86 | + """ |
| 87 | + |
| 88 | + description: Dict[str, str] |
| 89 | + """ |
| 90 | + A map from locales to text descriptions of the database. |
| 91 | + """ |
| 92 | + |
| 93 | + ip_version: int |
| 94 | + """ |
| 95 | + The IP version of the data in a database. A value of "4" means the |
| 96 | + database only supports IPv4. A database with a value of "6" may support |
| 97 | + both IPv4 and IPv6 lookups. |
| 98 | + """ |
| 99 | + |
| 100 | + languages: List[str] |
| 101 | + """ |
| 102 | + A list of locale codes supported by the databse. |
| 103 | + """ |
| 104 | + |
| 105 | + node_count: int |
| 106 | + """ |
| 107 | + The number of nodes in the database. |
| 108 | + """ |
| 109 | + |
| 110 | + record_size: int |
| 111 | + """ |
| 112 | + The bit size of a record in the search tree. |
| 113 | + """ |
| 114 | + |
| 115 | + def __init__(self, **kwargs: Any) -> None: |
| 116 | + """Creates new Metadata object. kwargs are key/value pairs from spec""" |
0 commit comments