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