On Tue, Jun 2, 2009 at 9:26 AM, Clay McClure <clay at daemons.net> wrote: > On Tue, Jun 2, 2009 at 2:08 AM, "Martin v. Löwis" <martin at v.loewis.de> wrote: > >>> That doesn't solve much. IPv4 objects still always use CIDR notation >>> when coerced to strings, meaning that IP addresses will always be >>> rendered with a trailing "/32". >> >> That's not true: >> >> py> x = ipaddr.IP("30.40.50.60") >> py> print(x.ip_ext_full) >> 30.40.50.60 > > Thankfully the authors have provided this obscure and strangely-named > method to get at the correct string representation of an IP address, > but sadly their __str__ method -- which is the Pythonic way to get > string representations of objects -- fails in this regard because they > have only one class representing two distinct concepts. The minimal demonstration of the problem of representing networks and addresses using the same class: >>> container = [1, 2, 3, 4] >>> for item in container: ... print "%s in %s: %s" % (item, container, item in container) ... 1 in [1, 2, 3, 4]: True 2 in [1, 2, 3, 4]: True 3 in [1, 2, 3, 4]: True 4 in [1, 2, 3, 4]: True >>> import ipaddr >>> container = ipaddr.IP('192.168.1.0/24') >>> for item in container: ... print "%s in %s: %s" % (item, container, item in container) ... Traceback (most recent call last): File "<stdin>", line 2, in <module> File "ipaddr.py", line 438, in __contains__ return self.network <= other.ip and self.broadcast >= other.broadcast AttributeError: 'str' object has no attribute 'ip' >>> -jake
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4