本文整理汇总了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
示例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), ">"])
示例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)
)
示例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
示例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)
示例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')
示例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))
示例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
示例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))
示例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.')
示例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)
示例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(""))
示例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(":"))
示例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"))
示例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"))