Beispiel #1
0
def main():
    # Must have at least one application
    app = WebApplication()

    # Generate index.html from index.enaml
    with open('index.html', 'wb') as f:
        f.write(Index().render())
Beispiel #2
0
def run():
    # Needed to create enaml components
    enaml_app = WebApplication()

    # Start the tornado app
    app = tornado.web.Application([
        (r'/', ViewerHandler),
        (r'/websocket/', ViewerWebSocket),
        (r'/static/(.*)', tornado.web.StaticFileHandler, {
            'path': os.path.dirname(__file__)
        }),
    ])
    app.listen(4040)
    tornado.ioloop.IOLoop.current().start()
Beispiel #3
0
    async def __setstate__(self, state, scope=None):
        """ Restore an object from the a state from the database. This is
        async as it will lookup any referenced objects from the DB.
        
        """
        unflatten = self.serializer.unflatten
        name = state.get('__model__')

        if name is None:
            raise ValueError("State must contain the __model__ key")
        if name != self.__model__:
            raise ValueError(f"Trying to use {name} state for "
                             f"{self.__model__} object")
        scope = scope or {}
        ref = state.pop('__ref__', None)
        if ref is not None:
            scope[ref] = self
        members = self.members()
        for k, v in state.items():
            
            # Don't use getattr because it triggers a default value lookup
            if members.get(k):
                try:
                    obj = await unflatten(v, scope)
                    setattr(self, k, obj)
                except Exception as e:
                    exc = traceback.format_exc()
                    WebApplication.instance().logger.error(
                        f"Error setting state:"
                        f"{self.__model__}.{k} = {pformat(obj)}:"
                        f"\nSelf: {ref}: {scope.get(ref)}"
                        f"\nValue: {pformat(v)}"
                        f"\nScope: {pformat(scope)}"
                        f"\nState: {pformat(state)}"
                        f"\n{exc}"
                    )
Beispiel #4
0
def run():
    # Needed to create enaml components
    enaml_app = WebApplication()

    log.setLevel('DEBUG')

    # Start the tornado app
    app = tornado.web.Application([
        (r'/', ViewerHandler),
        (r'/websocket/', ViewerWebSocket),
        (r'/static/(.*)', tornado.web.StaticFileHandler, {
            'path': os.path.dirname(__file__)
        }),
    ])
    app.listen(int(os.environ.get('PORT', 5000)))
    tornado.ioloop.IOLoop.current().start()
Beispiel #5
0
def run_web_app():
    enaml_app = WebApplication()
    # Start the tornado app
    app = tornado.web.Application(
        [
            (r"/", ViewerHandler),
            (r"/datas", DatasHandler),
            (r"/ws", WsHandler),
            (r"/static/(.*)", StaticFiles, {
                "path": "static/"
            }),
        ],
        debug=True,
    )
    app.listen(8888)

    io_loop = tornado.ioloop.IOLoop.current()
    io_loop.start()
Beispiel #6
0
def run():
    # Python3.8 win32;
    asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())

    enable_pretty_logging()
    # Needed to create enaml components
    enaml_app = WebApplication()

    # Start the tornado app
    app = tornado.web.Application([
        (r'/', ViewerHandler),
        (r'/websocket/', ViewerWebSocket),
        (r'/static/(.*)', tornado.web.StaticFileHandler, {
            'path': os.path.dirname(__file__)
        }),
    ],
                                  debug=True)
    app.listen(8888)
    tornado.ioloop.IOLoop.current().start()
Beispiel #7
0
def app():
    from web.core.app import WebApplication
    app = WebApplication.instance() or WebApplication()
    yield app
Beispiel #8
0
def app():
    app = WebApplication.instance() or WebApplication()
    yield app
Beispiel #9
0
def app(event_loop):
    client = AsyncIOMotorClient(io_loop=event_loop)
    app = WebApplication.instance() or WebApplication()
    db = client.enaml_web_test_db
    app.database = db
    yield app
Beispiel #10
0
 def _get_database(self):
     db =  WebApplication.instance().database
     if db is None:
         raise EnvironmentError("No database set!")
     return db
Beispiel #11
0
def app(event_loop):
    app = WebApplication.instance() or WebApplication()
    yield app