Skip to content

Commit eecf1f7

Browse files
committed
Improve docs
1 parent 39a20e0 commit eecf1f7

File tree

6 files changed

+35
-32
lines changed

6 files changed

+35
-32
lines changed

examples/benchmark.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/python
2+
"""Basic benchmark for maxminddb."""
23

34
import argparse
45
import random
@@ -20,6 +21,7 @@
2021

2122

2223
def lookup_ip_address() -> None:
24+
"""Look up the IP."""
2325
ip = socket.inet_ntoa(struct.pack("!L", random.getrandbits(32)))
2426
reader.get(str(ip))
2527

@@ -29,4 +31,3 @@ def lookup_ip_address() -> None:
2931
setup="from __main__ import lookup_ip_address",
3032
number=args.count,
3133
)
32-

maxminddb/__init__.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,16 @@ def open_database(
4242
"""Open a MaxMind DB database.
4343
4444
Arguments:
45-
database -- A path to a valid MaxMind DB file such as a GeoIP2 database
46-
file, or a file descriptor in the case of MODE_FD.
47-
mode -- mode to open the database with. Valid mode are:
48-
* MODE_MMAP_EXT - use the C extension with memory map.
49-
* MODE_MMAP - read from memory map. Pure Python.
50-
* MODE_FILE - read database as standard file. Pure Python.
51-
* MODE_MEMORY - load database into memory. Pure Python.
52-
* MODE_FD - the param passed via database is a file descriptor, not
53-
a path. This mode implies MODE_MEMORY.
54-
* MODE_AUTO - tries MODE_MMAP_EXT, MODE_MMAP, MODE_FILE in that
45+
database: A path to a valid MaxMind DB file such as a GeoIP2 database
46+
file, or a file descriptor in the case of MODE_FD.
47+
mode: mode to open the database with. Valid mode are:
48+
* MODE_MMAP_EXT - use the C extension with memory map.
49+
* MODE_MMAP - read from memory map. Pure Python.
50+
* MODE_FILE - read database as standard file. Pure Python.
51+
* MODE_MEMORY - load database into memory. Pure Python.
52+
* MODE_FD - the param passed via database is a file descriptor, not
53+
a path. This mode implies MODE_MEMORY.
54+
* MODE_AUTO - tries MODE_MMAP_EXT, MODE_MMAP, MODE_FILE in that
5555
order. Default mode.
5656
5757
"""

maxminddb/decoder.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ def __init__(
2525
pointer_base: int = 0,
2626
pointer_test: bool = False,
2727
) -> None:
28-
"""Created a Decoder for a MaxMind DB.
28+
"""Create a Decoder for a MaxMind DB.
2929
3030
Arguments:
31-
database_buffer -- an mmap'd MaxMind DB file.
32-
pointer_base -- the base number to use when decoding a pointer
33-
pointer_test -- used for internal unit testing of pointer code
31+
database_buffer: an mmap'd MaxMind DB file.
32+
pointer_base: the base number to use when decoding a pointer
33+
pointer_test: used for internal unit testing of pointer code
3434
3535
"""
3636
self._pointer_test = pointer_test
@@ -136,7 +136,7 @@ def decode(self, offset: int) -> tuple[Record, int]:
136136
"""Decode a section of the data section starting at offset.
137137
138138
Arguments:
139-
offset -- the location of the data structure to decode
139+
offset: the location of the data structure to decode
140140
141141
"""
142142
new_offset = offset + 1

maxminddb/extension.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class Metadata:
7979

8080
languages: list[str]
8181
"""
82-
A list of locale codes supported by the databse.
82+
A list of locale codes supported by the database.
8383
"""
8484

8585
node_count: int

maxminddb/file.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class FileBuffer:
1616
"""A slice-able file reader."""
1717

1818
def __init__(self, database: str) -> None:
19+
"""Create FileBuffer."""
1920
# pylint: disable=consider-using-with
2021
self._handle = open(database, "rb")
2122
self._size = os.fstat(self._handle.fileno()).st_size

maxminddb/reader.py

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@
2323

2424

2525
class Reader:
26-
"""A pure Python implementation of a reader for the MaxMind DB format. IP
27-
addresses can be looked up using the ``get`` method.
26+
"""A pure Python implementation of a reader for the MaxMind DB format.
27+
28+
IP addresses can be looked up using the ``get`` method.
2829
"""
2930

3031
_DATA_SECTION_SEPARATOR_SIZE = 16
@@ -45,15 +46,15 @@ def __init__(
4546
"""Reader for the MaxMind DB file format.
4647
4748
Arguments:
48-
database -- A path to a valid MaxMind DB file such as a GeoIP2 database
49-
file, or a file descriptor in the case of MODE_FD.
50-
mode -- mode to open the database with. Valid mode are:
51-
* MODE_MMAP - read from memory map.
52-
* MODE_FILE - read database as standard file.
53-
* MODE_MEMORY - load database into memory.
54-
* MODE_AUTO - tries MODE_MMAP and then MODE_FILE. Default.
55-
* MODE_FD - the param passed via database is a file descriptor, not
56-
a path. This mode implies MODE_MEMORY.
49+
database: A path to a valid MaxMind DB file such as a GeoIP2 database
50+
file, or a file descriptor in the case of MODE_FD.
51+
mode: mode to open the database with. Valid mode are:
52+
* MODE_MMAP - read from memory map.
53+
* MODE_FILE - read database as standard file.
54+
* MODE_MEMORY - load database into memory.
55+
* MODE_AUTO - tries MODE_MMAP and then MODE_FILE. Default.
56+
* MODE_FD - the param passed via database is a file descriptor, not
57+
a path. This mode implies MODE_MEMORY.
5758
5859
"""
5960
filename: Any
@@ -140,7 +141,7 @@ def get(self, ip_address: Union[str, IPv6Address, IPv4Address]) -> Optional[Reco
140141
"""Return the record for the ip_address in the MaxMind DB.
141142
142143
Arguments:
143-
ip_address -- an IP address in the standard string notation
144+
ip_address: an IP address in the standard string notation
144145
145146
"""
146147
(record, _) = self.get_with_prefix_len(ip_address)
@@ -153,7 +154,7 @@ def get_with_prefix_len(
153154
"""Return a tuple with the record and the associated prefix length.
154155
155156
Arguments:
156-
ip_address -- an IP address in the standard string notation
157+
ip_address: an IP address in the standard string notation
157158
158159
"""
159160
if isinstance(ip_address, str):
@@ -326,7 +327,7 @@ class Metadata:
326327

327328
languages: list[str]
328329
"""
329-
A list of locale codes supported by the databse.
330+
A list of locale codes supported by the database.
330331
"""
331332

332333
node_count: int
@@ -340,7 +341,7 @@ class Metadata:
340341
"""
341342

342343
def __init__(self, **kwargs) -> None:
343-
"""Creates new Metadata object. kwargs are key/value pairs from spec."""
344+
"""Create new Metadata object. kwargs are key/value pairs from spec."""
344345
# Although I could just update __dict__, that is less obvious and it
345346
# doesn't work well with static analysis tools and some IDEs
346347
self.node_count = kwargs["node_count"]

0 commit comments

Comments
 (0)