当前位置: 首页>>代码示例>>Python>>正文


Python abstract.isIPAddress方法代码示例

本文整理汇总了Python中twisted.internet.abstract.isIPAddress方法的典型用法代码示例。如果您正苦于以下问题:Python abstract.isIPAddress方法的具体用法?Python abstract.isIPAddress怎么用?Python abstract.isIPAddress使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在twisted.internet.abstract的用法示例。


在下文中一共展示了abstract.isIPAddress方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from twisted.internet import abstract [as 别名]
# 或者: from twisted.internet.abstract import isIPAddress [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

示例2: endpoint_from_hint_obj

# 需要导入模块: from twisted.internet import abstract [as 别名]
# 或者: from twisted.internet.abstract import isIPAddress [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

示例3: _setAddressFamily

# 需要导入模块: from twisted.internet import abstract [as 别名]
# 或者: from twisted.internet.abstract import isIPAddress [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

示例4: connect

# 需要导入模块: from twisted.internet import abstract [as 别名]
# 或者: from twisted.internet.abstract import isIPAddress [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

示例5: connect

# 需要导入模块: from twisted.internet import abstract [as 别名]
# 或者: from twisted.internet.abstract import isIPAddress [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

示例6: __init__

# 需要导入模块: from twisted.internet import abstract [as 别名]
# 或者: from twisted.internet.abstract import isIPAddress [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

示例7: resolve

# 需要导入模块: from twisted.internet import abstract [as 别名]
# 或者: from twisted.internet.abstract import isIPAddress [as 别名]
def resolve(self, name, timeout = (1, 3, 11, 45)):
        """Return a Deferred that will resolve a hostname.
        """
        if not name:
            # XXX - This is *less than* '::', and will screw up IPv6 servers
            return defer.succeed('0.0.0.0')
        if abstract.isIPAddress(name):
            return defer.succeed(name)
        return self.resolver.getHostByName(name, timeout)

    # Installation.

    # IReactorCore 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:15,代码来源:base.py

示例8: _aRecords

# 需要导入模块: from twisted.internet import abstract [as 别名]
# 或者: from twisted.internet.abstract import isIPAddress [as 别名]
def _aRecords(self, name):
        """
        Return a tuple of L{dns.RRHeader} instances for all of the IPv4
        addresses in the hosts file.
        """
        return tuple([
            dns.RRHeader(name, dns.A, dns.IN, self.ttl,
                         dns.Record_A(addr, self.ttl))
            for addr
            in searchFileForAll(FilePath(self.file), name)
            if isIPAddress(addr)]) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:13,代码来源:hosts.py

示例9: _aaaaRecords

# 需要导入模块: from twisted.internet import abstract [as 别名]
# 或者: from twisted.internet.abstract import isIPAddress [as 别名]
def _aaaaRecords(self, name):
        """
        Return a tuple of L{dns.RRHeader} instances for all of the IPv6
        addresses in the hosts file.
        """
        return tuple([
            dns.RRHeader(name, dns.AAAA, dns.IN, self.ttl,
                         dns.Record_AAAA(addr, self.ttl))
            for addr
            in searchFileForAll(FilePath(self.file), name)
            if not isIPAddress(addr)]) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:13,代码来源:hosts.py

示例10: test_shortDecimalDotted

# 需要导入模块: from twisted.internet import abstract [as 别名]
# 或者: from twisted.internet.abstract import isIPAddress [as 别名]
def test_shortDecimalDotted(self):
        """
        L{isIPAddress} should return C{False} for a dotted decimal
        representation with fewer or more than four octets.
        """
        self.assertFalse(isIPAddress('0'))
        self.assertFalse(isIPAddress('0.1'))
        self.assertFalse(isIPAddress('0.1.2'))
        self.assertFalse(isIPAddress('0.1.2.3.4')) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:11,代码来源:test_abstract.py

示例11: test_invalidLetters

# 需要导入模块: from twisted.internet import abstract [as 别名]
# 或者: from twisted.internet.abstract import isIPAddress [as 别名]
def test_invalidLetters(self):
        """
        L{isIPAddress} should return C{False} for any non-decimal dotted
        representation including letters.
        """
        self.assertFalse(isIPAddress('a.2.3.4'))
        self.assertFalse(isIPAddress('1.b.3.4')) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:9,代码来源:test_abstract.py

示例12: test_invalidPunctuation

# 需要导入模块: from twisted.internet import abstract [as 别名]
# 或者: from twisted.internet.abstract import isIPAddress [as 别名]
def test_invalidPunctuation(self):
        """
        L{isIPAddress} should return C{False} for a string containing
        strange punctuation.
        """
        self.assertFalse(isIPAddress(','))
        self.assertFalse(isIPAddress('1,2'))
        self.assertFalse(isIPAddress('1,2,3'))
        self.assertFalse(isIPAddress('1.,.3,4')) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:11,代码来源:test_abstract.py

示例13: test_emptyString

# 需要导入模块: from twisted.internet import abstract [as 别名]
# 或者: from twisted.internet.abstract import isIPAddress [as 别名]
def test_emptyString(self):
        """
        L{isIPAddress} should return C{False} for the empty string.
        """
        self.assertFalse(isIPAddress('')) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:7,代码来源:test_abstract.py

示例14: test_invalidNegative

# 需要导入模块: from twisted.internet import abstract [as 别名]
# 或者: from twisted.internet.abstract import isIPAddress [as 别名]
def test_invalidNegative(self):
        """
        L{isIPAddress} should return C{False} for negative decimal values.
        """
        self.assertFalse(isIPAddress('-1'))
        self.assertFalse(isIPAddress('1.-2'))
        self.assertFalse(isIPAddress('1.2.-3'))
        self.assertFalse(isIPAddress('1.2.-3.4')) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:10,代码来源:test_abstract.py

示例15: test_unicodeAndBytes

# 需要导入模块: from twisted.internet import abstract [as 别名]
# 或者: from twisted.internet.abstract import isIPAddress [as 别名]
def test_unicodeAndBytes(self):
        """
        L{isIPAddress} evaluates ASCII-encoded bytes as well as text.
        """
        self.assertFalse(isIPAddress(b'256.0.0.0'))
        self.assertFalse(isIPAddress(u'256.0.0.0'))
        self.assertTrue(isIPAddress(b'252.253.254.255'))
        self.assertTrue(isIPAddress(u'252.253.254.255')) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:10,代码来源:test_abstract.py


注:本文中的twisted.internet.abstract.isIPAddress方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。