Example #1
0
    def __init__(self,
                 routes: List[routing.Route] = None,
                 commands: List[Callable] = None,
                 settings: Dict[str, Any] = None) -> None:
        from apistar.settings import Settings
        from apistar.templating import Templates
        from apistar.backends.sqlalchemy import SQLAlchemy

        routes = [] if (routes is None) else routes
        commands = [] if (commands is None) else commands

        self.routes = routes
        self.commands = list(self.built_in_commands) + commands
        self.settings = Settings(settings or {})

        initial_types = [App]  # type: List[type]
        self.preloaded = {
            'app': self
        }
        if 'TEMPLATES' in self.settings:
            initial_types.append(Templates)
            self.preloaded['templates'] = Templates.build(self.settings)
        if 'DATABASE' in self.settings:
            initial_types.append(SQLAlchemy)
            self.preloaded['sql_alchemy'] = SQLAlchemy.build(self.settings)
            self.commands += [cmd.create_tables]

        self.router = routing.Router(self.routes, initial_types)
        self.wsgi = get_wsgi_server(app=self)
        self.click = get_click_client(app=self)
Example #2
0
    def __init__(self,
                 routes: routing.RoutesConfig = None,
                 commands: List[Callable] = None,
                 settings: Dict[str, Any] = None) -> None:
        from apistar.settings import Settings
        initial_types = [App, routing.Router]  # type: List[type]

        routes = [] if (routes is None) else routes
        commands = [] if (commands is None) else commands

        self.routes = routes
        self.commands = list(self.built_in_commands) + commands
        self.settings = Settings(settings or {})
        self.router = routing.Router(self.routes, initial_types)

        self.preloaded = {
            'app': self,
            'router': self.router,
        }
        preload_state(self.preloaded, self.routes)
        if 'sql_alchemy' in self.preloaded:
            self.commands += [cmd.create_tables]

        self.wsgi = get_wsgi_server(app=self)
        self.click = get_click_client(app=self)
Example #3
0
    def __init__(self, routes=None, commands=None):
        routes = [] if (routes is None) else routes
        commands = [] if (commands is None) else commands

        self.routes = routes
        self.commands = list(self.built_in_commands) + commands

        self.router = routing.Router(self.routes)
        self.wsgi = get_wsgi_server(app=self)
        self.click = get_click_client(app=self)