Skip to content

Instantly share code, notes, and snippets.

@mguijarr
Created November 7, 2016 09:34
Show Gist options
  • Save mguijarr/b7592758be44e5b38c8e9e1b1d8ee2cc to your computer and use it in GitHub Desktop.
Save mguijarr/b7592758be44e5b38c8e9e1b1d8ee2cc to your computer and use it in GitHub Desktop.
Example of a Python spec server to be able to execute commands from spec in a comfortable way
from SpecClient_gevent.SpecServer import SpecServer, BaseSpecRequestHandler
import time
class MyRequestHandler(BaseSpecRequestHandler):
FUNCTIONS_CONTAINER = None
def __getattr__(self, attr):
if attr.startswith("__"):
raise AttributeError(attr)
return getattr(MyRequestHandler.FUNCTIONS_CONTAINER, attr)
def dispatchIncomingMessage(self, m):
if m.cmd in (3,4):
self.executeCommandAndReply(m.sn, m.data)
return True
return False
class MyFakeSpecServer(SpecServer):
def __init__(self, host, session_name):
SpecServer.__init__(self, host, session_name, handler=MyRequestHandler)
class MyFunctions:
def __init__(self):
pass
def do_something(self):
time.sleep(2)
return 'hello'
srv = MyFakeSpecServer('0.0.0.0', 'fake')
MyRequestHandler.FUNCTIONS_CONTAINER = MyFunctions()
srv.serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment