本文整理汇总了Python中twisted.internet.error.DNSLookupError方法的典型用法代码示例。如果您正苦于以下问题:Python error.DNSLookupError方法的具体用法?Python error.DNSLookupError怎么用?Python error.DNSLookupError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.internet.error
的用法示例。
在下文中一共展示了error.DNSLookupError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: errback_httpbin
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import DNSLookupError [as 别名]
def errback_httpbin(self, failure):
# log all failures
self.logger.error(repr(failure))
# in case you want to do something special for some errors,
# you may need the failure's type:
if failure.check(HttpError):
# these exceptions come from HttpError spider middleware
# you can get the non-200 response
response = failure.value.response
self.logger.error('HttpError on %s', response.url)
elif failure.check(DNSLookupError):
# this is the original request
request = failure.request
self.logger.error('DNSLookupError on %s', request.url)
elif failure.check(TimeoutError, TCPTimedOutError):
request = failure.request
self.logger.error('TimeoutError on %s', request.url)
示例2: test_failure
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import DNSLookupError [as 别名]
def test_failure(self):
"""
L{SimpleResolverComplexifier} translates a known error result from
L{IResolverSimple.resolveHostName} into an empty result.
"""
simple = SillyResolverSimple()
complex = SimpleResolverComplexifier(simple)
receiver = ResultHolder(self)
self.assertEqual(receiver._started, False)
complex.resolveHostName(receiver, u"example.com")
self.assertEqual(receiver._started, True)
self.assertEqual(receiver._ended, False)
self.assertEqual(receiver._addresses, [])
simple._requests[0].errback(DNSLookupError("nope"))
self.assertEqual(receiver._ended, True)
self.assertEqual(receiver._addresses, [])
示例3: _cbGotServers
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import DNSLookupError [as 别名]
def _cbGotServers(self, result):
answers, auth, add = result
if len(answers) == 1 and answers[0].type == dns.SRV \
and answers[0].payload \
and answers[0].payload.target == dns.Name(b'.'):
# decidedly not available
raise error.DNSLookupError("Service %s not available for domain %s."
% (repr(self.service), repr(self.domain)))
self.servers = []
self.orderedServers = []
for a in answers:
if a.type != dns.SRV or not a.payload:
continue
self.orderedServers.append(a.payload)
示例4: test_errorsLogged
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import DNSLookupError [as 别名]
def test_errorsLogged(self):
"""
Hostname resolution errors are logged.
"""
mreactor = MemoryReactor()
clientFactory = object()
ep, ignoredArgs, ignoredDest = self.createClientEndpoint(
mreactor, clientFactory)
def getaddrinfoThatFails(*args, **kwargs):
raise gaierror(-5, 'No address associated with hostname')
ep._getaddrinfo = getaddrinfoThatFails
d = ep.connect(clientFactory)
self.assertIsInstance(self.failureResultOf(d).value,
error.DNSLookupError)
self.assertEqual(1, len(self.flushLoggedErrors(gaierror)))
示例5: connect
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import DNSLookupError [as 别名]
def connect(self):
"""Start connection to remote server."""
self.factory.doStart()
self.factory.startedConnecting(self)
if not self.servers:
if self.domain is None:
self.connectionFailed(error.DNSLookupError("Domain is not defined."))
return
d = client.lookupService('_%s._%s.%s' %
(nativeString(self.service),
nativeString(self.protocol),
self.domain))
d.addCallbacks(self._cbGotServers, self._ebGotServers)
d.addCallback(lambda x, self=self: self._reallyConnect())
if self._defaultPort:
d.addErrback(self._ebServiceUnknown)
d.addErrback(self.connectionFailed)
elif self.connector is None:
self._reallyConnect()
else:
self.connector.connect()
示例6: test_socks5TorStyleFailedResolution
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import DNSLookupError [as 别名]
def test_socks5TorStyleFailedResolution(self):
"""
A Tor-style name resolution when resolution fails.
"""
self.assert_handshake()
self.deliver_data(
self.sock,
struct.pack('!BBBB', 5, 0xf0, 0, 3) + struct.pack(
"!B", len(b"unknown")
) + b"unknown" + struct.pack("!H", 3401)
)
reply = self.sock.transport.value()
self.sock.transport.clear()
self.assertEqual(reply, struct.pack('!BBBB', 5, 4, 0, 0))
self.assertTrue(self.sock.transport.stringTCPTransport_closing)
self.assertEqual(len(self.flushLoggedErrors(DNSLookupError)), 1)
示例7: errback_httpbin
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import DNSLookupError [as 别名]
def errback_httpbin(self, failure):
# log all failures
self.logger.error(repr(failure))
# in case you want to do something special for some errors,
# you may need the failure's type:
if failure.check(HttpError):
print("HttpError出错了")
# these exceptions come from HttpError spider middleware
# you can get the non-200 response
response = failure.value.response
self.logger.error('HttpError on %s', response.url)
elif failure.check(DNSLookupError):
# this is the original request
request = failure.request
self.logger.error('DNSLookupError on %s', request.url)
elif failure.check(TimeoutError, TCPTimedOutError):
request = failure.request
self.logger.error('TimeoutError on %s', request.url)
示例8: connect
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import DNSLookupError [as 别名]
def connect(self):
"""Start connection to remote server."""
self.factory.doStart()
self.factory.startedConnecting(self)
if not self.servers:
if self.domain is None:
self.connectionFailed(error.DNSLookupError("Domain is not defined."))
return
d = client.lookupService('_%s._%s.%s' % (self.service,
self.protocol,
self.domain))
d.addCallbacks(self._cbGotServers, self._ebGotServers)
d.addCallback(lambda x, self=self: self._reallyConnect())
d.addErrback(self.connectionFailed)
elif self.connector is None:
self._reallyConnect()
else:
self.connector.connect()
示例9: resolveHostName
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import DNSLookupError [as 别名]
def resolveHostName(self, resolutionReceiver, hostName, portNumber=0,
addressTypes=None, transportSemantics='TCP'):
"""
See L{IHostnameResolver.resolveHostName}
@param resolutionReceiver: see interface
@param hostName: see interface
@param portNumber: see interface
@param addressTypes: see interface
@param transportSemantics: see interface
@return: see interface
"""
resolution = HostResolution(hostName)
resolutionReceiver.resolutionBegan(resolution)
onAddress = self._simpleResolver.getHostByName(hostName)
def addressReceived(address):
resolutionReceiver.addressResolved(IPv4Address('TCP', address,
portNumber))
def errorReceived(error):
if not error.check(DNSLookupError):
self._log.failure("while looking up {name} with {resolver}",
error, name=hostName,
resolver=self._simpleResolver)
onAddress.addCallbacks(addressReceived, errorReceived)
def finish(result):
resolutionReceiver.resolutionComplete()
onAddress.addCallback(finish)
return resolution
示例10: resolutionComplete
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import DNSLookupError [as 别名]
def resolutionComplete(self):
"""
See L{IResolutionReceiver.resolutionComplete}
"""
if self._resolved:
return
self._deferred.errback(DNSLookupError(self._resolution.name))
示例11: _fail
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import DNSLookupError [as 别名]
def _fail(self, name, err):
err = error.DNSLookupError("address %r not found: %s" % (name, err))
return failure.Failure(err)
示例12: getHostByName
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import DNSLookupError [as 别名]
def getHostByName(self, name, timeout = (1, 3, 11, 45)):
try:
address = socket.gethostbyname(name)
except socket.error:
msg = "address %r not found" % (name,)
err = error.DNSLookupError(msg)
return defer.fail(err)
else:
return defer.succeed(address)
示例13: test_failure
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import DNSLookupError [as 别名]
def test_failure(self):
"""
L{ThreadedResolver.getHostByName} returns a L{Deferred} which fires a
L{Failure} if the call to L{socket.gethostbyname} raises an exception.
"""
timeout = 30
reactor = FakeReactor()
self.addCleanup(reactor._stop)
def fakeGetHostByName(name):
raise IOError("ENOBUFS (this is a funny joke)")
self.patch(socket, 'gethostbyname', fakeGetHostByName)
failedWith = []
resolver = ThreadedResolver(reactor)
d = resolver.getHostByName("some.name", (timeout,))
self.assertFailure(d, DNSLookupError)
d.addCallback(failedWith.append)
reactor._runThreadCalls()
self.assertEqual(len(failedWith), 1)
# Make sure that any timeout-related stuff gets cleaned up.
reactor._clock.advance(timeout + 1)
self.assertEqual(reactor._clock.calls, [])
示例14: test_timeout
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import DNSLookupError [as 别名]
def test_timeout(self):
"""
If L{socket.gethostbyname} does not complete before the specified
timeout elapsed, the L{Deferred} returned by
L{ThreadedResolver.getHostByBame} fails with L{DNSLookupError}.
"""
timeout = 10
reactor = FakeReactor()
self.addCleanup(reactor._stop)
result = Queue()
def fakeGetHostByName(name):
raise result.get()
self.patch(socket, 'gethostbyname', fakeGetHostByName)
failedWith = []
resolver = ThreadedResolver(reactor)
d = resolver.getHostByName("some.name", (timeout,))
self.assertFailure(d, DNSLookupError)
d.addCallback(failedWith.append)
reactor._clock.advance(timeout - 1)
self.assertEqual(failedWith, [])
reactor._clock.advance(1)
self.assertEqual(len(failedWith), 1)
# Eventually the socket.gethostbyname does finish - in this case, with
# an exception. Nobody cares, though.
result.put(IOError("The I/O was errorful"))
示例15: test_failure
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import DNSLookupError [as 别名]
def test_failure(self):
"""
If no address is returned by GAI for a hostname, the connection attempt
fails with L{error.DNSLookupError}.
"""
endpoint = endpoints.HostnameEndpoint(
deterministicResolvingReactor(Clock(), []),
b"example.com", 80
)
clientFactory = object()
dConnect = endpoint.connect(clientFactory)
exc = self.failureResultOf(dConnect, error.DNSLookupError)
self.assertIn("example.com", str(exc))