本文整理汇总了Python中starlette.routing.Route方法的典型用法代码示例。如果您正苦于以下问题:Python routing.Route方法的具体用法?Python routing.Route怎么用?Python routing.Route使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类starlette.routing
的用法示例。
在下文中一共展示了routing.Route方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_webgear_routes
# 需要导入模块: from starlette import routing [as 别名]
# 或者: from starlette.routing import Route [as 别名]
def test_webgear_routes():
"""
Test for WebGear API's custom routes
"""
try:
# add various performance tweaks as usual
options = {
"frame_size_reduction": 40,
"frame_jpeg_quality": 80,
"frame_jpeg_optimize": True,
"frame_jpeg_progressive": False,
}
# initialize WebGear app
web = WebGear(
source=return_testvideo_path(), logging=True, **options
)
# modify route to point our rendered webpage
web.routes.append(Route("/hello", endpoint=hello_webpage))
# test
client = TestClient(web(), raise_server_exceptions=True)
response = client.get("/")
assert response.status_code == 200
response_hello = client.get("/hello")
assert response_hello.status_code == 200
web.shutdown()
except Exception as e:
pytest.fail(str(e))
示例2: _create_starlette_app
# 需要导入模块: from starlette import routing [as 别名]
# 或者: from starlette.routing import Route [as 别名]
def _create_starlette_app():
def home(_):
return PlainTextResponse("hi")
app = applications.Starlette(
routes=[Route("/foobar", home), Route("/user/{username}", home)]
)
return app
示例3: __init__
# 需要导入模块: from starlette import routing [as 别名]
# 或者: from starlette.routing import Route [as 别名]
def __init__(
self,
*,
engine: Engine = None,
sdl: str = None,
graphiql: typing.Union[None, bool, GraphiQL] = True,
path: str = "/",
subscriptions: typing.Union[bool, Subscriptions] = None,
context: dict = None,
schema_name: str = "default",
) -> None:
if engine is None:
assert sdl, "`sdl` expected if `engine` not given"
engine = Engine(sdl=sdl, schema_name=schema_name)
assert engine, "`engine` expected if `sdl` not given"
self.engine = engine
if context is None:
context = {}
if graphiql is True:
graphiql = GraphiQL()
elif not graphiql:
graphiql = None
assert graphiql is None or isinstance(graphiql, GraphiQL)
if subscriptions is True:
subscriptions = Subscriptions(path="/subscriptions")
elif not subscriptions:
subscriptions = None
assert subscriptions is None or isinstance(subscriptions, Subscriptions)
routes: typing.List[BaseRoute] = []
if graphiql and graphiql.path is not None:
routes.append(Route(graphiql.path, GraphiQLEndpoint))
routes.append(Route(path, GraphQLEndpoint))
if subscriptions is not None:
routes.append(WebSocketRoute(subscriptions.path, SubscriptionEndpoint))
self.router = Router(routes=routes, on_startup=[self.startup])
config = GraphQLConfig(
engine=self.engine,
context=context,
graphiql=graphiql,
path=path,
subscriptions=subscriptions,
)
self.app = GraphQLMiddleware(self.router, config=config)
self._started_up = False