Skip to content

Commit 61d825d

Browse files
committed
Merge pull request #6 from bd808/features/ipv6
Support IPv6 addresses
2 parents 9a01106 + eff2144 commit 61d825d

20 files changed

Lines changed: 1816 additions & 1235 deletions

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
*.pyc
2+
.coverage
23
.venv
34
build
45
dist
56
extras
7+
iptools.egg-info
68
setuptools-*.egg
7-
src/iptools.egg-info

.travis.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
language: python
2-
32
python:
43
- "2.5"
54
- "2.6"
65
- "2.7"
76
- "3.2"
87
- "3.3"
98
- "pypy"
10-
11-
script: "./runtests"
12-
13-
# nothing to install, but this will squelch a warning
14-
install: "true"
15-
9+
install:
10+
- pip install . --use-mirrors
11+
- pip install -r tests/requirements.txt --use-mirrors
12+
script:
13+
- flake8 iptools
14+
- flake8 tests
15+
- nosetests
1616
notifications:
1717
email:
1818
- travis-ci+python-iptools@bd808.com

CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ Changes
33

44
0.6
55
---
6+
Support IPv6 addresses in IpRange and IpRangeList
7+
Utility functions for IPv6 addresses
68

79
0.5
810
---

MANIFEST.in

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
include README.md
21
include AUTHORS
2+
include CHANGES
3+
include ez_setup.py
34
include INSTALL
45
include LICENSE
5-
include CHANGES
66
include MANIFEST.in
7-
include ez_setup.py
7+
include README.md
8+
recursive-include docs Makefile *.rst *.py

docs/conf.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,28 @@
22

33
import sys
44
import os
5-
import datetime
5+
from datetime import date
66

7-
sys.path.append(os.path.abspath('../src'))
7+
sys.path.insert(0, os.path.abspath(os.path.join(os.getcwd(), '..')))
88
import iptools
99

1010
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.viewcode']
1111
templates_path = ['_templates']
1212
source_suffix = '.rst'
1313
master_doc = 'index'
14-
project = 'python-iptools'
15-
copyright = '%s, Bryan Davis. All Rights Reserved' % datetime.date.today().year
14+
project = 'iptools'
15+
copyright = '%s, Bryan Davis. All Rights Reserved' % date.today().year
1616
version = iptools.__version__
1717
release = version
1818
exclude_patterns = ['_build']
1919
pygments_style = 'sphinx'
2020

2121
on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
2222
if on_rtd:
23-
html_theme = 'default'
23+
html_theme = 'default'
2424
else:
25-
html_theme = 'nature'
25+
html_theme = 'nature'
2626
html_static_path = ['_static']
2727
htmlhelp_basename = 'iptoolsdoc'
2828

29+
autodoc_member_order = 'groupwise'

docs/index.rst

Lines changed: 111 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,126 @@
1-
.. python-iptools documentation master file, created by
2-
sphinx-quickstart on Thu May 24 18:28:05 2012.
3-
You can adapt this file completely to your liking, but it should at least
4-
contain the root `toctree` directive.
1+
##############################
2+
iptools - IP Address Utilities
3+
##############################
4+
The iptools_ package is a collection of utilities for dealing with IP
5+
addresses.
56

6-
iptools's documentation
7-
=======================
7+
The project was inspired by a desire to be able to use CIDR_ address notation
8+
to designate ``INTERNAL_IPS`` in a Django_ project's settings file.
89

9-
.. automodule:: iptools
10-
:members:
11-
:exclude-members: IpRange, IpRangeList
1210

