[Python-Dev] PEP 3144 review.
steve at pearwood.info
Thu Sep 17 20:26:41 CEST 2009
On Thu, 17 Sep 2009 05:15:16 pm Andrew McNamara wrote:
> Conceptually, you sometimes need a bare address, and other times,
> you need an address with an associated network (host interface
> configs, router configs, etc). By AddressWithMask, I really mean
> AddressWithEnoughInformationToDeriveNetworkWhenNeeded. Conveniently,
> IPv4 and IPv6 addressing allows us to derive the network from the
> host address combined with the netmask - in other words, we don't
> have to attach a real Network object to Address objects until the
> user tries to access it, and then we derive it from the address and
To clarify: when you say "derive the network" are you talking about the
network (which is a container) or the network address = host_address &
netmask (which is not a container)? I think you're referring to the
If there's need for address+netmask, does it need to be a separate
class? Perhaps Address objects could simply have a netmask property,
defaulting to None. If you need an "address with mask" object, you
create an Address and set the mask:
addr = Address(...)
addr.netmask = "255.255.255.0"
The caller is responsible for ensuring the netmask has been set before
trying to use it:
network_address = addr & addr.netmask
> If you have a .network attribute on an address object, checking if an
> address is in the same network as another address becomes:
> addr_a in addr_b.network
> As the module stands, you write that as:
> addr_a in addr_b
> I don't think the intent is as clear with the later.
I would find the later completely unclear and disturbing -- how can one
address contain another address?
More information about the Python-Dev