當前位置: 首頁>>代碼示例>>Python>>正文


Python abstract.isIPv6Address方法代碼示例

本文整理匯總了Python中twisted.internet.abstract.isIPv6Address方法的典型用法代碼示例。如果您正苦於以下問題:Python abstract.isIPv6Address方法的具體用法?Python abstract.isIPv6Address怎麽用?Python abstract.isIPv6Address使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在twisted.internet.abstract的用法示例。


在下文中一共展示了abstract.isIPv6Address方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _query

# 需要導入模塊: from twisted.internet import abstract [as 別名]
# 或者: from twisted.internet.abstract import isIPv6Address [as 別名]
def _query(self, *args):
        """
        Get a new L{DNSDatagramProtocol} instance from L{_connectedProtocol},
        issue a query to it using C{*args}, and arrange for it to be
        disconnected from its transport after the query completes.

        @param *args: Positional arguments to be passed to
            L{DNSDatagramProtocol.query}.

        @return: A L{Deferred} which will be called back with the result of the
            query.
        """
        if isIPv6Address(args[0][0]):
            protocol = self._connectedProtocol(interface='::')
        else:
            protocol = self._connectedProtocol()
        d = protocol.query(*args)
        def cbQueried(result):
            protocol.transport.stopListening()
            return result
        d.addBoth(cbQueried)
        return d 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:24,代碼來源:client.py

示例2: __repr__

# 需要導入模塊: from twisted.internet import abstract [as 別名]
# 或者: from twisted.internet.abstract import isIPv6Address [as 別名]
def __repr__(self):
        """
        Produce a string representation of the L{HostnameEndpoint}.

        @return: A L{str}
        """
        if self._badHostname:
            # Use the backslash-encoded version of the string passed to the
            # constructor, which is already a native string.
            host = self._hostStr
        elif isIPv6Address(self._hostStr):
            host = '[{}]'.format(self._hostStr)
        else:
            # Convert the bytes representation to a native string to ensure
            # that we display the punycoded version of the hostname, which is
            # more useful than any IDN version as it can be easily copy-pasted
            # into debugging tools.
            host = nativeString(self._hostBytes)
        return "".join(["<HostnameEndpoint ", host, ":", str(self._port), ">"]) 
開發者ID:wistbean,項目名稱:learn_python3_spider,代碼行數:21,代碼來源:endpoints.py

示例3: __init__

# 需要導入模塊: from twisted.internet import abstract [as 別名]
# 或者: from twisted.internet.abstract import isIPv6Address [as 別名]
def __init__(self, hostname, ctx):
        """
        Initialize L{ClientTLSOptions}.

        @param hostname: The hostname to verify as input by a human.
        @type hostname: L{unicode}

        @param ctx: an L{OpenSSL.SSL.Context} to use for new connections.
        @type ctx: L{OpenSSL.SSL.Context}.
        """
        self._ctx = ctx
        self._hostname = hostname

        if isIPAddress(hostname) or isIPv6Address(hostname):
            self._hostnameBytes = hostname.encode('ascii')
            self._hostnameIsDnsName = False
        else:
            self._hostnameBytes = _idnaBytes(hostname)
            self._hostnameIsDnsName = True

        self._hostnameASCII = self._hostnameBytes.decode("ascii")
        ctx.set_info_callback(
            _tolerateErrors(self._identityVerifyingInfoCallback)
        ) 
開發者ID:wistbean,項目名稱:learn_python3_spider,代碼行數:26,代碼來源:_sslverify.py

示例4: endpoint_from_hint_obj

# 需要導入模塊: from twisted.internet import abstract [as 別名]
# 或者: from twisted.internet.abstract import isIPv6Address [as 別名]
def endpoint_from_hint_obj(hint, tor, reactor):
    if tor:
        if isinstance(hint, (DirectTCPV1Hint, TorTCPV1Hint)):
            # this Tor object will throw ValueError for non-public IPv4
            # addresses and any IPv6 address
            try:
                return tor.stream_via(hint.hostname, hint.port)
            except ValueError:
                return None
        return None
    if isinstance(hint, DirectTCPV1Hint):
        # avoid DNS lookup unless necessary
        if isIPAddress(hint.hostname):
            return TCP4ClientEndpoint(reactor, hint.hostname, hint.port)
        if isIPv6Address(hint.hostname):
            return TCP6ClientEndpoint(reactor, hint.hostname, hint.port)
        return HostnameEndpoint(reactor, hint.hostname, hint.port)
    return None 
開發者ID:warner,項目名稱:magic-wormhole,代碼行數:20,代碼來源:_hints.py

示例5: _computeHostValue

# 需要導入模塊: from twisted.internet import abstract [as 別名]
# 或者: from twisted.internet.abstract import isIPv6Address [as 別名]
def _computeHostValue(self, scheme, host, port):
        """
        Compute the string to use for the value of the I{Host} header, based on
        the given scheme, host name, and port number.
        """
        if (isIPv6Address(nativeString(host))):
            host = b'[' + host + b']'
        if (scheme, port) in ((b'http', 80), (b'https', 443)):
            return host
        return host + b":" + intToBytes(port) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:12,代碼來源:client.py

示例6: _setAddressFamily

# 需要導入模塊: from twisted.internet import abstract [as 別名]
# 或者: from twisted.internet.abstract import isIPv6Address [as 別名]
def _setAddressFamily(self):
        """
        Resolve address family for the socket.
        """
        if isIPv6Address(self.interface):
            self.addressFamily = socket.AF_INET6
        elif isIPAddress(self.interface):
            self.addressFamily = socket.AF_INET
        elif self.interface:
            raise error.InvalidAddressError(
                self.interface, 'not an IPv4 or IPv6 address') 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:13,代碼來源:udp.py

