本文整理汇总了Python中twisted.internet.error.TimeoutError方法的典型用法代码示例。如果您正苦于以下问题:Python error.TimeoutError方法的具体用法?Python error.TimeoutError怎么用?Python error.TimeoutError使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.internet.error
的用法示例。
在下文中一共展示了error.TimeoutError方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: errback_httpbin
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import TimeoutError [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_serverTimeout
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import TimeoutError [as 别名]
def test_serverTimeout(self):
"""
The *client* has a timeout mechanism which will close connections that
are inactive for a period.
"""
c = Clock()
self.server.timeoutTest = True
self.client.timeout = 5 #seconds
self.client.callLater = c.callLater
self.selectedArgs = None
def login():
d = self.client.login(b'testuser', b'password-test')
c.advance(5)
d.addErrback(timedOut)
return d
def timedOut(failure):
self._cbStopClient(None)
failure.trap(error.TimeoutError)
d = self.connected.addCallback(strip(login))
d.addErrback(self._ebGeneral)
return defer.gatherResults([d, self.loopback()])
示例3: _process_error
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import TimeoutError [as 别名]
def _process_error(self, failure):
err = failure.value
if isinstance(err, gcmclient.GCMAuthenticationError):
self.log.error("GCM Authentication Error: %s" % err)
raise RouterException("Server error", status_code=500,
errno=901)
if isinstance(err, TimeoutError):
self.log.warn("GCM Timeout: %s" % err)
self.metrics.increment("notification.bridge.error",
tags=make_tags(
self._base_tags,
reason="timeout"))
raise RouterException("Server error", status_code=502,
errno=903,
log_exception=False)
if isinstance(err, ConnectError):
self.log.warn("GCM Unavailable: %s" % err)
self.metrics.increment("notification.bridge.error",
tags=make_tags(
self._base_tags,
reason="connection_unavailable"))
raise RouterException("Server error", status_code=502,
errno=902,
log_exception=False)
return failure
示例4: errback_httpbin
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import TimeoutError [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)
示例5: connectionLost
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import TimeoutError [as 别名]
def connectionLost(self, reason):
if self.timeout > 0:
self.setTimeout(None)
if self._timedOut:
reason = error.TimeoutError()
elif self._greetingError:
reason = ServerErrorResponse(self._greetingError)
d = []
if self._waiting is not None:
d.append(self._waiting)
self._waiting = None
if self._blockedQueue is not None:
d.extend([deferred for (deferred, f, a) in self._blockedQueue])
self._blockedQueue = None
for w in d:
w.errback(reason)
示例6: test_serverTimeout
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import TimeoutError [as 别名]
def test_serverTimeout(self):
"""
The *client* has a timeout mechanism which will close connections that
are inactive for a period.
"""
c = Clock()
self.server.timeoutTest = True
self.client.timeout = 5 #seconds
self.client.callLater = c.callLater
self.selectedArgs = None
def login():
d = self.client.login('testuser', 'password-test')
c.advance(5)
d.addErrback(timedOut)
return d
def timedOut(failure):
self._cbStopClient(None)
failure.trap(error.TimeoutError)
d = self.connected.addCallback(strip(login))
d.addErrback(self._ebGeneral)
return defer.gatherResults([d, self.loopback()])
示例7: testCallBeforeStartupUnexecuted
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import TimeoutError [as 别名]
def testCallBeforeStartupUnexecuted(self):
progname = self.mktemp()
progfile = file(progname, 'w')
progfile.write(_callBeforeStartupProgram % {'reactor': reactor.__module__})
progfile.close()
def programFinished((out, err, reason)):
if reason.check(error.ProcessTerminated):
self.fail("Process did not exit cleanly (out: %s err: %s)" % (out, err))
if err:
log.msg("Unexpected output on standard error: %s" % (err,))
self.failIf(out, "Expected no output, instead received:\n%s" % (out,))
def programTimeout(err):
err.trap(error.TimeoutError)
proto.signalProcess('KILL')
return err
env = os.environ.copy()
env['PYTHONPATH'] = os.pathsep.join(sys.path)
d = defer.Deferred().addCallbacks(programFinished, programTimeout)
proto = ThreadStartupProcessProtocol(d)
reactor.spawnProcess(proto, sys.executable, ('python', progname), env)
return d
示例8: testServerTimeout
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import TimeoutError [as 别名]
def testServerTimeout(self):
self.server.timeoutTest = True
self.client.timeout = 5 #seconds
self.selectedArgs = None
def login():
d = self.client.login('testuser', 'password-test')
d.addErrback(timedOut)
return d
def timedOut(failure):
self._cbStopClient(None)
failure.trap(error.TimeoutError)
d = self.connected.addCallback(strip(login))
d.addErrback(self._ebGeneral)
self.loopback()
示例9: handleCmdConnectFailure
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import TimeoutError [as 别名]
def handleCmdConnectFailure(self, failure):
log.error("CMD CONNECT: %s" % failure.getErrorMessage())
# Map common twisted errors to SOCKS error codes
if failure.type == error.NoRouteError:
self.sendReply(SOCKSv5Reply.NetworkUnreachable)
elif failure.type == error.ConnectionRefusedError:
self.sendReply(SOCKSv5Reply.ConnectionRefused)
elif failure.type == error.TCPTimedOutError or failure.type == error.TimeoutError:
self.sendReply(SOCKSv5Reply.TTLExpired)
elif failure.type == error.UnsupportedAddressFamily:
self.sendReply(SOCKSv5Reply.AddressTypeNotSupported)
elif failure.type == error.ConnectError:
# Twisted doesn't have a exception defined for EHOSTUNREACH,
# so the failure is a ConnectError. Try to catch this case
# and send a better reply, but fall back to a GeneralFailure.
reply = SOCKSv5Reply.GeneralFailure
try:
import errno
if hasattr(errno, "EHOSTUNREACH"):
if failure.value.osError == errno.EHOSTUNREACH:
reply = SOCKSv5Reply.HostUnreachable
if hasattr(errno, "WSAEHOSTUNREACH"):
if failure.value.osError == errno.WSAEHOSTUNREACH:
reply = SOCKSv5Reply.HostUnreachable
except Exception:
pass
self.sendReply(reply)
else:
self.sendReply(SOCKSv5Reply.GeneralFailure)
failure.trap(error.NoRouteError, error.ConnectionRefusedError,
error.TCPTimedOutError, error.TimeoutError,
error.UnsupportedAddressFamily, error.ConnectError)
示例10: connect
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import TimeoutError [as 别名]
def connect(self):
"""Start connection to remote server."""
if self.state != "disconnected":
raise RuntimeError("can't connect in this state")
self.state = "connecting"
if not self.factoryStarted:
self.factory.doStart()
self.factoryStarted = 1
self.transport = transport = self._makeTransport()
if self.timeout is not None:
self.timeoutID = self.reactor.callLater(self.timeout, transport.failIfNotConnected, error.TimeoutError())
self.factory.startedConnecting(self)
示例11: connectionLost
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import TimeoutError [as 别名]
def connectionLost(self, reason):
"""
Clean up when the connection has been lost.
When the loss of connection was initiated by the client due to a
timeout, the L{_timedOut} flag will be set. When it was initiated by
the client due to an error in the server greeting, L{_greetingError}
will be set to the server response minus the status indicator.
@type reason: L{Failure <twisted.python.failure.Failure>}
@param reason: The reason the connection was terminated.
"""
if self.timeout > 0:
self.setTimeout(None)
if self._timedOut:
reason = error.TimeoutError()
elif self._greetingError:
reason = ServerErrorResponse(self._greetingError)
d = []
if self._waiting is not None:
d.append(self._waiting)
self._waiting = None
if self._blockedQueue is not None:
d.extend([deferred for (deferred, f, a) in self._blockedQueue])
self._blockedQueue = None
for w in d:
w.errback(reason)
示例12: testTimeout
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import TimeoutError [as 别名]
def testTimeout(self):
def login():
d = self.client.login('test', 'twisted')
d.addCallback(loggedIn)
d.addErrback(timedOut)
return d
def loggedIn(result):
self.fail("Successfully logged in!? Impossible!")
def timedOut(failure):
failure.trap(error.TimeoutError)
self._cbStopClient(None)
def quit():
return self.client.quit()
self.client.timeout = 0.01
# Tell the server to not return a response to client. This
# will trigger a timeout.
pop3testserver.TIMEOUT_RESPONSE = True
methods = [login, quit]
map(self.connected.addCallback, map(strip, methods))
self.connected.addCallback(self._cbStopClient)
self.connected.addErrback(self._ebGeneral)
return self.loopback()
示例13: _reissue
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import TimeoutError [as 别名]
def _reissue(self, reason, addressesLeft, addressesUsed, query, timeout):
reason.trap(dns.DNSQueryTimeoutError)
# If there are no servers left to be tried, adjust the timeout
# to the next longest timeout period and move all the
# "used" addresses back to the list of addresses to try.
if not addressesLeft:
addressesLeft = addressesUsed
addressesLeft.reverse()
addressesUsed = []
timeout = timeout[1:]
# If all timeout values have been used this query has failed. Tell the
# protocol we're giving up on it and return a terminal timeout failure
# to our caller.
if not timeout:
return failure.Failure(defer.TimeoutError(query))
# Get an address to try. Take it out of the list of addresses
# to try and put it ino the list of already tried addresses.
address = addressesLeft.pop()
addressesUsed.append(address)
# Issue a query to a server. Use the current timeout. Add this
# function as a timeout errback in case another retry is required.
d = self._query(address, query, timeout[0], reason.value.id)
d.addErrback(self._reissue, addressesLeft, addressesUsed, query, timeout)
return d
示例14: _timeoutZone
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import TimeoutError [as 别名]
def _timeoutZone(self, d, controller, connector, seconds):
connector.disconnect()
controller.timeoutCall = None
controller.deferred = None
d.errback(error.TimeoutError("Zone lookup timed out after %d seconds" % (seconds,)))
示例15: testCallBeforeStartupUnexecuted
# 需要导入模块: from twisted.internet import error [as 别名]
# 或者: from twisted.internet.error import TimeoutError [as 别名]
def testCallBeforeStartupUnexecuted(self):
progname = self.mktemp()
with open(progname, 'w') as progfile:
progfile.write(_callBeforeStartupProgram % {'reactor': reactor.__module__})
def programFinished(result):
(out, err, reason) = result
if reason.check(error.ProcessTerminated):
self.fail("Process did not exit cleanly (out: %s err: %s)" % (out, err))
if err:
log.msg("Unexpected output on standard error: %s" % (err,))
self.assertFalse(
out,
"Expected no output, instead received:\n%s" % (out,))
def programTimeout(err):
err.trap(error.TimeoutError)
proto.signalProcess('KILL')
return err
env = os.environ.copy()
env['PYTHONPATH'] = os.pathsep.join(sys.path)
d = defer.Deferred().addCallbacks(programFinished, programTimeout)
proto = ThreadStartupProcessProtocol(d)
reactor.spawnProcess(proto, sys.executable, ('python', progname), env)
return d