Skip to content

Commit

Permalink
create_manpage_completions: Use raw strings for backslashes
Browse files Browse the repository at this point in the history
python 3.12 emits a SyntaxWarning for invalid escape sequences.

Fixes #9814
  • Loading branch information
faho committed May 26, 2023
1 parent bec8e8d commit 2eba684
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions share/tools/create_manpage_completions.py
Expand Up @@ -245,22 +245,22 @@ def remove_groff_formatting(data):
data = data.replace("\\fB", "")
data = data.replace("\\fR", "")
data = data.replace("\\e", "")
data = re.sub(".PD( \d+)", "", data)
data = re.sub(r".PD( \d+)", "", data)
data = data.replace(".BI", "")
data = data.replace(".BR", "")
data = data.replace("0.5i", "")
data = data.replace(".rb", "")
data = data.replace("\\^", "")
data = data.replace("{ ", "")
data = data.replace(" }", "")
data = data.replace("\ ", "")
data = data.replace("\-", "-")
data = data.replace("\&", "")
data = data.replace(r"\ ", "")
data = data.replace(r"\-", "-")
data = data.replace(r"\&", "")
data = data.replace(".B", "")
data = data.replace("\-", "-")
data = data.replace(r"\-", "-")
data = data.replace(".I", "")
data = data.replace("\f", "")
data = data.replace("\(cq", "'")
data = data.replace(r"\(cq", "'")
return data


Expand All @@ -274,13 +274,13 @@ def parse_man_page(self, manpage):

class Type1ManParser(ManParser):
def is_my_type(self, manpage):
return compile_and_search('\.SH "OPTIONS"(.*?)', manpage) is not None
return compile_and_search(r'\.SH "OPTIONS"(.*?)', manpage) is not None

def parse_man_page(self, manpage):
options_section_regex = re.compile('\.SH "OPTIONS"(.*?)(\.SH|\Z)', re.DOTALL)
options_section_regex = re.compile(r'\.SH "OPTIONS"(.*?)(\.SH|\Z)', re.DOTALL)
options_section = re.search(options_section_regex, manpage).group(1)

options_parts_regex = re.compile("\.PP(.*?)\.RE", re.DOTALL)
options_parts_regex = re.compile(r"\.PP(.*?)\.RE", re.DOTALL)
options_matched = re.search(options_parts_regex, options_section)
add_diagnostic("Command is %r" % CMDNAME)

Expand Down Expand Up @@ -320,7 +320,7 @@ def parse_man_page(self, manpage):

def fallback(self, options_section):
add_diagnostic("Trying fallback")
options_parts_regex = re.compile("\.TP( \d+)?(.*?)\.TP", re.DOTALL)
options_parts_regex = re.compile(r"\.TP( \d+)?(.*?)\.TP", re.DOTALL)
options_matched = re.search(options_parts_regex, options_section)
if options_matched is None:
add_diagnostic("Still not found")
Expand Down Expand Up @@ -349,9 +349,9 @@ def fallback(self, options_section):

def fallback2(self, options_section):
add_diagnostic("Trying last chance fallback")
ix_remover_regex = re.compile("\.IX.*")
ix_remover_regex = re.compile(r"\.IX.*")
trailing_num_regex = re.compile("\\d+$")
options_parts_regex = re.compile("\.IP (.*?)\.IP", re.DOTALL)
options_parts_regex = re.compile(r"\.IP (.*?)\.IP", re.DOTALL)

options_section = re.sub(ix_remover_regex, "", options_section)
options_matched = re.search(options_parts_regex, options_section)
Expand Down Expand Up @@ -386,14 +386,14 @@ def fallback2(self, options_section):

class Type2ManParser(ManParser):
def is_my_type(self, manpage):
return compile_and_search("\.SH OPTIONS(.*?)", manpage) is not None
return compile_and_search(r"\.SH OPTIONS(.*?)", manpage) is not None

def parse_man_page(self, manpage):
options_section_regex = re.compile("\.SH OPTIONS(.*?)(\.SH|\Z)", re.DOTALL)
options_section_regex = re.compile(r"\.SH OPTIONS(.*?)(\.SH|\Z)", re.DOTALL)
options_section = re.search(options_section_regex, manpage).group(1)

