本文整理匯總了Python中aiohttp_cors.setup方法的典型用法代碼示例。如果您正苦於以下問題:Python aiohttp_cors.setup方法的具體用法?Python aiohttp_cors.setup怎麽用?Python aiohttp_cors.setup使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類aiohttp_cors
的用法示例。
在下文中一共展示了aiohttp_cors.setup方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _init_subapp
# 需要導入模塊: import aiohttp_cors [as 別名]
# 或者: from aiohttp_cors import setup [as 別名]
def _init_subapp(pkg_name: str,
root_app: web.Application,
subapp: web.Application,
global_middlewares: Iterable[WebMiddleware]) -> None:
subapp.on_response_prepare.append(on_prepare)
async def _copy_public_interface_objs(subapp: web.Application):
# Allow subapp's access to the root app properties.
# These are the public APIs exposed to plugins as well.
for key, obj in public_interface_objs.items():
subapp[key] = obj
# We must copy the public interface prior to all user-defined startup signal handlers.
subapp.on_startup.insert(0, _copy_public_interface_objs)
prefix = subapp.get('prefix', pkg_name.split('.')[-1].replace('_', '-'))
aiojobs.aiohttp.setup(subapp, **root_app['scheduler_opts'])
root_app.add_subapp('/' + prefix, subapp)
root_app.middlewares.extend(global_middlewares)
示例2: create_app
# 需要導入模塊: import aiohttp_cors [as 別名]
# 或者: from aiohttp_cors import setup [as 別名]
def create_app(default_cors_options: CORSOptions) -> Tuple[web.Application, Iterable[WebMiddleware]]:
app = web.Application()
app['prefix'] = 'auth' # slashed to distinguish with "/vN/authorize"
app['api_versions'] = (1, 2, 3, 4)
cors = aiohttp_cors.setup(app, defaults=default_cors_options)
root_resource = cors.add(app.router.add_resource(r''))
cors.add(root_resource.add_route('GET', test))
cors.add(root_resource.add_route('POST', test))
test_resource = cors.add(app.router.add_resource('/test'))
cors.add(test_resource.add_route('GET', test))
cors.add(test_resource.add_route('POST', test))
cors.add(app.router.add_route('POST', '/authorize', authorize))
cors.add(app.router.add_route('GET', '/role', get_role))
cors.add(app.router.add_route('POST', '/signup', signup))
cors.add(app.router.add_route('POST', '/signout', signout))
cors.add(app.router.add_route('POST', '/update-password', update_password))
cors.add(app.router.add_route('GET', '/ssh-keypair', get_ssh_keypair))
cors.add(app.router.add_route('PATCH', '/ssh-keypair', refresh_ssh_keypair))
return app, [auth_middleware]
示例3: create_app
# 需要導入模塊: import aiohttp_cors [as 別名]
# 或者: from aiohttp_cors import setup [as 別名]
def create_app(default_cors_options: CORSOptions) -> Tuple[web.Application, Iterable[WebMiddleware]]:
app = web.Application()
app.on_startup.append(init)
app.on_shutdown.append(shutdown)
app['api_versions'] = (1, 2, 3, 4)
cors = aiohttp_cors.setup(app, defaults=default_cors_options)
cors.add(app.router.add_route('POST', '/_/create-from-template', create_from_template))
cors.add(app.router.add_route('GET', '/_/match', match_sessions))
cors.add(app.router.add_route('POST', '', create_from_params))
session_resource = cors.add(app.router.add_resource(r'/{session_name}'))
cors.add(session_resource.add_route('GET', get_info))
cors.add(session_resource.add_route('PATCH', restart))
cors.add(session_resource.add_route('DELETE', destroy))
cors.add(session_resource.add_route('POST', execute))
task_log_resource = cors.add(app.router.add_resource(r'/_/logs'))
cors.add(task_log_resource.add_route('HEAD', get_task_logs))
cors.add(task_log_resource.add_route('GET', get_task_logs))
cors.add(app.router.add_route('GET', '/{session_name}/logs', get_container_logs))
cors.add(app.router.add_route('POST', '/{session_name}/interrupt', interrupt))
cors.add(app.router.add_route('POST', '/{session_name}/complete', complete))
cors.add(app.router.add_route('POST', '/{session_name}/upload', upload_files))
cors.add(app.router.add_route('GET', '/{session_name}/download', download_files))
cors.add(app.router.add_route('GET', '/{session_name}/download_single', download_single))
cors.add(app.router.add_route('GET', '/{session_name}/files', list_files))
return app, []
示例4: create_app
# 需要導入模塊: import aiohttp_cors [as 別名]
# 或者: from aiohttp_cors import setup [as 別名]
def create_app(default_cors_options: CORSOptions) -> Tuple[web.Application, Iterable[WebMiddleware]]:
app = web.Application()
app['api_versions'] = (4,)
cors = aiohttp_cors.setup(app, defaults=default_cors_options)
add_route = app.router.add_route
cors.add(add_route('GET', '/presets', list_presets))
cors.add(add_route('POST', '/check-presets', check_presets))
cors.add(add_route('POST', '/recalculate-usage', recalculate_usage))
cors.add(add_route('GET', '/usage/month', usage_per_month))
cors.add(add_route('GET', '/usage/period', usage_per_period))
cors.add(add_route('GET', '/stats/user/month', user_month_stats))
cors.add(add_route('GET', '/stats/admin/month', admin_month_stats))
cors.add(add_route('GET', '/watcher', get_watcher_status))
cors.add(add_route('POST', '/watcher/agent/start', watcher_agent_start))
cors.add(add_route('POST', '/watcher/agent/stop', watcher_agent_stop))
cors.add(add_route('POST', '/watcher/agent/restart', watcher_agent_restart))
return app, []
示例5: start
# 需要導入模塊: import aiohttp_cors [as 別名]
# 或者: from aiohttp_cors import setup [as 別名]
def start(self):
app = web.Application(client_max_size=JSON_RPC_CLIENT_REQUEST_MAX_SIZE)
cors = aiohttp_cors.setup(app)
route = app.router.add_post("/", self.__handle)
cors.add(
route,
{
"*": aiohttp_cors.ResourceOptions(
allow_credentials=True,
expose_headers=("X-Custom-Server-Header",),
allow_methods=["POST", "PUT"],
allow_headers=("X-Requested-With", "Content-Type"),
)
},
)
self.runner = web.AppRunner(app, access_log=None)
self.loop.run_until_complete(self.runner.setup())
site = web.TCPSite(self.runner, self.host, self.port)
self.loop.run_until_complete(site.start())
示例6: add_routes
# 需要導入模塊: import aiohttp_cors [as 別名]
# 或者: from aiohttp_cors import setup [as 別名]
def add_routes(app, with_ui=False):
{# URLs are traverse in reversed sorted order so that longer ones are evaluated first #}
{% for relative_url, class_name in entries|dictsort(true)|reverse %}
app.router.add_view(r"/{{ relative_url }}", views.{{ class_name }})
{% endfor %}
if with_ui:
app.router.add_view(r"/the_specification", views.__SWAGGER_SPEC__)
app.router.add_static(r"/ui", path="ui")
# Configure default CORS settings.
cors = aiohttp_cors.setup(app, defaults={
"*": aiohttp_cors.ResourceOptions(
allow_credentials=True,
expose_headers="*",
allow_headers="*",
)
})
# Configure CORS on all routes.
for route in app.router.routes():
cors.add(route)
示例7: make_app
# 需要導入模塊: import aiohttp_cors [as 別名]
# 或者: from aiohttp_cors import setup [as 別名]
def make_app(request):
def inner(defaults, route_config):
app = web.Application()
cors = _setup(app, defaults=defaults)
if request.param == 'resource':
resource = cors.add(app.router.add_resource("/resource"))
cors.add(resource.add_route("GET", handler), route_config)
elif request.param == 'view':
WebViewHandler.cors_config = route_config
cors.add(
app.router.add_route("*", "/resource", WebViewHandler))
elif request.param == 'route':
cors.add(
app.router.add_route("GET", "/resource", handler),
route_config)
else:
raise RuntimeError('unknown parameter {}'.format(request.param))
return app
return inner
示例8: __init__
# 需要導入模塊: import aiohttp_cors [as 別名]
# 或者: from aiohttp_cors import setup [as 別名]
def __init__(self, bot: Bot, host: str, port: int):
self.bot = bot
self.app = web.Application(middlewares=[web.normalize_path_middleware()])
self.app.add_routes([
web.post('/callback', self.callback)
])
cors = aiohttp_cors.setup(self.app, defaults={
"*": aiohttp_cors.ResourceOptions(
allow_credentials=True,
expose_headers="*",
allow_headers="*",
)
})
ufw_resource = cors.add(self.app.router.add_resource("/ufw/{wallet}"))
cors.add(ufw_resource.add_route("GET", self.ufw))
wfu_resource = cors.add(self.app.router.add_resource("/wfu/{user}"))
cors.add(wfu_resource.add_route("GET", self.wfu))
users_resource = cors.add(self.app.router.add_resource("/users"))
cors.add(users_resource.add_route("GET", self.users))
self.logger = logging.getLogger()
self.host = host
self.port = port
self.min_amount = 10 if Env.banano() else 0.1
示例9: make_app
# 需要導入模塊: import aiohttp_cors [as 別名]
# 或者: from aiohttp_cors import setup [as 別名]
def make_app() -> web.Application:
app = web.Application()
executor = ProcessPoolExecutor()
cors = aiohttp_cors.setup(app)
resource = cors.add(app.router.add_resource("/"))
cors.add(
resource.add_route("POST", partial(handle, executor=executor)),
{
"*": aiohttp_cors.ResourceOptions(
allow_headers=(*BLACK_HEADERS, "Content-Type"), expose_headers="*"
)
},
)
return app
示例10: manager_status_ctx
# 需要導入模塊: import aiohttp_cors [as 別名]
# 或者: from aiohttp_cors import setup [as 別名]
def manager_status_ctx(app: web.Application) -> AsyncIterator[None]:
if app['pidx'] == 0:
mgr_status = await app['config_server'].get_manager_status()
if mgr_status is None or mgr_status not in (ManagerStatus.RUNNING, ManagerStatus.FROZEN):
# legacy transition: we now have only RUNNING or FROZEN for HA setup.
await app['config_server'].update_manager_status(ManagerStatus.RUNNING)
mgr_status = ManagerStatus.RUNNING
log.info('Manager status: {}', mgr_status)
tz = app['config']['system']['timezone']
log.info('Configured timezone: {}', tz.tzname(datetime.now()))
yield
示例11: create_app
# 需要導入模塊: import aiohttp_cors [as 別名]
# 或者: from aiohttp_cors import setup [as 別名]
def create_app(default_cors_options: CORSOptions) -> Tuple[web.Application, Iterable[WebMiddleware]]:
app = web.Application()
app.cleanup_ctx.append(stream_app_ctx)
app['prefix'] = 'stream'
app['api_versions'] = (2, 3, 4)
cors = aiohttp_cors.setup(app, defaults=default_cors_options)
add_route = app.router.add_route
cors.add(add_route('GET', r'/session/{session_name}/pty', stream_pty))
cors.add(add_route('GET', r'/session/{session_name}/execute', stream_execute))
cors.add(add_route('GET', r'/session/{session_name}/apps', get_stream_apps))
# internally both tcp/http proxies use websockets as API/agent-level transports,
# and thus they have the same implementation here.
cors.add(add_route('GET', r'/session/{session_name}/httpproxy', stream_proxy))
cors.add(add_route('GET', r'/session/{session_name}/tcpproxy', stream_proxy))
return app, []
示例12: create_app
# 需要導入模塊: import aiohttp_cors [as 別名]
# 或者: from aiohttp_cors import setup [as 別名]
def create_app(default_cors_options: CORSOptions) -> Tuple[web.Application, Iterable[WebMiddleware]]:
app = web.Application()
app.on_startup.append(init)
app.on_shutdown.append(shutdown)
app['prefix'] = 'image'
app['api_versions'] = (4,)
cors = aiohttp_cors.setup(app, defaults=default_cors_options)
cors.add(app.router.add_route('GET', '/import', get_import_image_form))
cors.add(app.router.add_route('POST', '/import', import_image))
return app, []
示例13: create_app
# 需要導入模塊: import aiohttp_cors [as 別名]
# 或者: from aiohttp_cors import setup [as 別名]
def create_app(default_cors_options: CORSOptions) -> Tuple[web.Application, Iterable[WebMiddleware]]:
app = web.Application()
app.cleanup_ctx.append(app_ctx)
app['prefix'] = 'config'
app['api_versions'] = (3, 4)
cors = aiohttp_cors.setup(app, defaults=default_cors_options)
cors.add(app.router.add_route('GET', r'/resource-slots', get_resource_slots))
cors.add(app.router.add_route('GET', r'/vfolder-types', get_vfolder_types))
cors.add(app.router.add_route('GET', r'/docker-registries', get_docker_registries))
cors.add(app.router.add_route('POST', r'/get', get_config))
cors.add(app.router.add_route('POST', r'/set', set_config))
cors.add(app.router.add_route('POST', r'/delete', delete_config))
return app, []
示例14: create_app
# 需要導入模塊: import aiohttp_cors [as 別名]
# 或者: from aiohttp_cors import setup [as 別名]
def create_app(default_cors_options: CORSOptions) -> Tuple[web.Application, Iterable[WebMiddleware]]:
app = web.Application()
app['api_versions'] = (2, 3, 4)
cors = aiohttp_cors.setup(app, defaults=default_cors_options)
status_resource = cors.add(app.router.add_resource('/status'))
cors.add(status_resource.add_route('GET', fetch_manager_status))
cors.add(status_resource.add_route('PUT', update_manager_status))
announcement_resource = cors.add(app.router.add_resource('/announcement'))
cors.add(announcement_resource.add_route('GET', get_announcement))
cors.add(announcement_resource.add_route('POST', update_announcement))
cors.add(app.router.add_route('POST', '/scheduler/operation', perform_scheduler_ops))
app.on_startup.append(init)
app.on_shutdown.append(shutdown)
return app, []
示例15: create_app
# 需要導入模塊: import aiohttp_cors [as 別名]
# 或者: from aiohttp_cors import setup [as 別名]
def create_app(default_cors_options: CORSOptions) -> Tuple[web.Application, Iterable[WebMiddleware]]:
app = web.Application()
app.on_startup.append(init)
app.on_shutdown.append(shutdown)
app['api_versions'] = (4, 5)
app['prefix'] = 'user-config'
cors = aiohttp_cors.setup(app, defaults=default_cors_options)
cors.add(app.router.add_route('POST', '/dotfiles', create))
cors.add(app.router.add_route('GET', '/dotfiles', list_or_get))
cors.add(app.router.add_route('PATCH', '/dotfiles', update))
cors.add(app.router.add_route('DELETE', '/dotfiles', delete))
cors.add(app.router.add_route('POST', '/bootstrap-script', update_bootstrap_script))
cors.add(app.router.add_route('GET', '/bootstrap-script', get_bootstrap_script))
return app, []