I don't see any valid reason for entering a network as "192.168.1.1/24" rather than the canonical "192.168.1.0/24". The former might indicate a typing error or a mental slip, so let's be helpful and signal it to the user.
Or perhaps there can be an optional "strict=True" (or "strict=False") argument to the constructor / parsing function.
I can live w/ a default of strict=False. there are plenty of cases where it's not an error and easy enough ways to check, if the developer is concerned, with or without an option. eg if addr.ip != addr.network:
I agree - there are definitely times when it is not an error, but I don't like the idea of a "strict" flag. I've done a bit of everything - router configs with a national ISP, scripts to manage host configuration, user interfaces, you name it. The way I see it, we need: * Two address classes that describe a single IP end-point - "Address" with no mask and "AddressWithMask" (the later being the current Network class, minus the container-like behaviour). * A "Network" container-like class. Same as the current Network class, but addresses with masked bits would be considered an error. This is along the lines that RDM was suggesting, except that we remove the container behaviour from AddressWithMask. Additionally: * The .network attribute on an AddressWithMask would return a Network instance. * An Address class would not have a .network attribute * Network.__contains__() would accept Network, Address and AddressWithMask. Only Network implements __contains__ - an AddressWithMask can't contain another address, although it's .network can. * Maybe an Address should compare equal with an AddressWithMask if the address is identical and the mask is equivalent to /32? Personally, I don't see a strong use-case for the list-like indexing and iteration behaviour - I think it's enough to implement some basic container behaviour, but I won't object to the iterator and indexing, provided they don't distort the rest of the design (which I fear they are doing now). Iterating or indexing a network should return Address or AddressWithMask instances - if the later, the mask should match the parent network's mask. I'm not particularly wedded to the name "AddressWithMask" - maybe it could be NetworkAddress or MaskedAddress or ? -- Andrew McNamara, Senior Developer, Object Craft http://www.object-craft.com.au/