本文整理汇总了Python中twisted.python.log.callWithLogger方法的典型用法代码示例。如果您正苦于以下问题:Python log.callWithLogger方法的具体用法?Python log.callWithLogger怎么用?Python log.callWithLogger使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.python.log
的用法示例。
在下文中一共展示了log.callWithLogger方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: addReader
# 需要导入模块: from twisted.python import log [as 别名]
# 或者: from twisted.python.log import callWithLogger [as 别名]
def addReader(self, reader):
if reader in self._readers.keys() or \
reader in self._continuousPolling._readers:
return
fd = reader.fileno()
try:
self._asyncioEventloop.add_reader(fd, callWithLogger, reader,
self._readOrWrite, reader,
True)
self._readers[reader] = fd
except IOError as e:
self._unregisterFDInAsyncio(fd)
if e.errno == errno.EPERM:
# epoll(7) doesn't support certain file descriptors,
# e.g. filesystem files, so for those we just poll
# continuously:
self._continuousPolling.addReader(reader)
else:
raise
示例2: addWriter
# 需要导入模块: from twisted.python import log [as 别名]
# 或者: from twisted.python.log import callWithLogger [as 别名]
def addWriter(self, writer):
if writer in self._writers.keys() or \
writer in self._continuousPolling._writers:
return
fd = writer.fileno()
try:
self._asyncioEventloop.add_writer(fd, callWithLogger, writer,
self._readOrWrite, writer,
False)
self._writers[writer] = fd
except PermissionError:
self._unregisterFDInAsyncio(fd)
# epoll(7) doesn't support certain file descriptors,
# e.g. filesystem files, so for those we just poll
# continuously:
self._continuousPolling.addWriter(writer)
except BrokenPipeError:
# The kqueuereactor will raise this if there is a broken pipe
self._unregisterFDInAsyncio(fd)
except:
self._unregisterFDInAsyncio(fd)
raise
示例3: doPoll
# 需要导入模块: from twisted.python import log [as 别名]
# 或者: from twisted.python.log import callWithLogger [as 别名]
def doPoll(self, timeout):
"""Poll the poller for new events."""
if timeout is not None:
timeout = int(timeout * 1000) # convert seconds to milliseconds
try:
l = self._poller.poll(timeout)
except SelectError as e:
if e.args[0] == errno.EINTR:
return
else:
raise
_drdw = self._doReadOrWrite
for fd, event in l:
try:
selectable = self._selectables[fd]
except KeyError:
# Handles the infrequent case where one selectable's
# handler disconnects another.
continue
log.callWithLogger(selectable, _drdw, selectable, fd, event)
示例4: ssh_CHANNEL_OPEN_FAILURE
# 需要导入模块: from twisted.python import log [as 别名]
# 或者: from twisted.python.log import callWithLogger [as 别名]
def ssh_CHANNEL_OPEN_FAILURE(self, packet):
"""
The other side did not accept our MSG_CHANNEL_OPEN request. Payload::
uint32 local channel number
uint32 reason code
string reason description
Find the channel using the local channel number and notify it by
calling its openFailed() method.
"""
localChannel, reasonCode = struct.unpack('>2L', packet[:8])
reasonDesc = common.getNS(packet[8:])[0]
channel = self.channels[localChannel]
del self.channels[localChannel]
channel.conn = self
reason = error.ConchError(reasonDesc, reasonCode)
log.callWithLogger(channel, channel.openFailed, reason)
示例5: ssh_CHANNEL_REQUEST
# 需要导入模块: from twisted.python import log [as 别名]
# 或者: from twisted.python.log import callWithLogger [as 别名]
def ssh_CHANNEL_REQUEST(self, packet):
"""
The other side is sending a request to a channel. Payload::
uint32 local channel number
string request name
bool want reply
<request specific data>
Pass the message to the channel's requestReceived method. If the
other side wants a reply, add callbacks which will send the
reply.
"""
localChannel = struct.unpack('>L', packet[:4])[0]
requestType, rest = common.getNS(packet[4:])
wantReply = ord(rest[0:1])
channel = self.channels[localChannel]
d = defer.maybeDeferred(log.callWithLogger, channel,
channel.requestReceived, requestType, rest[1:])
if wantReply:
d.addCallback(self._cbChannelRequest, localChannel)
d.addErrback(self._ebChannelRequest, localChannel)
return d
示例6: ssh_CHANNEL_FAILURE
# 需要导入模块: from twisted.python import log [as 别名]
# 或者: from twisted.python.log import callWithLogger [as 别名]
def ssh_CHANNEL_FAILURE(self, packet):
"""
Our channel request to the other side failed. Payload::
uint32 local channel number
Get the C{Deferred} out of self.deferreds and errback it with a
C{error.ConchError}.
"""
localChannel = struct.unpack('>L', packet[:4])[0]
if self.deferreds.get(localChannel):
d = self.deferreds[localChannel].pop(0)
log.callWithLogger(self.channels[localChannel],
d.errback,
error.ConchError('channel request failed'))
# methods for users of the connection to call
示例7: channelClosed
# 需要导入模块: from twisted.python import log [as 别名]
# 或者: from twisted.python.log import callWithLogger [as 别名]
def channelClosed(self, channel):
"""
Called when a channel is closed.
It clears the local state related to the channel, and calls
channel.closed().
MAKE SURE YOU CALL THIS METHOD, even if you subclass L{SSHConnection}.
If you don't, things will break mysteriously.
@type channel: L{SSHChannel}
"""
if channel in self.channelsToRemoteChannel: # actually open
channel.localClosed = channel.remoteClosed = True
del self.localToRemoteChannel[channel.id]
del self.channels[channel.id]
del self.channelsToRemoteChannel[channel]
for d in self.deferreds.setdefault(channel.id, []):
d.errback(error.ConchError("Channel closed."))
del self.deferreds[channel.id][:]
log.callWithLogger(channel, channel.closed)
示例8: ssh_CHANNEL_OPEN_CONFIRMATION
# 需要导入模块: from twisted.python import log [as 别名]
# 或者: from twisted.python.log import callWithLogger [as 别名]
def ssh_CHANNEL_OPEN_CONFIRMATION(self, packet):
"""
The other side accepted our MSG_CHANNEL_OPEN request. Payload::
uint32 local channel number
uint32 remote channel number
uint32 remote window size
uint32 remote maximum packet size
<channel specific data>
Find the channel using the local channel number and notify its
channelOpen method.
"""
(localChannel, remoteChannel, windowSize,
maxPacket) = struct.unpack('>4L', packet[: 16])
specificData = packet[16:]
channel = self.channels[localChannel]
channel.conn = self
self.localToRemoteChannel[localChannel] = remoteChannel
self.channelsToRemoteChannel[channel] = remoteChannel
channel.remoteWindowLeft = windowSize
channel.remoteMaxPacket = maxPacket
log.callWithLogger(channel, channel.channelOpen, specificData)
示例9: channelClosed
# 需要导入模块: from twisted.python import log [as 别名]
# 或者: from twisted.python.log import callWithLogger [as 别名]
def channelClosed(self, channel):
"""
Called when a channel is closed.
It clears the local state related to the channel, and calls
channel.closed().
MAKE SURE YOU CALL THIS METHOD, even if you subclass L{SSHConnection}.
If you don't, things will break mysteriously.
@type channel: L{SSHChannel}
"""
if channel in self.channelsToRemoteChannel: # actually open
channel.localClosed = channel.remoteClosed = True
del self.localToRemoteChannel[channel.id]
del self.channels[channel.id]
del self.channelsToRemoteChannel[channel]
for d in self.deferreds.pop(channel.id, []):
d.errback(error.ConchError("Channel closed."))
log.callWithLogger(channel, channel.closed)
示例10: _invoke_callback
# 需要导入模块: from twisted.python import log [as 别名]
# 或者: from twisted.python.log import callWithLogger [as 别名]
def _invoke_callback(self, fd, events):
(reader, writer) = self._fds[fd]
if reader:
err = None
if reader.fileno() == -1:
err = error.ConnectionLost()
elif events & IOLoop.READ:
err = log.callWithLogger(reader, reader.doRead)
if err is None and events & IOLoop.ERROR:
err = error.ConnectionLost()
if err is not None:
self.removeReader(reader)
reader.readConnectionLost(failure.Failure(err))
if writer:
err = None
if writer.fileno() == -1:
err = error.ConnectionLost()
elif events & IOLoop.WRITE:
err = log.callWithLogger(writer, writer.doWrite)
if err is None and events & IOLoop.ERROR:
err = error.ConnectionLost()
if err is not None:
self.removeWriter(writer)
writer.writeConnectionLost(failure.Failure(err))
示例11: ssh_CHANNEL_REQUEST
# 需要导入模块: from twisted.python import log [as 别名]
# 或者: from twisted.python.log import callWithLogger [as 别名]
def ssh_CHANNEL_REQUEST(self, packet):
"""
The other side is sending a request to a channel. Payload::
uint32 local channel number
string request name
bool want reply
<request specific data>
Pass the message to the channel's requestReceived method. If the
other side wants a reply, add callbacks which will send the
reply.
"""
localChannel = struct.unpack('>L', packet[: 4])[0]
requestType, rest = common.getNS(packet[4:])
wantReply = ord(rest[0])
channel = self.channels[localChannel]
d = defer.maybeDeferred(log.callWithLogger, channel,
channel.requestReceived, requestType, rest[1:])
if wantReply:
d.addCallback(self._cbChannelRequest, localChannel)
d.addErrback(self._ebChannelRequest, localChannel)
return d
示例12: dispatchMessage
# 需要导入模块: from twisted.python import log [as 别名]
# 或者: from twisted.python.log import callWithLogger [as 别名]
def dispatchMessage(self, messageNum, payload):
"""
Send a received message to the appropriate method.
@type messageNum: C{int}
@type payload: c{str}
"""
if messageNum < 50 and messageNum in messages:
messageType = messages[messageNum][4:]
f = getattr(self, 'ssh_%s' % messageType, None)
if f is not None:
f(payload)
else:
log.msg("couldn't handle %s" % messageType)
log.msg(repr(payload))
self.sendUnimplemented()
elif self.service:
log.callWithLogger(self.service, self.service.packetReceived,
messageNum, payload)
else:
log.msg("couldn't handle %s" % messageNum)
log.msg(repr(payload))
self.sendUnimplemented()
示例13: run
# 需要导入模块: from twisted.python import log [as 别名]
# 或者: from twisted.python.log import callWithLogger [as 别名]
def run(self, save=1, installSignalHandlers=1):
"""run(save=1, installSignalHandlers=1)
Run this application, running the main loop if necessary.
If 'save' is true, then when this Application is shut down, it
will be persisted to a pickle.
'installSignalHandlers' is passed through to reactor.run(), the
function that starts the mainloop.
"""
from twisted.internet import reactor
if not self._boundPorts:
self.bindPorts()
self._save = save
reactor.addSystemEventTrigger('before', 'shutdown', self._beforeShutDown)
reactor.addSystemEventTrigger('after', 'shutdown', self._afterShutDown)
global theApplication
theApplication = self
log.callWithLogger(self, reactor.run, installSignalHandlers=installSignalHandlers)
#
# These are dummy classes for backwards-compatibility!
#
示例14: ssh_CHANNEL_DATA
# 需要导入模块: from twisted.python import log [as 别名]
# 或者: from twisted.python.log import callWithLogger [as 别名]
def ssh_CHANNEL_DATA(self, packet):
localChannel, dataLength = struct.unpack('>2L', packet[: 8])
channel = self.channels[localChannel]
# XXX should this move to dataReceived to put client in charge?
if dataLength > channel.localWindowLeft or \
dataLength > channel.localMaxPacket: # more data than we want
log.callWithLogger(channel, lambda s=self,c=channel:
log.msg('too much data') and s.sendClose(c))
return
#packet = packet[:channel.localWindowLeft+4]
data = common.getNS(packet[4:])[0]
channel.localWindowLeft-=dataLength
if channel.localWindowLeft < channel.localWindowSize/2:
self.adjustWindow(channel, channel.localWindowSize - \
channel.localWindowLeft)
#log.msg('local window left: %s/%s' % (channel.localWindowLeft,
# channel.localWindowSize))
log.callWithLogger(channel, channel.dataReceived, data)
示例15: _invoke_callback
# 需要导入模块: from twisted.python import log [as 别名]
# 或者: from twisted.python.log import callWithLogger [as 别名]
def _invoke_callback(self, fd, events):
if fd not in self._fds:
return
(reader, writer) = self._fds[fd]
if reader:
err = None
if reader.fileno() == -1:
err = error.ConnectionLost()
elif events & IOLoop.READ:
err = log.callWithLogger(reader, reader.doRead)
if err is None and events & IOLoop.ERROR:
err = error.ConnectionLost()
if err is not None:
self.removeReader(reader)
reader.readConnectionLost(failure.Failure(err))
if writer:
err = None
if writer.fileno() == -1:
err = error.ConnectionLost()
elif events & IOLoop.WRITE:
err = log.callWithLogger(writer, writer.doWrite)
if err is None and events & IOLoop.ERROR:
err = error.ConnectionLost()
if err is not None:
self.removeWriter(writer)
writer.writeConnectionLost(failure.Failure(err))