Ticket #5086: fix-ipv6-literals-udp.2.patch

File fix-ipv6-literals-udp.2.patch, 2.7 KB (added by marto1_, 3 years ago)

Fixed patch, so all tests run, although twisted.scripts.test.test_tap2rpm fail sometimes.

  • twisted/internet/udp.py

     
    8080        self.interface = interface
    8181        self.setLogStr()
    8282        self._connectedAddr = None
     83        self.setAddressFamily()
    8384
    8485    def __repr__(self):
    8586        if self._realPortNumber is not None:
     
    207208        """
    208209        if self._connectedAddr:
    209210            raise RuntimeError("already connected, reconnecting is not currently supported")
    210         if not abstract.isIPAddress(host):
     211        if not abstract.isIPAddress(host) and not abstract.isIPv6Address(host):
    211212            raise ValueError("please pass only IP addresses, not domain names")
    212213        self._connectedAddr = (host, port)
    213214        self.socket.connect((host, port))
     
    252253        logPrefix = self._getLogPrefix(self.protocol)
    253254        self.logstr = "%s (UDP)" % logPrefix
    254255
     256    def setAddressFamily(self):
     257        """
     258        Resolve address family for the socket.
     259        """
     260        if abstract.isIPv6Address(self.interface):
     261            if not socket.has_ipv6:
     262                raise RuntimeError("IPV6 is not supported, "+\
     263                                       "compile with ipv6 support")
     264            self.addressFamily = socket.AF_INET6
     265        elif abstract.isIPAddress(self.interface):
     266            self.addressFamily = socket.AF_INET
     267       
    255268
     269
    256270    def logPrefix(self):
    257271        """
    258272        Return the prefix to log with.
     
    262276
    263277    def getHost(self):
    264278        """
    265         Returns an IPv4Address.
     279        Returns an IPv4Address or IPv6Address.
    266280
    267281        This indicates the address from which I am connecting.
    268282        """
    269         return address.IPv4Address('UDP', *self.socket.getsockname())
     283        if self.addressFamily == socket.AF_INET:
     284            return address.IPv4Address('UDP', *self.socket.getsockname())
     285        elif self.addressFamily == socket.AF_INET6:
     286            return address.IPv6Address('UDP', *self.socket.getsockname())
    270287
    271288
    272289
  • twisted/internet/address.py

     
    7777        IPv6 address; for example, "::1".
    7878    @type host: C{str}
    7979    """
     80    def __init__(self, type, host, port, flowinfo=0, scopeId=0, _bwHack=None):
     81        _IPAddress.__init__(self, type, host, port)
     82        if _bwHack is not None:
     83            warnings.warn("twisted.internet.address.IPv4Address._bwHack "
     84                          "is deprecated since Twisted 11.0",
     85                          DeprecationWarning, stacklevel=2)
    8086
    8187
    8288