Skip to content

Commit

Permalink
fix: Use raw string notation for regex (ietf-tools#1083)
Browse files Browse the repository at this point in the history
  • Loading branch information
kesara authored Jan 17, 2024
1 parent 4c7e638 commit 007abf6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
14 changes: 7 additions & 7 deletions xml2rfc/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,9 @@ def replacer(match):
.replace(':', ':' + wj_char)
)
if 'http://' in text:
text = re.sub('http:\S*', replacer, text)
text = re.sub(r'http:\S*', replacer, text)
if 'https://' in text:
text = re.sub('https:\S*', replacer, text)
text = re.sub(r'https:\S*', replacer, text)
return text

# ----------------------------------------------------------------------
Expand All @@ -286,13 +286,13 @@ def formatXmlWhitespace(tree):
# Preserve formatting on artwork
if element.tag != 'artwork':
if element.text is not None:
element.text = re.sub('\s*\n\s*', ' ', \
re.sub('\.\s*\n\s*', '. ', \
element.text = re.sub(r'\s*\n\s*', ' ', \
re.sub(r'\.\s*\n\s*', '. ', \
element.text.lstrip()))

if element.tail is not None:
element.tail = re.sub('\s*\n\s*', ' ', \
re.sub('\.\s*\n\s*', '. ', \
element.tail = re.sub(r'\s*\n\s*', ' ', \
re.sub(r'\.\s*\n\s*', '. ', \
element.tail))


Expand Down Expand Up @@ -580,7 +580,7 @@ def _replace_slashed_words(str, slashList):
""" replace slashed separated words the list with
<word1> &nbsp; / &nbsp; <word 2>
"""
match = re.findall(u'(\w+(/\w+)+)', str)
match = re.findall(r'(\w+(/\w+)+)', str)
for item in match:
if item[0] in slashList:
str = re.sub(item[0], slashList[item[0]], str)
Expand Down
4 changes: 2 additions & 2 deletions xml2rfc/writers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ def get_initials(self, author):
# period
initials = initials.strip()
initials += '.' if not initials.endswith('.') else ''
initials = re.sub('([^.]) ', '\g<1>. ', initials)
initials = re.sub(r'([^.]) ', r'\g<1>. ', initials)
else:
initials = initials_list[0] + "."
return initials
Expand Down Expand Up @@ -1347,7 +1347,7 @@ def _build_document(self):
xml2rfc.log.warn("No (or empty) 'docName' attribute in the <rfc/> element -- can't insert draft name on first page.")
if docName and '.' in docName:
xml2rfc.log.warn("The 'docName' attribute of the <rfc/> element should not contain any filename extension: docName=\"draft-foo-bar-02\".")
if docName and not rfcnum and not re.search('-\d\d$', docName):
if docName and not rfcnum and not re.search(r'-\d\d$', docName):
xml2rfc.log.warn("The 'docName' attribute of the <rfc/> element should have a revision number as the last component: docName=\"draft-foo-bar-02\".")
self.write_title(title.text, docName, title.sourceline)

Expand Down

0 comments on commit 007abf6

Please sign in to comment.