Python twisted.python.log.callWithLogger() Examples
The following are 30
code examples of twisted.python.log.callWithLogger().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
twisted.python.log
, or try the search function
.
Example #1
Source File: connection.py From python-for-android with Apache License 2.0 | 6 votes |
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
Example #2
Source File: app.py From BitTorrent with GNU General Public License v3.0 | 6 votes |
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! #
Example #3
Source File: connection.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
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)
Example #4
Source File: connection.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
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
Example #5
Source File: connection.py From learn_python3_spider with MIT License | 6 votes |
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)
Example #6
Source File: connection.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
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
Example #7
Source File: connection.py From learn_python3_spider with MIT License | 6 votes |
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)
Example #8
Source File: connection.py From python-for-android with Apache License 2.0 | 6 votes |
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
Example #9
Source File: transport.py From python-for-android with Apache License 2.0 | 6 votes |
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()
Example #10
Source File: asyncioreactor.py From learn_python3_spider with MIT License | 6 votes |
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
Example #11
Source File: connection.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
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)
Example #12
Source File: connection.py From python-for-android with Apache License 2.0 | 6 votes |
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)
Example #13
Source File: connection.py From BitTorrent with GNU General Public License v3.0 | 6 votes |
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)
Example #14
Source File: pollreactor.py From learn_python3_spider with MIT License | 6 votes |
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)
Example #15
Source File: asyncioreactor.py From learn_python3_spider with MIT License | 6 votes |
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
Example #16
Source File: twisted.py From honeything with GNU General Public License v3.0 | 6 votes |
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))
Example #17
Source File: connection.py From learn_python3_spider with MIT License | 6 votes |
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)
Example #18
Source File: connection.py From learn_python3_spider with MIT License | 6 votes |
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
Example #19
Source File: asyncioreactor.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
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
Example #20
Source File: asyncioreactor.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
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
Example #21
Source File: pollreactor.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
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)
Example #22
Source File: connection.py From python-for-android with Apache License 2.0 | 6 votes |
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)
Example #23
Source File: connection.py From learn_python3_spider with MIT License | 6 votes |
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
Example #24
Source File: connection.py From python-for-android with Apache License 2.0 | 5 votes |
def ssh_CHANNEL_WINDOW_ADJUST(self, packet): """ The other side is adding bytes to its window. Payload:: uint32 local channel number uint32 bytes to add Call the channel's addWindowBytes() method to add new bytes to the remote window. """ localChannel, bytesToAdd = struct.unpack('>2L', packet[:8]) channel = self.channels[localChannel] log.callWithLogger(channel, channel.addWindowBytes, bytesToAdd)
Example #25
Source File: gtkreactor.py From python-for-android with Apache License 2.0 | 5 votes |
def callback(self, source, condition): log.callWithLogger(source, self._readAndWrite, source, condition) self.simulate() # fire Twisted timers return 1 # 1=don't auto-remove the source
Example #26
Source File: transport.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
def dataReceived(self, data): self.buf = self.buf+data if not self.gotVersion: parts = self.buf.split('\n') for p in parts: if p[: 4] == 'SSH-': self.gotVersion = 1 self.otherVersionString = p.strip() if p.split('-')[1]not in('1.99', '2.0'): # bad version self.sendDisconnect(DISCONNECT_PROTOCOL_VERSION_NOT_SUPPORTED, 'bad version %s'%p.split('-')[1]) return i = parts.index(p) self.buf = '\n'.join(parts[i+1:]) packet = self.getPacket() while packet: messageNum = ord(packet[0]) if messageNum < 50: messageType = messages[messageNum][4:] f = getattr(self, 'ssh_%s'%messageType, None) if f: f(packet[1:]) else: log.msg("couldn't handle %s"%messageType) log.msg(repr(packet[1:])) self.sendUnimplemented() elif self.service: log.callWithLogger(self.service, self.service.packetReceived, ord(packet[0]), packet[1:]) else: log.msg("couldn't handle %s"%messageNum) log.msg(repr(packet[1:])) self.sendUnimplemented() packet = self.getPacket()
Example #27
Source File: win32eventreactor.py From python-for-android with Apache License 2.0 | 5 votes |
def doWaitForMultipleEvents(self, timeout): log.msg(channel='system', event='iteration', reactor=self) if timeout is None: #timeout = INFINITE timeout = 100 else: timeout = int(timeout * 1000) if not (self._events or self._writes): # sleep so we don't suck up CPU time time.sleep(timeout / 1000.0) return canDoMoreWrites = 0 for fd in self._writes.keys(): if log.callWithLogger(fd, self._runWrite, fd): canDoMoreWrites = 1 if canDoMoreWrites: timeout = 0 handles = self._events.keys() or [self.dummyEvent] val = MsgWaitForMultipleObjects(handles, 0, timeout, QS_ALLINPUT | QS_ALLEVENTS) if val == WAIT_TIMEOUT: return elif val == WAIT_OBJECT_0 + len(handles): exit = win32gui.PumpWaitingMessages() if exit: self.callLater(0, self.stop) return elif val >= WAIT_OBJECT_0 and val < WAIT_OBJECT_0 + len(handles): fd, action = self._events[handles[val - WAIT_OBJECT_0]] log.callWithLogger(fd, self._runAction, action, fd)
Example #28
Source File: base.py From python-for-android with Apache License 2.0 | 5 votes |
def disconnectAll(self): """Disconnect every reader, and writer in the system. """ selectables = self.removeAll() for reader in selectables: log.callWithLogger(reader, reader.connectionLost, failure.Failure(main.CONNECTION_LOST))
Example #29
Source File: connection.py From python-for-android with Apache License 2.0 | 5 votes |
def ssh_CHANNEL_CLOSE(self, packet): """ The other side is closing its end; it does not want to receive any more data. Payload:: uint32 local channel number Notify the channnel by calling its closeReceived() method. If the channel has also sent a close message, call self.channelClosed(). """ localChannel = struct.unpack('>L', packet[:4])[0] channel = self.channels[localChannel] log.callWithLogger(channel, channel.closeReceived) channel.remoteClosed = True if channel.localClosed and channel.remoteClosed: self.channelClosed(channel)
Example #30
Source File: connection.py From python-for-android with Apache License 2.0 | 5 votes |
def ssh_CHANNEL_DATA(self, packet): """ The other side is sending us data. Payload:: uint32 local channel number string data Check to make sure the other side hasn't sent too much data (more than what's in the window, or more than the maximum packet size). If they have, close the channel. Otherwise, decrease the available window and pass the data to the channel's dataReceived(). """ 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, log.msg, 'too much data') self.sendClose(channel) 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)