From d087c38ad2169266385f2b8303adead7987c3433 Mon Sep 17 00:00:00 2001 From: Mariano Benedettini Date: Mon, 5 Apr 2021 18:18:23 -0300 Subject: [PATCH 1/4] Filter urls with url_regexp --- sphinxcontrib/autohttp/flask_base.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/sphinxcontrib/autohttp/flask_base.py b/sphinxcontrib/autohttp/flask_base.py index 782a95d..502e04a 100644 --- a/sphinxcontrib/autohttp/flask_base.py +++ b/sphinxcontrib/autohttp/flask_base.py @@ -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': @@ -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 @@ -186,6 +189,13 @@ 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. @@ -193,10 +203,10 @@ def inspect_routes(self, app): :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: From 746632c2cea8483f7c84e1843ca4eb25240b6ac0 Mon Sep 17 00:00:00 2001 From: Mariano Benedettini Date: Mon, 5 Apr 2021 18:20:02 -0300 Subject: [PATCH 2/4] Update version --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index b673f84..1632520 100644 --- a/setup.py +++ b/setup.py @@ -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', From 483d4fd31ed9ee31b594a1934ba985db9ac553d4 Mon Sep 17 00:00:00 2001 From: Mariano Benedettini Date: Mon, 5 Apr 2021 18:23:01 -0300 Subject: [PATCH 3/4] Update doc --- doc/index.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/doc/index.rst b/doc/index.rst index 1ecbc96..f23968e 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -787,6 +787,12 @@ will be rendered as: .. versionadded:: 1.1.2 + ``url_regexp`` + Filters urls by filtering out based on a regexp instance built based + on the regular expression passed here as a string. + + .. versionadded:: 1.8.1 + .. _Flask: http://flask.pocoo.org/ From 3061675c01ef38a16e98866994fe2e4b9626d857 Mon Sep 17 00:00:00 2001 From: Mariano Benedettini Date: Mon, 5 Apr 2021 18:25:06 -0300 Subject: [PATCH 4/4] Correct doc --- doc/index.rst | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/index.rst b/doc/index.rst index f23968e..edc2085 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -788,8 +788,9 @@ will be rendered as: .. versionadded:: 1.1.2 ``url_regexp`` - Filters urls by filtering out based on a regexp instance built based - on the regular expression passed here as a string. + 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