11+
************
12+
Installation
13+
************
14+
Install the latest stable version from PyPi using pip_:
15+
16+
.. code-block:: bash
17+
18+
pip install iptools
19+
20+
or setuptools_:
21+
22+
.. code-block:: bash
23+
24+
easy_install iptools
25+
26+
Install the latest development version:
27+
28+
.. code-block:: bash
29+
30+
git clone https://github.com/bd808/python-iptools.git
31+
cd python-iptools
32+
python setup.py install
33+
34+
35+
******************************
36+
Using with Django INTERNAL_IPS
37+
******************************
38+
An :class:`iptools.IpRangeList` object can be used in a Django_ settings file
39+
to allow CIDR_ and/or ``(start, end)`` ranges to be used in the
40+
``INTERNAL_IPS`` list.
41+
42+
There are many internal and add-on components for Django_ that use the
43+
INTERNAL_IPS_ configuration setting to alter application behavior or make
44+
debugging easier. When you are developing and testing an application by
45+
yourself it's easy to add the ip address that your web browser will be coming
46+
from to this list. When you are developing in a group or testing from many ips
47+
it can become cumbersome to add more and more ip addresses to the setting
48+
individually.
49+
50+
The :class:`iptools.IpRangeList` object can help by replacing the standard
51+
tuple of addresses recommended by the Django docs with an intelligent object
52+
that responds to the membership test operator in. This object can be
53+
configured with dotted quad IP addresses like the default ``INTERNAL_IPS``
54+
tuple (eg. '127.0.0.1'), CIDR_ block notation (eg. '127/8', '192.168/16') for
55+
entire network blocks, and/or (start, end) tuples describing an arbitrary
56+
range of IP addresses.
57+
58+
Django_'s internal checks against the ``INTERNAL_IPS`` tuple take the form
59+
``if addr in INTERNAL_IPS`` or ``if addr not in INTERNAL_IPS``. This works
60+
transparently with the :class:`iptools.IpRangeList` object because it
61+
implements the magic method ``__contains__`` which python calls when the
62+
``in`` or ``not in`` operators are used.
63+
64+
.. code-block:: python
65+
66+
import iptools
67+
68+
INTERNAL_IPS = iptools.IpRangeList(
69+
'127.0.0.1', # single ip
70+
'192.168/16', # CIDR network block
71+
('10.0.0.1', '10.0.0.19'), # arbitrary inclusive range
72+
'::1', # single IPv6 address
73+
'fe80::/10', # IPv6 CIDR block
74+
)
75+
76+
77+
***
78+
API
79+
***
80+
81+
iptools
1382
=======
14-
IpRange
15-
=======
16-
.. autoclass:: IpRange
83+
.. automodule:: iptools
84+
85+
IpRangeList
86+
-----------
87+
.. autoclass:: iptools.IpRangeList
1788
:members:
1889
:special-members:
90+
:show-inheritance:
1991

20-
===========
21-
IpRangeList
22-
===========
23-
.. autoclass:: IpRangeList
92+
93+
IpRange
94+
-------
95+
.. autoclass:: iptools.IpRange
2496
:members:
2597
:special-members:
98+
:show-inheritance:
99+
26100

27-
=========
28-
Constants
29-
=========
30-
.. automodule:: iptools.constants
101+
IPv4
102+
====
103+
.. automodule:: iptools.ipv4
31104
:members:
105+
:show-inheritance:
106+
107+
108+
IPv6
109+
====
110+
.. automodule:: iptools.ipv6
111+
:members:
112+
:show-inheritance:
32113

33-
Indices and tables
34-
==================
35114

115+
******************
116+
Indices and tables
117+
******************
36118
* :ref:`genindex`
37119
* :ref:`search`
120+
121+
.. _iptools: http://pypi.python.org/pypi/iptools
122+
.. _Django: http://www.djangoproject.com/
123+
.. _pip: http://www.pip-installer.org/en/latest/
124+
.. _setuptools: https://pypi.python.org/pypi/setuptools
125+
.. _CIDR: http://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing
126+
.. _INTERNAL_IPS: http://docs.djangoproject.com/en/dev/ref/settings/#internal-ips

docs/requirements.txt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
Jinja2==2.6
2-
Pygments==1.6
3-
Sphinx==1.1.3
4-
docutils==0.10
5-
wsgiref==0.1.2
1+
sphinx

0 commit comments

Comments
 (0)