Skip to content

Commit

Permalink
Fix an error in README and improve the examples
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Thayer committed Sep 21, 2013
1 parent 0215671 commit 5d9af31
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions README
Expand Up @@ -39,23 +39,19 @@ A simple example which associates CIDR prefixes with strings::
>>> t = SubnetTree.SubnetTree()
>>> t["10.1.0.0/16"] = "Network 1"
>>> t["10.1.42.0/24"] = "Network 1, Subnet 42"
>>> t["10.2.0.0/16"] = "Network 2"
>>> print "10.1.42.1" in t
True
>>> print t["10.1.42.1"]
Network 1, Subnet 42
>>> print t["10.1.43.1"]
Network 1
>>> print "10.1.42.1" in t
True
>>> print "10.1.43.1" in t
True
>>> print "10.20.1.1" in t
False
>>> print t["10.20.1.1"]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "SubnetTree.py", line 67, in __getitem__
def __getitem__(*args): return _SubnetTree.SubnetTree___getitem__(*args)
KeyError: '10.20.1.1'
>>> try:
... print t["10.20.1.1"]
... except KeyError, err:
... print "Error: %s not found" % err
Error: '10.20.1.1' not found

By default, CIDR prefixes and IP addresses are given as strings.
Alternatively, a ``SubnetTree`` object can be switched into *binary
Expand All @@ -67,7 +63,7 @@ binary strings as, e.g., returned by `socket.inet_aton
>>> t.get_binary_lookup_mode()
False
>>> t.set_binary_lookup_mode(True)
>>> t.binary_lookup_mode()
>>> t.get_binary_lookup_mode()
True
>>> import socket
>>> print t[socket.inet_aton("10.1.42.1")]
Expand Down

0 comments on commit 5d9af31

Please sign in to comment.