Created
November 24, 2012 14:33
-
-
Save Kindari/4139905 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def send(self, command, *args, **kwargs): | |
| #data is base64 encoded later | |
| data = kwargs.pop('data', None) | |
| # all commands must have a transaction id | |
| tid = self.transaction_id | |
| parts = [command, '-i %d' % tid] | |
| if args: # extra arguments | |
| parts.extend( args ) | |
| if kwargs: # named arguments | |
| parts.extend( ['-%s %s' % item for item in kwargs.items()] ) | |
| payload = ' '.join(parts) | |
| if data: | |
| payload += ' -- ' + base64.b64encode( data ) | |
| payload += '\x00' # null terminated payloads | |
| self.socket.send( payload ) | |
| return tid |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment