Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def adapter(app, request):
view_func = None
views = app.api.url_map.get(request.path)
for view, support_methods in views.items():
if request.method in support_methods:
view_func = view
break
if not hasattr(view_func, 'meta'):
return Response('406 Current url not have Fair UI', status=406)
try:
# get request parameters
params = get_request_params(request)
params_proto = params.copy()
# plugin
for plugin in view_func.meta.plugins:
plugin.before_request(view_func)
for parameter in plugin.parameters:
del params[parameter[0]]
# structure parameters
params = structure_params(view_func, params_proto, params)
request.meta = view_func.meta
response_content = view_func(**params)
if isinstance(response_content, ResponseRaise):
response_content = response_content.response()
except ResponseRaise as response_raise:
response_content = response_raise.response()
def api_adapter(self):
view_func = None
views = self.api.url_map.get(request.path)
for view, support_methods in views.items():
if request.method in support_methods:
view_func = view
break
if not hasattr(view_func, 'meta'):
return Response('406 Current url not have Fair UI', status=406)
try:
request.meta = view_func.meta
# get request parameters
params = get_request_params()
params_proto = params.copy()
# plugin
for plugin in view_func.meta.plugins:
plugin.before_request(view_func.meta, params)
for parameter in plugin.parameters:
del params[parameter[0]]
# structure parameters
params = structure_params(view_func, params_proto, params)
response_content = view_func(**params)
if isinstance(response_content, ResponseRaise):
response_content = response_content.response()
except ResponseRaise as response_raise:
response_content = response_raise.response()
except Exception as e:
def __response(self, *args, **kwargs):
try:
# get request parameters
self.params = get_request_params(request)
self.params_proto = self.params.copy()
if self.params.get('__fair') == 'doc':
response_doc = None
if self.method.meta.response:
response_doc = rst_to_html(self.method.meta.response.__doc__)
return render_template('doc.html',
title='DOC UI',
api_uri=self.uri,
method=request.method,
meta=self.method.meta,
api_title=text_to_html(self.method.meta.title),
response_doc=response_doc,
description=text_to_html(self.method.meta.description))
# plugin
def __response(self, *args, **kwargs):
try:
# get request parameters
self.params = get_request_params(request)
self.params_proto = self.params.copy()
if self.params.get('__fair') == 'doc':
response_doc = None
if self.method.element.response:
response_doc = rst_to_html(self.method.element.response.__doc__)
return render_template('doc.html',
title='DOC UI',
api_uri=self.uri,
method=request.method,
element=self.method.element,
api_title=text_to_html(self.method.element.title),
response_doc=response_doc,
description=text_to_html(self.method.element.description))
# plugin