Skip to content

Commit 4f3e690

Browse files
author
Jonathan Corbet
committed
docs: fix automarkup regression on Python 2
It turns out that the Python 2 re module lacks the ASCII flag, so don't try to use it there. Fixes: f66e47f ("docs: automarkup.py: Fix regexes to solve sphinx 3 warnings") Reported-by: Dafna Hirschfeld <dafna.hirschfeld@collabora.com> Signed-off-by: Jonathan Corbet <corbet@lwn.net>
1 parent e051955 commit 4f3e690

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

Documentation/sphinx/automarkup.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,29 +15,37 @@
1515
import re
1616
from itertools import chain
1717

18+
#
19+
# Python 2 lacks re.ASCII...
20+
#
21+
try:
22+
ascii_p3 = re.ASCII
23+
except AttributeError:
24+
ascii_p3 = 0
25+
1826
#
1927
# Regex nastiness. Of course.
2028
# Try to identify "function()" that's not already marked up some
2129
# other way. Sphinx doesn't like a lot of stuff right after a
2230
# :c:func: block (i.e. ":c:func:`mmap()`s" flakes out), so the last
2331
# bit tries to restrict matches to things that won't create trouble.
2432
#
25-
RE_function = re.compile(r'\b(([a-zA-Z_]\w+)\(\))', flags=re.ASCII)
33+
RE_function = re.compile(r'\b(([a-zA-Z_]\w+)\(\))', flags=ascii_p3)
2634

2735
#
2836
# Sphinx 2 uses the same :c:type role for struct, union, enum and typedef
2937
#
3038
RE_generic_type = re.compile(r'\b(struct|union|enum|typedef)\s+([a-zA-Z_]\w+)',
31-
flags=re.ASCII)
39+
flags=ascii_p3)
3240

3341
#
3442
# Sphinx 3 uses a different C role for each one of struct, union, enum and
3543
# typedef
3644
#
37-
RE_struct = re.compile(r'\b(struct)\s+([a-zA-Z_]\w+)', flags=re.ASCII)
38-
RE_union = re.compile(r'\b(union)\s+([a-zA-Z_]\w+)', flags=re.ASCII)
39-
RE_enum = re.compile(r'\b(enum)\s+([a-zA-Z_]\w+)', flags=re.ASCII)
40-
RE_typedef = re.compile(r'\b(typedef)\s+([a-zA-Z_]\w+)', flags=re.ASCII)
45+
RE_struct = re.compile(r'\b(struct)\s+([a-zA-Z_]\w+)', flags=ascii_p3)
46+
RE_union = re.compile(r'\b(union)\s+([a-zA-Z_]\w+)', flags=ascii_p3)
47+
RE_enum = re.compile(r'\b(enum)\s+([a-zA-Z_]\w+)', flags=ascii_p3)
48+
RE_typedef = re.compile(r'\b(typedef)\s+([a-zA-Z_]\w+)', flags=ascii_p3)
4149

4250
#
4351
# Detects a reference to a documentation page of the form Documentation/... with

0 commit comments

Comments
 (0)