def make_rst(self): app = import_object(self.arguments[0]) for method, path, endpoint in get_routes(app): try: blueprint, endpoint_internal = endpoint.split('.') if blueprint in self.undoc_blueprints: continue except ValueError: pass # endpoint is not within a blueprint if self.endpoints and endpoint not in self.endpoints: continue if endpoint in self.undoc_endpoints: continue try: static_url_path = app.static_url_path # Flask 0.7 or higher except AttributeError: static_url_path = app.static_path # Flask 0.6 or under if ('undoc-static' in self.options and endpoint == 'static' and path == static_url_path + '/(path:filename)'): continue view = app.view_functions[endpoint] docstring = view.__doc__ or '' if hasattr(view, 'view_class'): meth_func = getattr(view.view_class, method.lower(), None) if meth_func and meth_func.__doc__: docstring = meth_func.__doc__ if not isinstance(docstring, unicode): analyzer = ModuleAnalyzer.for_module(view.__module__) docstring = force_decode(docstring, analyzer.encoding) if not docstring and 'include-empty-docstring' not in self.options: continue docstring = prepare_docstring(docstring) for line in http_directive(method, path, docstring): yield line
def make_rst(self): app = import_object(self.arguments[0]) if self.endpoints: routes = itertools.chain( *[get_routes(app, endpoint) for endpoint in self.endpoints]) else: routes = get_routes(app) # sort by path then method for method, paths, endpoint in sorted(routes, key=operator.itemgetter(1, 0)): if endpoint in self.undoc_endpoints: continue view = app._endpoints[endpoint] docstring = view.__doc__ or '' if hasattr(view, 'view_class'): meth_func = getattr(view.view_class, method.lower(), None) if meth_func and meth_func.__doc__: docstring = meth_func.__doc__ if not isinstance(docstring, six.text_type): analyzer = ModuleAnalyzer.for_module(view.__module__) docstring = force_decode(docstring, analyzer.encoding) if not docstring and 'include-empty-docstring' not in self.options: continue docstring = self.fix_docstring(docstring) docstring = prepare_docstring(docstring) for line in http_directive(method, paths, docstring): yield line
def make_rst(self, qref=False): app = import_object(self.arguments[0]) if self.endpoints: routes = itertools.chain(*[ get_routes(app, endpoint, self.order) for endpoint in self.endpoints ]) else: routes = get_routes(app, order=self.order) for method, paths, endpoint in routes: try: blueprint, _, endpoint_internal = endpoint.rpartition('.') if self.blueprints and blueprint not in self.blueprints: continue if blueprint in self.undoc_blueprints: continue except ValueError: pass # endpoint is not within a blueprint if endpoint in self.undoc_endpoints: continue try: static_url_path = app.static_url_path # Flask 0.7 or higher except AttributeError: static_url_path = app.static_path # Flask 0.6 or under if ('undoc-static' in self.options and endpoint == 'static' and static_url_path + '/(path:filename)' in paths): continue view = app.view_functions[endpoint] if self.modules and view.__module__ not in self.modules: continue if self.undoc_modules and view.__module__ in self.modules: continue docstring = view.__doc__ or '' if hasattr(view, 'view_class'): meth_func = getattr(view.view_class, method.lower(), None) if meth_func and meth_func.__doc__: docstring = meth_func.__doc__ if not isinstance(docstring, six.text_type): analyzer = ModuleAnalyzer.for_module(view.__module__) docstring = force_decode(docstring, analyzer.encoding) if not docstring and 'include-empty-docstring' not in self.options: continue docstring = prepare_docstring(docstring) if qref == True: for path in paths: row = quickref_directive(method, path, docstring) yield row else: lines = list(http_directive(method, paths, docstring)) self.state.document.settings.env.app.emit( 'autodoc-process-docstring', 'function', None, view, {}, lines) for line in lines: yield line
def make_rst(self, qref=False): app = import_object(self.arguments[0]) if self.endpoints: routes = itertools.chain(*[get_routes(app, endpoint, self.order) for endpoint in self.endpoints]) else: routes = get_routes(app, order=self.order) for method, paths, endpoint in routes: try: blueprint, _, endpoint_internal = endpoint.rpartition('.') if self.blueprints and blueprint not in self.blueprints: continue if blueprint in self.undoc_blueprints: continue except ValueError: pass # endpoint is not within a blueprint if endpoint in self.undoc_endpoints: continue try: static_url_path = app.static_url_path # Flask 0.7 or higher except AttributeError: static_url_path = app.static_path # Flask 0.6 or under if ('undoc-static' in self.options and endpoint == 'static' and static_url_path + '/(path:filename)' in paths): continue view = app.view_functions[endpoint] if self.modules and view.__module__ not in self.modules: continue if self.undoc_modules and view.__module__ in self.modules: continue docstring = view.__doc__ or '' if hasattr(view, 'view_class'): meth_func = getattr(view.view_class, method.lower(), None) if meth_func and meth_func.__doc__: docstring = meth_func.__doc__ if not isinstance(docstring, six.text_type): analyzer = ModuleAnalyzer.for_module(view.__module__) docstring = force_decode(docstring, analyzer.encoding) if not docstring and 'include-empty-docstring' not in self.options: continue docstring = prepare_docstring(docstring) if qref == True: for path in paths: row = quickref_directive(method, path, docstring) yield row else: for line in http_directive(method, paths, docstring): yield line
def run(self): pyobj = import_object(self.content[0].strip()) json_string = json.dumps(pyobj, indent=2, sort_keys=True, separators=(',', ':')) literal = nodes.literal_block(json_string, json_string) literal['language'] = 'json' set_source_info(self, literal) caption = self.options.get('caption') if caption: literal = container_wrapper(self, literal, caption) return [literal]
def make_rst(self, qref=False): app = import_object(self.arguments[0]) routes = self.inspect_routes(app) if 'view' in self.groupby: routes = self.groupby_view(routes) for method, paths, view_func, view_doc in routes: docstring = prepare_docstring(view_doc) if qref: for path in paths: row = quickref_directive(method, path, docstring) yield row else: for line in http_directive(method, paths, docstring): yield line
def make_rst(self): app = import_object(self.arguments[0]) if self.endpoints: routes = itertools.chain(*[get_routes(app, endpoint) for endpoint in self.endpoints]) else: routes = get_routes(app) for method, paths, endpoint in routes: if not self.check_regex_validate_path(paths): continue if self.check_regex_cancel_path(paths): continue try: blueprint, _, endpoint_internal = endpoint.rpartition('.') if self.blueprints and blueprint not in self.blueprints: continue if blueprint in self.undoc_blueprints: continue except ValueError: pass # endpoint is not within a blueprint if endpoint in self.undoc_endpoints: continue try: static_url_path = app.static_url_path # Flask 0.7 or higher except AttributeError: static_url_path = app.static_path # Flask 0.6 or under if ('undoc-static' in self.options and endpoint == 'static' and static_url_path + '/(path:filename)' in paths): continue view = app.view_functions[endpoint] docstring = view.__doc__ or '' if hasattr(view, 'view_class'): meth_func = getattr(view.view_class, method.lower(), None) if meth_func and meth_func.__doc__: docstring = meth_func.__doc__ if not isinstance(docstring, six.text_type): analyzer = ModuleAnalyzer.for_module(view.__module__) docstring = force_decode(docstring, analyzer.encoding) if not docstring and 'include-empty-docstring' not in self.options: continue docstring = prepare_docstring(docstring) for line in http_directive(method, paths, docstring): yield line
def make_rst(self): app = import_object(self.arguments[0]) for method, path, target in get_routes(app): endpoint = target.name or target.callback.__name__ if self.endpoints and endpoint not in self.endpoints: continue if endpoint in self.undoc_endpoints: continue view = target.callback docstring = view.__doc__ or '' if not isinstance(docstring, six.text_type): analyzer = ModuleAnalyzer.for_module(view.__module__) docstring = force_decode(docstring, analyzer.encoding) if not docstring and 'include-empty-docstring' not in self.options: continue docstring = prepare_docstring(docstring) for line in http_directive(method, path, docstring): yield line
def make_rst(self, qref=False): app = import_object(self.arguments[0]) routes = self.inspect_routes(app) if 'view' in self.groupby: routes = self.groupby_view(routes) for method, paths, view_func, view_doc in routes: docstring = prepare_docstring(view_doc) if qref: auto = self.options.get("autoquickref", False) is None blueprint = get_blueprint(app, view_func) for path in paths: row = quickref_directive(method, path, docstring, blueprint, auto=auto) yield row else: for line in http_directive(method, paths, docstring): yield line
def make_rst(self): app = import_object(self.arguments[0]) for method, path, handler in get_routes(app): class_name = handler.__name__ method_name = getattr(handler, method).__name__ endpoint = '.'.join((class_name, method_name)) if self.endpoints and endpoint not in self.endpoints: continue if endpoint in self.undoc_endpoints: continue docstring = getattr(handler, method).__doc__ or '' #if not isinstance(docstring, unicode): # analyzer = ModuleAnalyzer.for_module(view.__module__) # docstring = force_decode(docstring, analyzer.encoding) if not docstring and 'include-empty-docstring' not in self.options: continue docstring = prepare_docstring(docstring) for line in http_directive(method, normalize_path(path), docstring): yield line
def make_rst(self): app = import_object(self.arguments[0]) for method, path, endpoint in get_routes(app): try: blueprint, endpoint_internal = endpoint.split('.') if self.blueprints and blueprint not in self.blueprints: continue if blueprint in self.undoc_blueprints: continue except ValueError: pass # endpoint is not within a blueprint if self.endpoints and endpoint not in self.endpoints: continue if endpoint in self.undoc_endpoints: continue try: static_url_path = app.static_url_path # Flask 0.7 or higher except AttributeError: static_url_path = app.static_path # Flask 0.6 or under if ('undoc-static' in self.options and endpoint == 'static' and path == static_url_path + '/(path:filename)'): continue view = app.view_functions[endpoint] docstring = view.__doc__ or '' if hasattr(view, 'view_class'): meth_func = getattr(view.view_class, method.lower(), None) if meth_func and meth_func.__doc__: docstring = meth_func.__doc__ if not type(docstring) == type(u""): analyzer = ModuleAnalyzer.for_module(view.__module__) docstring = force_decode(docstring, analyzer.encoding) if not docstring and 'include-empty-docstring' not in self.options: continue docstring = prepare_docstring(docstring) for line in http_directive(method, path, docstring): yield line
def make_rst(self): app = import_object(self.arguments[0]) yield "Services:\n" yield "" for x in self._make_toc(get_routes(app)): yield '- {}'.format(x) yield "" for method, path, endpoint in get_routes(app): try: blueprint, _, endpoint_internal = endpoint.rpartition('.') if self.blueprints and blueprint not in self.blueprints: continue if blueprint in self.undoc_blueprints: continue except ValueError: pass # endpoint is not within a blueprint if self.endpoints and endpoint not in self.endpoints: continue if endpoint in self.undoc_endpoints: continue try: static_url_path = app.static_url_path # Flask 0.7 or higher except AttributeError: static_url_path = app.static_path # Flask 0.6 or under if ('undoc-static' in self.options and endpoint == 'static' and path == static_url_path + '/(path:filename)'): continue view = app.view_functions[endpoint] docstring = view.__doc__ or '' if hasattr(view, 'view_class'): meth_func = getattr(view.view_class, method.lower(), None) if meth_func and meth_func.__doc__: docstring = meth_func.__doc__ if not isinstance(docstring, six.text_type): analyzer = ModuleAnalyzer.for_module(view.__module__) docstring = force_decode(docstring, analyzer.encoding) if not docstring and 'include-empty-docstring' not in self.options: continue #Thanks flask-classy for this :D if len(endpoint.split(":")) == 2: view_cls, view_func = endpoint.split(":") if hasattr(app, 'view_classes') and view_cls in app.view_classes: cls = app.view_classes[view_cls] members = inspect.getmembers(cls,predicate=inspect.ismethod) if hasattr(cls,'args_rules'): rules = cls.args_rules if view_func in rules: for m in members: if m[0] == view_func: docstring += m[1].__doc__.strip() docstring += '\n\n' for a in rules[view_func]: t = str(a.type).replace('type','').replace("'","").replace('<','').replace('>','') params = dict( type=t, name=str(a.name), description=str(a.description), default=str(a.default) ) if a.required: docstring += ' :<json {type} {name}: {description}.\n'.format(**params) else: docstring += ' :<json {type} {name}: *(optional)* {description}. *Default*={default}\n'.format(**params) docstring = prepare_docstring(docstring) for line in http_directive(method, path, docstring): yield line