Skip to main content

Python 2.6 backport of 3.4's ipaddress module

Project description

This is a Python 2.6 backport of the Python 3.4 ipaddress module.

Please refer to the official Python 3.4 documentation for more information on the module.

Changes from Python 3.4’s ipaddress module

Since Python 2 has no distinct bytes type, bytearray is used instead for the “packed” address representation. Additionally, since Python 2.7’s functools does not have Python 3.2’s lru_cache, no caching is performed for the is_private and is_global properties; this should be a minor problem as Python 3.3’s ipaddress did not use lru_cache either. The backport should behave identical to 3.4 in all other respects.

Changes from py2-ipaddress 3.4

Python 2.6 support and a bugfix.

Changes from py2-ipaddress 2.0.1 and earlier

Since Python 2 does not distinguish between bytes and str like Python 3 does, version 2.0.1 and earlier of py2-ipaddress attempted to interpret str arguments as _both_ and do the “right” thing.

This unfortunately led to surprising behavior in py2-ipaddress:

>>> ipaddress.ip_address('test.example.org')
IPv6Address('7465:7374:2e65:7861:6d70:6c65:2e6f:7267')

The ipaddress module does not, of course, perform DNS resolution. Rather, the argument is interpreted as a byte string (of length 16) and converted bit-for-bit into an IPv6 address. In Python 3, ipaddress correctly rejects such a constructor argument (unless the b prefix is used to explicitly mark the literal as a byte string).

Even worse, there is not always a single right interpretation. Python 3 example:

>>> ipaddress.ip_address('::1234:5678:9abc')
IPv6Address('::1234:5678:9abc')
>>> ipaddress.ip_address(b'::1234:5678:9abc')
IPv6Address('3a3a:3132:3334:3a35:3637:383a:3961:6263')

There is no way to distinguish the two invocations in Python 2. As a result, py2-ipaddress 3.4 uses bytearray for all byte strings, and str for text strings only:

>>> ipaddress.ip_address('::1234:5678:9abc')
IPv6Address('::1234:5678:9abc')
>>> ipaddress.ip_address(b'::1234:5678:9abc')
IPv6Address('::1234:5678:9abc')
>>> ipaddress.ip_address(bytearray('::1234:5678:9abc'))
IPv6Address('3a3a:3132:3334:3a35:3637:383a:3961:6263')

License

The ipaddress modules (both the original and this backport) are licensed under the Python Software Foundation License version 2.

The modifications made for Python 2.6 compatibility are hereby released into the public domain by the authors.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py2-ipaddress-3.4.1.tar.gz (17.9 kB view details)

Uploaded Source

File details

Details for the file py2-ipaddress-3.4.1.tar.gz.

File metadata

  • Download URL: py2-ipaddress-3.4.1.tar.gz
  • Upload date:
  • Size: 17.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for py2-ipaddress-3.4.1.tar.gz
Algorithm Hash digest
SHA256 6d7bf02ac2590764691bf50ac213e966bc885ed37c02606513dcac484190564b
MD5 47734313c841068e3d5386d048d01c3d
BLAKE2b-256 06f2ff20f2d2fd4757be329c8ecb81e9e7fa3bec0b65445821e3a575410cf194

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page