示例7: connect

# 需要導入模塊: from twisted.internet import abstract [as 別名]
# 或者: from twisted.internet.abstract import isIPv6Address [as 別名]
def connect(self, host, port):
        """
        'Connect' to remote server.
        """
        if self._connectedAddr:
            raise RuntimeError(
                "already connected, reconnecting is not currently supported "
                "(talk to itamar if you want this)")
        if not isIPAddress(host) and not isIPv6Address(host):
            raise error.InvalidAddressError(
                host, 'not an IPv4 or IPv6 address.')
        self._connectedAddr = (host, port)
        self.socket.connect((host, port)) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:15,代碼來源:udp.py

示例8: __init__

# 需要導入模塊: from twisted.internet import abstract [as 別名]
# 或者: from twisted.internet.abstract import isIPv6Address [as 別名]
def __init__(self, port, factory, backlog=50, interface='', reactor=None):
        self.port = port
        self.factory = factory
        self.backlog = backlog
        self.interface = interface
        self.reactor = reactor
        if isIPv6Address(interface):
            self.addressFamily = socket.AF_INET6
            self._addressType = address.IPv6Address 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:11,代碼來源:tcp.py

示例9: connect

# 需要導入模塊: from twisted.internet import abstract [as 別名]
# 或者: from twisted.internet.abstract import isIPv6Address [as 別名]
def connect(self, host, port):
        """
        'Connect' to remote server.
        """
        if self._connectedAddr:
            raise RuntimeError("already connected, reconnecting is not currently supported")
        if not abstract.isIPAddress(host) and not abstract.isIPv6Address(host):
            raise error.InvalidAddressError(
                host, 'not an IPv4 or IPv6 address.')
        self._connectedAddr = (host, port)
        self.socket.connect((host, port)) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:13,代碼來源:udp.py

示例10: _setAddressFamily

# 需要導入模塊: from twisted.internet import abstract [as 別名]
# 或者: from twisted.internet.abstract import isIPv6Address [as 別名]
def _setAddressFamily(self):
        """
        Resolve address family for the socket.
        """
        if abstract.isIPv6Address(self.interface):
            self.addressFamily = socket.AF_INET6
        elif abstract.isIPAddress(self.interface):
            self.addressFamily = socket.AF_INET
        elif self.interface:
            raise error.InvalidAddressError(
                self.interface, 'not an IPv4 or IPv6 address.') 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:13,代碼來源:udp.py

示例11: __init__

# 需要導入模塊: from twisted.internet import abstract [as 別名]
# 或者: from twisted.internet.abstract import isIPv6Address [as 別名]
def __init__(self, host, port, bindAddress, connector, reactor=None):
        # BaseClient.__init__ is invoked later
        self.connector = connector
        self.addr = (host, port)

        whenDone = self.resolveAddress
        err = None
        skt = None

        if abstract.isIPAddress(host):
            self._requiresResolution = False
        elif abstract.isIPv6Address(host):
            self._requiresResolution = False
            self.addr = _resolveIPv6(host, port)
            self.addressFamily = socket.AF_INET6
            self._addressType = address.IPv6Address
        else:
            self._requiresResolution = True
        try:
            skt = self.createInternetSocket()
        except socket.error as se:
            err = error.ConnectBindError(se.args[0], se.args[1])
            whenDone = None
        if whenDone and bindAddress is not None:
            try:
                if abstract.isIPv6Address(bindAddress[0]):
                    bindinfo = _resolveIPv6(*bindAddress)
                else:
                    bindinfo = bindAddress
                skt.bind(bindinfo)
            except socket.error as se:
                err = error.ConnectBindError(se.args[0], se.args[1])
                whenDone = None
        self._finishInit(whenDone, skt, err, reactor) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:36,代碼來源:tcp.py

示例12: test_empty

# 需要導入模塊: from twisted.internet import abstract [as 別名]
# 或者: from twisted.internet.abstract import isIPv6Address [as 別名]
def test_empty(self):
        """
        The empty string is not an IPv6 address literal.
        """
        self.assertFalse(isIPv6Address("")) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:7,代碼來源:test_abstract.py

示例13: test_colon

# 需要導入模塊: from twisted.internet import abstract [as 別名]
# 或者: from twisted.internet.abstract import isIPv6Address [as 別名]
def test_colon(self):
        """
        A single C{":"} is not an IPv6 address literal.
        """
        self.assertFalse(isIPv6Address(":")) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:7,代碼來源:test_abstract.py

示例14: test_loopback

# 需要導入模塊: from twisted.internet import abstract [as 別名]
# 或者: from twisted.internet.abstract import isIPv6Address [as 別名]
def test_loopback(self):
        """
        C{"::1"} is the IPv6 loopback address literal.
        """
        self.assertTrue(isIPv6Address("::1")) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:7,代碼來源:test_abstract.py

示例15: test_scopeID

# 需要導入模塊: from twisted.internet import abstract [as 別名]
# 或者: from twisted.internet.abstract import isIPv6Address [as 別名]
def test_scopeID(self):
        """
        An otherwise valid IPv6 address literal may also include a C{"%"}
        followed by an arbitrary scope identifier.
        """
        self.assertTrue(isIPv6Address("fe80::1%eth0"))
        self.assertTrue(isIPv6Address("fe80::2%1"))
        self.assertTrue(isIPv6Address("fe80::3%en2")) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:10,代碼來源:test_abstract.py


注:本文中的twisted.internet.abstract.isIPv6Address方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。