[Twisted-Python] conch defer for dataReceived
![](https://secure.gravatar.com/avatar/7fe88e910d129dba8d3a8678530d9443.jpg?s=120&d=mm&r=g)
Hello all. Help me please. Tell me how to wrap in Defer dataReceived. For example, I need to execute a command and send receive data in callback. The only yet I found - to use the session number sent commands and replies received Can one example. Thanks in advance! -- Alexey
![](https://secure.gravatar.com/avatar/e1554622707bedd9202884900430b838.jpg?s=120&d=mm&r=g)
If you want to have commands and responses, you need a higher-level callback than simply dataReceived. This is what, for example, AMP <https://twistedmatrix.com/documents/current/api/twisted.protocols.amp.html <https://twistedmatrix.com/documents/current/api/twisted.protocols.amp.html>> is for. -glyph
![](https://secure.gravatar.com/avatar/7fe88e910d129dba8d3a8678530d9443.jpg?s=120&d=mm&r=g)
Thans You! I found same solution, but to another problem like this. Channel class: class SFTPChannel(channel.SSHChannel): name ='session' _sftp = defer.Deferred() # defer = def channelOpen(self, _):d =self.conn.sendRequest(self, 'subsystem', common.NS('sftp'), wantReply=True) self.conn.sftp_channel_defer = d.addCallbacks(self._cbSFTP)@defer.inlineCallbacks def _cbSFTP(self, result):self.client = FileTransferClient() self.client.makeConnection(self) self.dataReceived =self.client.dataReceived self._sftp.callback(self.client) def get_file(self, *args): print args Use in exteral module m = connection.sftp_channel._sftp.addCallback(connection.sftp_channel.get_file, *['./222/test.txt', '/root/freeswitch_37_17.tar']) m.addCallback(self._cbFileRCopy) m.addErrback(self._ebFileRCopy) I think, if set some defer in SSHChannel in def channelOpen(self, data): self.conn.sendRequest(self, 'exec', common.NS(self.command), wantReply=True).addCallback(self._gotResponse) self._chennel_defer = Defered() and in def dataReceived(self, data): self._chennel_defer = some_def() But in this case one channel = one command = one respons 29.07.15 11:56, Glyph пишет:
![](https://secure.gravatar.com/avatar/e1554622707bedd9202884900430b838.jpg?s=120&d=mm&r=g)
If you want to have commands and responses, you need a higher-level callback than simply dataReceived. This is what, for example, AMP <https://twistedmatrix.com/documents/current/api/twisted.protocols.amp.html <https://twistedmatrix.com/documents/current/api/twisted.protocols.amp.html>> is for. -glyph
![](https://secure.gravatar.com/avatar/7fe88e910d129dba8d3a8678530d9443.jpg?s=120&d=mm&r=g)
Thans You! I found same solution, but to another problem like this. Channel class: class SFTPChannel(channel.SSHChannel): name ='session' _sftp = defer.Deferred() # defer = def channelOpen(self, _):d =self.conn.sendRequest(self, 'subsystem', common.NS('sftp'), wantReply=True) self.conn.sftp_channel_defer = d.addCallbacks(self._cbSFTP)@defer.inlineCallbacks def _cbSFTP(self, result):self.client = FileTransferClient() self.client.makeConnection(self) self.dataReceived =self.client.dataReceived self._sftp.callback(self.client) def get_file(self, *args): print args Use in exteral module m = connection.sftp_channel._sftp.addCallback(connection.sftp_channel.get_file, *['./222/test.txt', '/root/freeswitch_37_17.tar']) m.addCallback(self._cbFileRCopy) m.addErrback(self._ebFileRCopy) I think, if set some defer in SSHChannel in def channelOpen(self, data): self.conn.sendRequest(self, 'exec', common.NS(self.command), wantReply=True).addCallback(self._gotResponse) self._chennel_defer = Defered() and in def dataReceived(self, data): self._chennel_defer = some_def() But in this case one channel = one command = one respons 29.07.15 11:56, Glyph пишет:
participants (3)
-
Alexey Panyovin
-
Glyph
-
Glyph Lefkowitz