Closed GoogleCodeExporter closed 9 years ago
I'm not going to implement this, if for no other reason than because this leads
to
>>> ipaddr.IPNetwork('1.1.1.0/24', prefixlen=16)
which, no matter what is returned, is bound to confuse.
Original comment by pmo...@google.com
on 4 Jan 2011 at 4:51
What if it threw an exception if 2 netmasks were supplied? Or make the
prefixlen= parameter only apply if constructing from integer/packed bytes and
throw an exception if it's supplied when constructing from a string? The only
'in the box' workaround for constructing from integers to supply a netmask is
to do an initial conversion of the integer to an IPvXAddress, then convert that
to string, then concatenate the netmask, and construct a new IPvXNetwork
object, which is kind of wasteful.
Original comment by maddi...@lightbound.net
on 4 Jan 2011 at 2:33
Like I said, one way or the other, it's going to be confusing.
It sounds like what you need is an efficient way to turn an int into packed
bytes which you can then use with the socket interface to turn into a
string.
eg:
IPv4Network('1.1.1.1/24')
while using socket for this intermediate stage might seem like an
unnecessary step, it's far less confusing than dealing two possibly
conflicting prefixlen's in the constructor. And since everything between 0
and 4294967295 is both a valid v4 and v6 int, I think it makes most sense to
not guess which packed representation the user wants.
Would that do?
Original comment by pmo...@google.com
on 4 Jan 2011 at 4:42
I've put up a fix in r198
Original comment by pmo...@google.com
on 7 Jan 2011 at 5:23
Original issue reported on code.google.com by
maddi...@lightbound.net
on 3 Jan 2011 at 6:03