6
def read(socket, size):
10
while len(datareturn) < size:
12
datareturn += socket.recv(1)
21
def __init__(self,socket, funcname):
25
def __call__(self,*args,**kwargs):
26
self.req = self._make_request(self.func, *args,**kwargs)
27
self.socket.send(self.req)
28
length = int(read(self.socket, 4))
30
return json.loads(read(self.socket, length))
32
def _make_request(self, func, *args, **kwargs):
35
request["function"] = func
36
request["args"] = args
37
request["kwargs"] = kwargs
40
js = json.dumps(request)
42
req = "%4i%s" % (size, js)
46
def __init__(self,server="127.0.0.1", port=3451):
47
self.socket = socket.socket()
48
self.socket.connect((server, port))
50
def __getattr__(self, name):
51
# magic method dispatcher
52
return _Method(self.socket, name)
55
4
'''A class which privides overwritable methods to included apps.'''
57
6
'''Called when the app is loaded.'''
60
def register_app(app):
61
10
'''Registers the app as being loaded, and creates and stores the instance
62
11
to send events to. Also calls the setup method on the app object once it
63
12
is created from the provided class. `app` should be a class.
66
15
# TODO: register instance
72
if __name__ == '__main__':
73
print api.__getattr__(sys.argv[1])(*sys.argv[2:])
74
#print api.__getattr__(sys.argv[1])()
76
#print api.get_functions()