Пример #1
0
from werkzeug.http import HTTP_STATUS_CODES

from apistar import commands, exceptions, http
from apistar.components import (commandline, console, dependency, router,
                                schema, sessions, statics, templates, wsgi)
from apistar.core import Command, Component
from apistar.frameworks.cli import CliApp
from apistar.interfaces import (CommandLineClient, Console, FileWrapper,
                                Injector, Router, Schema, SessionStore,
                                StaticFiles, Templates)
from apistar.types import KeywordArgs, ReturnValue, WSGIEnviron

STATUS_TEXT = {
    code: "%d %s" % (code, msg)
    for code, msg in HTTP_STATUS_CODES.items()
}


class WSGIApp(CliApp):
    INJECTOR_CLS = dependency.DependencyInjector

    BUILTIN_COMMANDS = [
        Command('new', commands.new),
        Command('run', commands.run_wsgi),
        Command('schema', commands.schema),
        Command('test', commands.test)
    ]

    BUILTIN_COMPONENTS = [
        Component(Schema, init=schema.CoreAPISchema),
Пример #2
0
from typing import Iterable, List, Tuple

from werkzeug.http import HTTP_STATUS_CODES

from apistar import http

__all__ = ['WSGIEnviron', 'WSGIResponse']


STATUS_CODES = {
    code: "%d %s" % (code, msg)
    for code, msg in HTTP_STATUS_CODES.items()
}

ACCESS_CONTROL_ALLOW_ORIGIN = 'Access-Control-Allow-Origin'

WSGIEnviron = http.WSGIEnviron


class WSGIResponse(object):
    __slots__ = ('status', 'headers', 'iterator')

    def __init__(self,
                 status: str,
                 headers: List[Tuple[str, str]],
                 iterator: Iterable[bytes]) -> None:
        self.status = status
        self.headers = headers
        self.iterator = iterator

    @classmethod