options_parts_regex = re.compile(
"\.[IT]P( \d+(\.\d)?i?)?(.*?)\.([IT]P|UNINDENT|UN|SH)", re.DOTALL
r"\.[IT]P( \d+(\.\d)?i?)?(.*?)\.([IT]P|UNINDENT|UN|SH)", re.DOTALL
)
options_matched = re.search(options_parts_regex, options_section)
add_diagnostic("Command is %r" % CMDNAME)
Expand Down Expand Up @@ -426,13 +426,13 @@ def parse_man_page(self, manpage):

class Type3ManParser(ManParser):
def is_my_type(self, manpage):
return compile_and_search("\.SH DESCRIPTION(.*?)", manpage) != None
return compile_and_search(r"\.SH DESCRIPTION(.*?)", manpage) != None

def parse_man_page(self, manpage):
options_section_regex = re.compile("\.SH DESCRIPTION(.*?)(\.SH|\Z)", re.DOTALL)
options_section_regex = re.compile(r"\.SH DESCRIPTION(.*?)(\.SH|\Z)", re.DOTALL)
options_section = re.search(options_section_regex, manpage).group(1)

options_parts_regex = re.compile("\.TP(.*?)\.TP", re.DOTALL)
options_parts_regex = re.compile(r"\.TP(.*?)\.TP", re.DOTALL)
options_matched = re.search(options_parts_regex, options_section)
add_diagnostic("Command is %r" % CMDNAME)

Expand Down Expand Up @@ -467,15 +467,15 @@ def parse_man_page(self, manpage):

class Type4ManParser(ManParser):
def is_my_type(self, manpage):
return compile_and_search("\.SH FUNCTION LETTERS(.*?)", manpage) != None
return compile_and_search(r"\.SH FUNCTION LETTERS(.*?)", manpage) != None

def parse_man_page(self, manpage):
options_section_regex = re.compile(
"\.SH FUNCTION LETTERS(.*?)(\.SH|\Z)", re.DOTALL
r"\.SH FUNCTION LETTERS(.*?)(\.SH|\Z)", re.DOTALL
)
options_section = re.search(options_section_regex, manpage).group(1)

options_parts_regex = re.compile("\.TP(.*?)\.TP", re.DOTALL)
options_parts_regex = re.compile(r"\.TP(.*?)\.TP", re.DOTALL)
options_matched = re.search(options_parts_regex, options_section)
add_diagnostic("Command is %r" % CMDNAME)

Expand Down Expand Up @@ -518,7 +518,7 @@ def is_my_type(self, manpage):
)

def parse_man_page(self, manpage):
options_section_regex = re.compile("\.SH OPTIONS(.*?)\.SH", re.DOTALL)
options_section_regex = re.compile(r"\.SH OPTIONS(.*?)\.SH", re.DOTALL)
options_section_matched = re.search(options_section_regex, manpage)
if options_section_matched is None:
return False
Expand Down Expand Up @@ -568,14 +568,14 @@ def parse_man_page(self, manpage):

class TypeDarwinManParser(ManParser):
def is_my_type(self, manpage):
return compile_and_search("\.S[hH] DESCRIPTION", manpage) is not None
return compile_and_search(r"\.S[hH] DESCRIPTION", manpage) is not None

def trim_groff(self, line):
# Remove initial period
if line.startswith("."):
line = line[1:]
# Skip leading groff crud
while re.match("[A-Z][a-z]\s", line):
while re.match(r"[A-Z][a-z]\s", line):
line = line[3:]

# If the line ends with a space and then a period or comma, then erase the space
Expand All @@ -600,7 +600,7 @@ def count_argument_dashes(self, line):
def groff_replace_escapes(self, line):
line = line.replace(".Nm", CMDNAME)
line = line.replace("\\ ", " ")
line = line.replace("\& ", "")
line = line.replace(r"\& ", "")
line = line.replace(".Pp", "")
return line

Expand Down

0 comments on commit 2eba684

Please sign in to comment.