Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
for plugin in self.meta.plugins:
plugin.before_request(self)
for parameter in plugin.parameters:
del self.params[parameter[0]]
# structure parameters
self.__structure_params()
response_content = self.method(self, **self.params)
if type(response_content) == tuple:
code, content, response_content = response_content
if not c.method:
c.meta = view_func.meta
method = 'GET' if 'GET' in c.meta.http_methods else random.choice(c.meta.http_methods)
return redirect(request.url_rule.rule + '?method=' + method)
if c.method in view_func.meta.http_methods:
c.meta = view_func.meta
break
if not c.meta:
return 'Http method [%s] not support' % c.method
context = {'api_config': {}, 'api_json_p': None}
c.url = request.path
c.path = 'http://+ request.environ[HTTP_HOST] + view.uri'
c.params = get_api_params(c.meta.param_list, context.get('api_config'))
c.title = text_to_html(c.meta.title)
c.params_config = {}
c.curr_api_config = {}
for plugin in c.meta.plugins:
if isinstance(plugin, jsonp.JsonP):
c.json_p = plugin.callback_field_name
# return context
# context = {'user': user,
# 'title': 'Test UI',
# 'web_ui_uri': app.config['web_ui']['uri'],
# 'exe_ui_uri': app.config['web_ui']['exe_ui']['uri'],
# 'post_type': request.args.get('type', 'j')}
def get_api_params(param_list, config):
params = []
params_config = config['params'] if config else {}
for param in param_list:
name = param['name']
requisite = b'\xe2\x97\x8f'.decode() if param['requisite'] else ''
if param['type'].has_sub_type:
type_name = '%s[%s]' % (param['type'].__name__, param['type'].type.__name__)
type_display = '''<span>%s</span>[<span>%s</span>]''' % (
param['type'].description, param['type'].__name__,
param['type'].type.description, param['type'].type.__name__)
else:
type_name = param['type'].__name__
type_display = '''<span class="show-message">%s</span>''' % \
(text_to_html(param['type'].description), param['type'].__name__)
pure_auto = 'checked="checked"' if name in params_config and params_config[name]['pure_auto'] else ''
param_url = params_config[name]['url'] if name in params_config else ''
params.append((name, requisite, text_to_html(param['description']), type_name, type_display, pure_auto, param_url))
return params
params_config = config['params'] if config else {}
for param in param_list:
name = param['name']
requisite = b'\xe2\x97\x8f'.decode() if param['requisite'] else ''
if param['type'].has_sub_type:
type_name = '%s[%s]' % (param['type'].__name__, param['type'].type.__name__)
type_display = '''<span>%s</span>[<span>%s</span>]''' % (
param['type'].description, param['type'].__name__,
param['type'].type.description, param['type'].type.__name__)
else:
type_name = param['type'].__name__
type_display = '''<span class="show-message">%s</span>''' % \
(text_to_html(param['type'].description), param['type'].__name__)
pure_auto = 'checked="checked"' if name in params_config and params_config[name]['pure_auto'] else ''
param_url = params_config[name]['url'] if name in params_config else ''
params.append((name, requisite, text_to_html(param['description']), type_name, type_display, pure_auto, param_url))
return params
# 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
for plugin in self.meta.plugins:
plugin.before_request(self)
for parameter in plugin.parameters:
del self.params[parameter[0]]
# structure parameters
self.__structure_params()
response_content = self.method(self, **self.params)
if type(response_content) == tuple:
code, content, response_content = response_content
self.log(code, content)
else:
def get_sorted_code(self, view, method):
codes = []
is_param_type = False
for error_code in method.api.code_index:
error_message = method.api.code_dict[error_code]
if error_code.startswith('param_type_error_') and not is_param_type:
codes.append(('----', None, None))
is_param_type = True
if is_param_type and not error_code.startswith('param_type_error_'):
codes.append(('----', None, None))
is_param_type = False
codes.append((error_code, text_to_html(error_message),
self.get_exe_case(view, method, error_code)))
return codes
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
for plugin in self.element.plugins:
plugin.before_request(self)
for parameter in plugin.parameters:
del self.params[parameter[0]]
# structure parameters
self.__structure_params()
response_content = self.method(self, **self.params)
if type(response_content) == tuple:
code, content, response_content = response_content