[Python-Dev] PEP 3144: IP Address Manipulation Library for the Python Standard Library
Nick Coghlan
ncoghlan at gmail.com
Sat Aug 22 01:08:05 CEST 2009
Peter Moody wrote:
this is a good idea and I'll implement this. .iterhosts() for subnet
> - (network|broadcast) and .iterallhosts() for the entire subnet (in my
> testing, looping over an iterator was actually reasonably faster than
> just for i in IP(network):, so I'll support iterators for both)
I would suggest just changing __iter__ to be the equivalent of the
current iterhosts() and then changing iterhosts() as described.
Such a change would would also fix the thread safety and nested
iteration problems problems suffered by the current __iter__
implementation. I haven't executed the following, but from reading the
code I am confident they would behave as a I describe in the comments:
# With the current implementation, this is an infinite loop
net = IPv4Network("192.168.2.0")
for x in net:
iter(net)
# And this only runs the inner loop once
for x in net:
for y in net:
pass
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
---------------------------------------------------------------
More information about the Python-Dev
mailing list