Skip to content

Commit 69d388c

Browse files
authored
Merge pull request #51 from maxmind/greg/network
Add support for getting the prefix length when looking up an IP
2 parents 17a155b + 3aac426 commit 69d388c

File tree

13 files changed

+415
-313
lines changed

13 files changed

+415
-313
lines changed

.clang-format

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
BasedOnStyle: LLVM
2+
IndentWidth: 4
3+
BinPackArguments: false
4+
BinPackParameters: false
5+
IndentCaseLabels: true

.uncrustify.cfg

Lines changed: 0 additions & 78 deletions
This file was deleted.

HISTORY.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ History
1414
``ipaddress.IPv6Address`` objects in addition to strings. This works with
1515
both the pure Python implementation as well as the extension. Based on a
1616
pull request #48 by Eric Pruitt. GitHub #50.
17+
* A new method, ``get_with_prefix_len`` was added. This method returns a
18+
tuple containing the record and the prefix length.
1719

1820
1.4.1 (2018-06-22)
1921
++++++++++++++++++

README.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ corresponding values for the IP address from the database (e.g., a dictionary
6262
for GeoIP2/GeoLite2 databases). If the database does not contain a record for
6363
that IP address, the method will return ``None``.
6464

65+
If you wish to also retrieve the prefix length for the record, use the
66+
``get_with_prefix_len`` method. This returns a tuple containing the record
67+
followed by the network prefix length associated with the record.
68+
6569
Example
6670
-------
6771

@@ -70,9 +74,13 @@ Example
7074
>>> import maxminddb
7175
>>>
7276
>>> reader = maxminddb.open_database('GeoLite2-City.mmdb')
77+
>>>
7378
>>> reader.get('1.1.1.1')
7479
{'country': ... }
7580
>>>
81+
>>> reader.get_with_prefix_len('1.1.1.1')
82+
({'country': ... }, 24)
83+
>>>
7684
>>> reader.close()
7785
7886
Exceptions

dev-bin/clang-format-all.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/sh
2+
3+
format="clang-format -i -style=file"
4+
5+
for dir in extension; do
6+
c_files=`find $dir -maxdepth 1 -name '*.c'`
7+
if [ "$c_files" != "" ]; then
8+
$format $dir/*.c;
9+
fi
10+
11+
h_files=`find $dir -maxdepth 1 -name '*.h'`
12+
if [ "$h_files" != "" ]; then
13+
$format $dir/*.h;
14+
fi
15+
done

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151

5252
# General information about the project.
5353
project = 'maxminddb'
54-
copyright = '2013-2018, MaxMind, Inc.'
54+
copyright = '2013-2019, MaxMind, Inc.'
5555

5656
# The version info for the project you're documenting, acts as replacement for
5757
# |version| and |release|, also used in various other places throughout the

docs/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@ Indices and tables
3535
* :ref:`modindex`
3636
* :ref:`search`
3737

38-
:copyright: (c) 2013-2018 by MaxMind, Inc.
38+
:copyright: (c) 2013-2019 by MaxMind, Inc.
3939
:license: Apache License, Version 2.0
4040

0 commit comments

Comments
 (0)