Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,13 @@ will be rendered as:

.. versionadded:: 1.1.2

``url_regexp``
Filters urls by matching based on a regexp instance built based
on the regular expression passed here as a string. The ones not matching
are discarded.

.. versionadded:: 1.8.1
Comment on lines +791 to +795
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is more clear to the reader.

Suggested change
Filters urls by matching based on a regexp instance built based
on the regular expression passed here as a string. The ones not matching
are discarded.
.. versionadded:: 1.8.1
Filters URLs by matching a regular expression passed into the parameter ``url_regexp`` as a string.
The URLs that don't match get discarded.
.. versionadded:: 2.0.0


.. _Flask: http://flask.pocoo.org/


Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def readme():

setup(
name='sphinxcontrib-httpdomain',
version='1.8.0',
version='1.8.1',
url='https://github.com/sphinx-contrib/httpdomain',
download_url='https://pypi.org/project/sphinxcontrib-httpdomain/',
license='BSD',
Expand Down
16 changes: 13 additions & 3 deletions sphinxcontrib/autohttp/flask_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,15 @@ def translate_werkzeug_rule(rule):
return buf.getvalue()


def get_routes(app, endpoint=None, order=None):
def get_routes(app, endpoint=None, order=None, url_regexp=None):
endpoints = []
for rule in app.url_map.iter_rules(endpoint):
url_with_endpoint = (
six.text_type(next(app.url_map.iter_rules(rule.endpoint))),
rule.endpoint
)
if url_regexp and not url_regexp.match(url_with_endpoint[0]):
continue
if url_with_endpoint not in endpoints:
endpoints.append(url_with_endpoint)
if order == 'path':
Expand Down Expand Up @@ -128,6 +130,7 @@ class AutoflaskBase(Directive):
'undoc-modules': directives.unchanged,
'undoc-static': directives.unchanged,
'include-empty-docstring': directives.unchanged,
'url_regexp': directives.unchanged,
'autoquickref': directives.flag}

@property
Expand Down Expand Up @@ -186,17 +189,24 @@ def groupby(self):
return frozenset()
return frozenset(re.split(r'\s*,\s*', groupby))

@property
def url_regexp(self):
url_regexp = self.options.get('url_regexp', None)
if url_regexp:
return re.compile(url_regexp)
return None

def inspect_routes(self, app):
"""Inspects the views of Flask.

:param app: The Flask application.
:returns: 4-tuple like ``(method, paths, view_func, view_doc)``
"""
if self.endpoints:
routes = itertools.chain(*[get_routes(app, endpoint, self.order)
routes = itertools.chain(*[get_routes(app, endpoint, self.order, url_regexp=self.url_regexp)
for endpoint in self.endpoints])
else:
routes = get_routes(app, order=self.order)
routes = get_routes(app, order=self.order, url_regexp=self.url_regexp)

for method, paths, endpoint in routes:
try:
Expand Down