[Python-Dev] PEP 3144 review. (original) (raw)
Peter Moody peter at hda3.com
Wed Sep 16 02:05:46 CEST 2009
- Previous message: [Python-Dev] PEP 3144 review.
- Next message: [Python-Dev] PEP 3144 review.
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Tue, Sep 15, 2009 at 4:34 PM, Scott Dial <scott+python-dev at scottdial.com> wrote:
R. David Murray wrote:
On Tue, 15 Sep 2009 at 21:58, Antoine Pitrou wrote:
Le mardi 15 septembre 2009 à 15:48 -0400, R. David Murray a écrit :
However, I do not think that the proposed API should accept, eg, IPv4Network('192.168.1.1/24') as valid. That's just too confusing and error prone.
Indeed, it should throw some kind of ValueError instead. Peter, what do you think?
I disagree. It seems overly pedantic to throw a valueerror on this. IPy does (used to do?) this and it's one of the primary reasons I wrote ipaddr.
This change would have to be dependent on Antoine's suggestion of:
>>> addr, net = parseaddresswithmask('192.168.1.1/24') >>> addr == IPv4Address('192.168.1.1') True >>> net == IPv4Network('192.168.1.0/24') True Otherwise, I am ok with this change too. It resloves the weird duality of IPv4Network. And as RDM says, anyone who wants the IPv4AddressWithNetwork functionality can just role it themselves. At the moment of iteration, you have access to what network it is and can build your own IPv4AddressWithNetwork objects.
now, I understand that as the author, I have certain biases, but I'm not having the same difficulty with this duality as others. I really don't even see it as a duality.
It seems as though your issue could more easily be solved by having an iterator in BaseNet which returns a new network object with the original prefix length.
eg:
for addr in ipaddr.IPv4Network('1.1.1.0/24').iterwithnetmask():
1.1.1.0/24, 1.1.1.1/24, 1.1.1.2/24...
(or better yet, .iterwithprefix)
this can be done much more cleanly/easily than adding two new (redundant in my eyes) classes and much less pedantically than raising exceptions w/ IPv?Network() constructor received something other than base network address.
Is this sufficient? If not, perhaps someone could help me better understand the confusion over IPv?Network objects.
Cheers, /peter
net = IPv4Network('10.0.0.0/24') netaddrs = [] for addr in net: netaddrs.append(IPv4AddressWithNetwork(addr, net))
I guess I am ok with this. It seems sub-optimal (why not just return a IPv4AddressWithNetwork to begin with?) but I suppose it is no less efficient since the same objects would be constructed. -- Scott Dial scott at scottdial.com scodial at cs.indiana.edu
Python-Dev mailing list Python-Dev at python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/python-dev%40hda3.com
- Previous message: [Python-Dev] PEP 3144 review.
- Next message: [Python-Dev] PEP 3144 review.
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]