def getRoutes(app): """ Get the routes assoicated with a L{klein} application. @param app: The L{klein} application to introspect. @type app: L{klein.Klein} @return: The routes associated to the application. @rtype: A generator of L{KleinRoute}s """ # This accesses private attributes of Klein: # https://github.com/twisted/klein/issues/49 # Adapted from sphinxcontrib.autohttp.flask for rule in app._url_map.iter_rules(): methods = rule.methods.difference(['HEAD']) path = translate_werkzeug_rule(rule.rule) # Klein sets `segment_count` which we don't care about # so ignore it. attributes = vars(app._endpoints[rule.endpoint]).copy() if 'segment_count' in attributes: del attributes['segment_count'] yield KleinRoute( methods=methods, path=path, endpoint=rule.endpoint, attributes=attributes)
def getRoutes(app): """ Get the routes assoicated with a L{klein} application. Endpoints decorated with ``@private_api`` will be omitted. @param app: The L{klein} application to introspect. @type app: L{klein.Klein} @return: The routes associated to the application. @rtype: A generator of L{KleinRoute}s """ # This accesses private attributes of Klein: # https://github.com/twisted/klein/issues/49 # Adapted from sphinxcontrib.autohttp.flask for rule in app._url_map.iter_rules(): methods = rule.methods.difference(['HEAD']) path = translate_werkzeug_rule(rule.rule) # Klein sets `segment_count` which we don't care about # so ignore it. attributes = vars(app._endpoints[rule.endpoint]).copy() if 'segment_count' in attributes: del attributes['segment_count'] yield KleinRoute( methods=methods, path=path, endpoint=rule.endpoint, attributes=attributes)
def get_routes(app, endpoint=None): endpoints = [] for rule in sorted(app.url_map.iter_rules(endpoint)): if rule.endpoint not in endpoints: endpoints.append(rule.endpoint) for endpoint in endpoints: methodrules = {} for rule in app.url_map.iter_rules(endpoint): methods = rule.methods.difference(['OPTIONS', 'HEAD']) path = autodocflask.translate_werkzeug_rule(rule.rule) for method in methods: if method in methodrules: methodrules[method].append(path) else: methodrules[method] = [path] for method, paths in methodrules.items(): yield method, paths, endpoint
def get_routes(app, endpoint=None): endpoints = [] routes = [] for rule in app.url_map.iter_rules(endpoint): if rule.endpoint not in endpoints: endpoints.append(rule.endpoint) for endpoint in endpoints: methodrules = {} for rule in app.url_map.iter_rules(endpoint): methods = rule.methods.difference(['OPTIONS', 'HEAD']) path = flask.translate_werkzeug_rule(rule.rule) for method in methods: if method in methodrules: methodrules[method].append(path) else: methodrules[method] = [path] for method, paths in methodrules.items(): routes.append((method, paths, endpoint)) routes = sorted(routes, key=lambda tup: tup[1][0]) for route in routes: yield route