本文整理匯總了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