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
#!/usr/bin/env python3 | |
import sys | |
import socket | |
import select | |
def command(name, args=None): | |
return {'name': name, 'args': args} | |
def readcmd(): |
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
var my_array = { | |
'one': 1337, | |
'two': 69, | |
}; |
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
<?php | |
$my_array = array( | |
'one' => 1337, | |
'two' => 69, | |
); |
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
class ActionManager(IOBase): | |
def __init__(self, action, socket, finished_callback=None): | |
self.action = action | |
self.socket = socket | |
self.finished_callback = finished_callback | |
self.vars = {} | |
def register(self, fdmanager): | |
if self.action is None: | |
return |
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
class ReadAction(Action): | |
def __init__(self, name): | |
super().__init__() | |
self.name = name | |
def run(self, socket, vars): | |
data = socket.recv(MAGIC_CONSTANT) | |
vars[self.name] = data | |
class WriteAction(Action): |
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
class Action: | |
def __init__(self): | |
self.next_action = None | |
def run(self, socket, vars): | |
pass # this will be overloaded | |
def __rshift__(self, other): | |
self.append_action(other) |
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
login_action = Write('LOGIN') >> \ | |
Read('login') >> \ | |
Write(lambda v: 'HELLO %s' % v['login']) |
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
class SendText(IOBase): | |
def __init__(self, fd, text=None): | |
self.fd = fd | |
self.text = text | |
if not self.text: | |
self.text = lambda: b"Hello!" | |
def register(self, fdmanager): | |
fdmanager.register_write(self.fs, self.write) |
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
class SendText(IOBase): | |
def __init__(self, fd, text=b"Hello!"): | |
self.fd = fd | |
self.text = text | |
def register(self, fdmanager): | |
fdmanager.register_write(self.fs, self.write) | |
def write(self): | |
os.write(self.fd, self.text) |
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
class FDManager: | |
def register_read(self, file_descriptor, callback): | |
# ... | |
def register_write(self, file_descriptor, callback): | |
# ... | |
def register_error(self, file_descriptor, callback): | |
# ... |
NewerOlder