diff options
author | smart+matt@google.com <smart+matt@google.com@09200d28-7f98-11dd-ad27-0f66e57d2035> | 2010-04-23 00:12:10 +0000 |
---|---|---|
committer | smart+matt@google.com <smart+matt@google.com@09200d28-7f98-11dd-ad27-0f66e57d2035> | 2010-04-23 00:12:10 +0000 |
commit | 2cad54cce7824d74188b532e7717410f10b182af (patch) | |
tree | ca6a2d7155538cb95834639d712782cbf6686fa9 /wiki | |
parent | f06bb73b681ec4db60310a85916d274a245ae181 (diff) | |
download | ipaddr-py-2cad54cce7824d74188b532e7717410f10b182af.tar.gz |
Edited wiki page through web user interface.
git-svn-id: https://ipaddr-py.googlecode.com/svn@160 09200d28-7f98-11dd-ad27-0f66e57d2035
Diffstat (limited to 'wiki')
-rw-r--r-- | wiki/UpgradingTo2x.wiki | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/wiki/UpgradingTo2x.wiki b/wiki/UpgradingTo2x.wiki index ab1de13..485d8d4 100644 --- a/wiki/UpgradingTo2x.wiki +++ b/wiki/UpgradingTo2x.wiki @@ -20,22 +20,38 @@ True Since Addresses and Networks are fundamentally different object types now, they're no longer comparable by default. {{{ ->>> address = ipaddr.IPv4Address('1.1.1.0') ->>> network = ipaddr.IPv4Network('1.1.1.0/24') +>>> address = ipaddr.IPv4Address('192.0.2.1') +>>> network = ipaddr.IPv4Network('192.0.2.0/24') >>> sorted([address, network]) Traceback (most recent call last): File "<stdin>", line 1, in <module> - File "/home/pmoody/src/ipaddr-py/trunk/ipaddr.py", line 440, in __lt__ + File "ipaddr.py", line 539, in __lt__ str(self), str(other))) -TypeError: 1.1.1.1 and 1.1.1.0/24 are not of the same type +TypeError: 192.0.2.0/24 and 192.0.2.1 are not of the same type }}} -However they can be sorted by using {{{ ipaddr.get_mixed_type_key() }}} key indexing function to sorted() +IPv4 and IPv6 objects are also no longer comparable by default: + +{{{ +>>> four = ipaddr.IPNetwork('192.0.2.0/24') +>>> six = ipaddr.IPNetwork('2001:db8::/32') +>>> sorted([four, six]) +Traceback (most recent call last): + File "<stdin>", line 1, in <module> + File "ipaddr.py", line 536, in __lt__ + str(self), str(other))) +TypeError: 2001:db8::/32 and 192.0.2.0/24 are not of the same version + +}}} + +However they can be sorted by using {{{ ipaddr.get_mixed_type_key() }}} key indexing function to sorted(). E.g., {{{ >>> sorted([address, network], key=ipaddr.get_mixed_type_key) -[IPv4Address('1.1.1.0'), IPv4Network('1.1.1.0/24')] +[IPv4Network('192.0.2.0/24'), IPv4Address('192.0.2.1')] +>>> sorted([four, six], key=ipaddr.get_mixed_type_key) +[IPv4Network('192.0.2.0/24'), IPv6Network('2001:db8::/32')] }}} === Classes === |