Nick Coghlan added the comment:

The Interface classes are actually designed to cover any association of an IP 
address with a specific network, not just host interface addresses. We knew it 
was a slight misnomer when we chose it, but network and broadcast addresses 
weren't considered special enough to be worth separating out (beyond the 
distinction present in iterating over the whole network range vs just the host 
addresses).

It's relatively straightforward to write a helper function that only allows the 
creation of host interfaces:

    def host_interface(address):
        ifaddr = ip_interface(address)
        if ifaddr.ip == ifaddr.network.network_address:
            raise ValueError("'{}' is a network address".format(ifaddr)
        if ifaddr.ip == ifaddr.network.broadcast_address:
            raise ValueError("'{}' is a broadcast address".format(ifaddr)
        return ifaddr

I'm not sure if it's worthwhile to add such a helper function to the module 
itself.

One argument in favour of adding it is that it may help to emphasise that the 
normal ip_interface factory function and the *Interface class constructors are 
*not* restricted purely to host interfaces, and thus allow network and 
broadcast addresses to be associated with their corresponding network 
definition.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue22876>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to