Exemple #1
0
 def __construct_api_files():
     if not utils.are_we_frozen():
         HubsInspector.construct_js_file(path=os.path.join(
             "libs", "WSCommunication", "Clients", "hubsApi.js"))
         HubsInspector.construct_js_file(
             path=os.path.join(os.pardir, "demo", "_static", "hubsApi.js"))
         HubsInspector.construct_python_file(path=os.path.join(
             "libs", "WSCommunication", "Clients", "hubs_api.py"))
    def test_JSCreation_withClientFunctions(self):
        class TestHubWithClient(Hub):
            def get_data(self):
                pass

            def _define_client_functions(self):
                return dict(client1=lambda x, y: None,
                            client2=lambda x, y=1: None,
                            client3=lambda x=0, y=1: None)

        HubsInspector.inspect_implemented_hubs(force_reconstruction=True)
        HubsInspector.construct_js_file()

        self.assertTrue(os.path.exists(HubsInspector.DEFAULT_JS_API_FILE_NAME))
import os
import logging.config
import json
from tornado import web, ioloop

from wshubsapi.hubs_inspector import HubsInspector
from wshubsapi.connection_handlers.tornado_handler import ConnectionHandler

logging.config.dictConfig(json.load(open('logging.json')))
log = logging.getLogger(__name__)

settings = {"static_path": os.path.join(os.path.dirname(__file__), "../Clients/_static")}

app = web.Application([
    (r'/(.*)', ConnectionHandler),
], **settings)

if __name__ == '__main__':
    HubsInspector.include_hubs_in("*_hub.py")  # use glob path patterns
    HubsInspector.inspect_implemented_hubs()
    HubsInspector.construct_js_file(settings["static_path"] + os.sep + "hubsApi.js")
    HubsInspector.construct_python_file(settings["static_path"] + os.sep + "hubs_api.py")
    HubsInspector.construct_dart_file(settings["static_path"] + os.sep + "hubs_api.dart")
    log.debug("starting...")
    app.listen(8888)

    ioloop.IOLoop.instance().start()
Exemple #4
0
 def __construct_api_files():
     if not utils.are_we_frozen():
         HubsInspector.construct_js_file(path=os.path.join("libs", "WSCommunication", "Clients", "hubsApi.js"))
         HubsInspector.construct_js_file(path=os.path.join(os.pardir, "demo", "_static", "hubsApi.js"))
         HubsInspector.construct_python_file(path=os.path.join("libs", "WSCommunication", "Clients", "hubs_api.py"))
from wsgiref.simple_server import make_server

from ws4py.server.wsgirefserver import WSGIServer, WebSocketWSGIRequestHandler
from ws4py.server.wsgiutils import WebSocketWSGIApplication

from wshubsapi.connection_handlers.ws4py_handler import ConnectionHandler
from wshubsapi.hubs_inspector import HubsInspector

if __name__ == '__main__':
    HubsInspector.include_hubs_in("*_hub.py")  # use glob path patterns
    HubsInspector.inspect_implemented_hubs()  # setup api
    HubsInspector.construct_python_file("../Clients/_static/hubs_api.py")  # only if you will use a python client
    HubsInspector.construct_js_file("../Clients/_static/hubsApi.js")  # only if you will use a js client

    server = make_server('127.0.0.1', 8888, server_class=WSGIServer,
                         handler_class=WebSocketWSGIRequestHandler,
                         app=WebSocketWSGIApplication(handler_cls=ConnectionHandler))
    server.initialize_websockets_manager()
    server.serve_forever()
    def test_JSCreation_new_path(self):
        full_path = os.path.join(self.other_folder, self.other_name)
        HubsInspector.construct_js_file(full_path)

        self.assertTrue(os.path.exists(full_path))
    def test_JSCreation_default_path(self):
        HubsInspector.construct_js_file()

        self.assertTrue(os.path.exists(HubsInspector.DEFAULT_JS_API_FILE_NAME))
import SocketServer
import importlib
import logging
from wshubsapi.connection_handlers.request_handler import SimpleRequestHandler
from wshubsapi.hubs_inspector import HubsInspector

logging.basicConfig(level=logging.DEBUG)
log = logging.getLogger("_server_")

httpd = SocketServer.TCPServer(("localhost", 8888), SimpleRequestHandler)

log.debug("listening...")

HubsInspector.include_hubs_in("*_hub.py")  # use glob path patterns
HubsInspector.inspect_implemented_hubs()
HubsInspector.construct_js_file("../Clients/_static/hubsApi.js")
HubsInspector.construct_python_file("../Clients/_static/hubs_api.py")
httpd.serve_forever()
Exemple #9
0
class MyConnectionHandler(ConnectionHandler):
    executor = ThreadPoolExecutor()

    def open(self, name=None):
        client_id = name
        if client_id in self.comm_environment.all_connected_clients:
            self.comm_environment.all_connected_clients.pop(client_id)
            try:
                self.close()
            except Exception:
                pass
        self.comm_environment.on_opened(self._connected_client, client_id)

        log.debug("open new connection with ID: {} ".format(client_id))

    def on_message(self, message):
        self.executor.submit(super().on_message, message)


if __name__ == '__main__':
    app = web.Application([
        (r'/(.*)', MyConnectionHandler),
    ])
    HubsInspector.include_hubs_in("**/*_hub.py")  # use glob path patterns
    HubsInspector.inspect_implemented_hubs()
    HubsInspector.construct_js_file("../web_client/services/hubsApi.js")
    log.debug("starting...")
    app.listen(8888)

    ioloop.IOLoop.instance().start()