当前位置: 首页>>代码示例>>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;未经允许,请勿转载。