Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __parse_doc_field(self, app, method, doc_field):
name = doc_field.children[0].astext()
content = rst_to_html(doc_field.children[1].rawsource)
if name == 'response':
self.response = app.config['responses'][content]
elif name == 'plugin':
for item in content.split():
plugin = app.config['plugins'].get(item)
if not plugin:
raise Exception('%s use undefined plugin %s' % (method.__name__, item))
self.plugins.append(plugin)
self.plugin_keys.append(item)
for error_code, error_message in plugin.error_codes.items():
self.__meta_code_set(error_code, error_message, 'plugin ' + item)
elif name.startswith('raise '):
self.__meta_code_set(name[6:], content)
elif name.startswith('param '):
items = name[6:].split()
param_type = items[0]
def doc_ui():
views = app.api.url_map[request.url_rule.rule[:-5]]
apis = []
for view_func in views:
meta = view_func.meta # type: Meta
response_doc = rst_to_html(meta.response_cls.__doc__)
apis.append(ContextClass(title=text_to_html(meta.title), description=text_to_html(meta.description),
methods=meta.http_methods, meta=meta, response_doc=response_doc))
return render_template('doc.html', apis=apis) # url 为 flask 模板内置变量
def __parse_doc_tree(self, view_func, doc_tree):
if type(doc_tree) == docutils.nodes.term:
self.title = rst_to_html(doc_tree.rawsource)
return
if type(doc_tree) == docutils.nodes.paragraph:
if self.description is None:
self.title = self.title + rst_to_html(doc_tree.rawsource)
self.description = ''
elif self.description == '':
self.description = rst_to_html(doc_tree.rawsource)
else:
self.description = self.description + os.linesep * 2 + rst_to_html(doc_tree.rawsource)
return
if type(doc_tree) == docutils.nodes.field:
self.__parse_doc_field(view_func, doc_tree)
return
for item in doc_tree.children:
self.__parse_doc_tree(view_func, item)
def __parse_doc_tree(self, view_func, doc_tree):
if type(doc_tree) == docutils.nodes.term:
self.title = rst_to_html(doc_tree.rawsource)
return
if type(doc_tree) == docutils.nodes.paragraph:
if self.description is None:
self.title = self.title + rst_to_html(doc_tree.rawsource)
self.description = ''
elif self.description == '':
self.description = rst_to_html(doc_tree.rawsource)
else:
self.description = self.description + os.linesep * 2 + rst_to_html(doc_tree.rawsource)
return
if type(doc_tree) == docutils.nodes.field:
self.__parse_doc_field(view_func, doc_tree)
return
def __parse_doc_tree(self, view_func, doc_tree):
if type(doc_tree) == docutils.nodes.term:
self.title = rst_to_html(doc_tree.rawsource)
return
if type(doc_tree) == docutils.nodes.paragraph:
if self.description is None:
self.title = self.title + rst_to_html(doc_tree.rawsource)
self.description = ''
elif self.description == '':
self.description = rst_to_html(doc_tree.rawsource)
else:
self.description = self.description + os.linesep * 2 + rst_to_html(doc_tree.rawsource)
return
if type(doc_tree) == docutils.nodes.field:
self.__parse_doc_field(view_func, doc_tree)
return
for item in doc_tree.children:
self.__parse_doc_tree(view_func, item)
def __parse_doc_tree(self, app, method, doc_tree):
if type(doc_tree) == docutils.nodes.term:
self.title = rst_to_html(doc_tree.rawsource)
return
if type(doc_tree) == docutils.nodes.paragraph:
if self.description is None:
self.title = self.title + rst_to_html(doc_tree.rawsource)
self.description = ''
elif self.description == '':
self.description = rst_to_html(doc_tree.rawsource)
else:
self.description = self.description + os.linesep * 2 + rst_to_html(doc_tree.rawsource)
return
if type(doc_tree) == docutils.nodes.field:
self.__parse_doc_field(app, method, doc_tree)
return
def __parse_doc_tree(self, view_func, doc_tree):
if type(doc_tree) == docutils.nodes.term:
self.title = rst_to_html(doc_tree.rawsource)
return
if type(doc_tree) == docutils.nodes.paragraph:
if self.description is None:
self.title = self.title + rst_to_html(doc_tree.rawsource)
self.description = ''
elif self.description == '':
self.description = rst_to_html(doc_tree.rawsource)
else:
self.description = self.description + os.linesep * 2 + rst_to_html(doc_tree.rawsource)
return
if type(doc_tree) == docutils.nodes.field:
self.__parse_doc_field(view_func, doc_tree)
return
for item in doc_tree.children:
self.__parse_doc_tree(view_func, item)
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