Skip to content

Commit 1f96d0d

Browse files
committed
Put r on a bunch more regex compile/match/sub
1 parent e68935d commit 1f96d0d

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

wikiextractor/extract.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
# ----------------------------------------------------------------------
3131

3232
# match tail after wikilink
33-
tailRE = re.compile('\w+')
33+
tailRE = re.compile(r'\w+')
3434
syntaxhighlight = re.compile('<syntaxhighlight .*?>(.*?)</syntaxhighlight>', re.DOTALL)
3535

3636
## PARAMS ####################################################################
@@ -168,8 +168,8 @@ def clean(extractor, text, expand_templates=False, html_safe=True):
168168
text = text.replace('\t', ' ')
169169
text = spaces.sub(' ', text)
170170
text = dots.sub('...', text)
171-
text = re.sub(u' (,:\.\)\]»)', r'\1', text)
172-
text = re.sub(u'(\[\(«) ', r'\1', text)
171+
text = re.sub(r' (,:\.\)\]»)', r'\1', text)
172+
text = re.sub(r'(\[\(«) ', r'\1', text)
173173
text = re.sub(r'\n\W+?\n', '\n', text, flags=re.U) # lines with only punctuations
174174
text = text.replace(',,', ',').replace(',.', '.')
175175
if html_safe:
@@ -380,7 +380,7 @@ def dropSpans(spans, text):
380380
# as well as U+3000 is IDEOGRAPHIC SPACE for bug 19052
381381
EXT_LINK_URL_CLASS = r'[^][<>"\x00-\x20\x7F\s]'
382382
ExtLinkBracketedRegex = re.compile(
383-
'(?i)\[((' + '|'.join(wgUrlProtocols) + ')' + EXT_LINK_URL_CLASS + r'+)\s*([^\]\x00-\x08\x0a-\x1F]*?)\]',
383+
r'(?i)\[((' + '|'.join(wgUrlProtocols) + ')' + EXT_LINK_URL_CLASS + r'+)\s*([^\]\x00-\x08\x0a-\x1F]*?)\]',
384384
re.S | re.U)
385385
EXT_IMAGE_REGEX = re.compile(
386386
r"""(?i)^(http://|https://)([^][<>"\x00-\x20\x7F\s]+)
@@ -734,7 +734,7 @@ def fixup(m):
734734
except:
735735
return text # leave as is
736736

737-
return re.sub("&#?(\w+);", fixup, text)
737+
return re.sub(r"&#?(\w+);", fixup, text)
738738

739739

740740
# Match HTML comments
@@ -1024,7 +1024,7 @@ def extract(self, out, html_safe=True):
10241024
maxParameterRecursionLevels = 16
10251025

10261026
# check for template beginning
1027-
reOpen = re.compile('(?<!{){{(?!{)', re.DOTALL)
1027+
reOpen = re.compile(r'(?<!{){{(?!{)', re.DOTALL)
10281028

10291029
def expandTemplates(self, wikitext):
10301030
"""
@@ -1434,11 +1434,11 @@ def findMatchingBraces(text, ldelim=0):
14341434
# {{{link|{{ucfirst:{{{1}}}}}} interchange}}}
14351435

14361436
if ldelim: # 2-3
1437-
reOpen = re.compile('[{]{%d,}' % ldelim) # at least ldelim
1438-
reNext = re.compile('[{]{2,}|}{2,}') # at least 2 open or close bracces
1437+
reOpen = re.compile(r'[{]{%d,}' % ldelim) # at least ldelim
1438+
reNext = re.compile(r'[{]{2,}|}{2,}') # at least 2 open or close bracces
14391439
else:
1440-
reOpen = re.compile('{{2,}|\[{2,}')
1441-
reNext = re.compile('{{2,}|}{2,}|\[{2,}|]{2,}') # at least 2
1440+
reOpen = re.compile(r'{{2,}|\[{2,}')
1441+
reNext = re.compile(r'{{2,}|}{2,}|\[{2,}|]{2,}') # at least 2
14421442

14431443
cur = 0
14441444
while True:
@@ -1582,7 +1582,7 @@ def fullyQualifiedTemplateTitle(templateTitle):
15821582
# Leading colon by itself implies main namespace, so strip this colon
15831583
return ucfirst(templateTitle[1:])
15841584
else:
1585-
m = re.match('([^:]*)(:.*)', templateTitle)
1585+
m = re.match(r'([^:]*)(:.*)', templateTitle)
15861586
if m:
15871587
# colon found but not in the first position - check if it
15881588
# designates a known namespace
@@ -1689,7 +1689,7 @@ def sharp_ifeq(lvalue, rvalue, valueIfTrue, valueIfFalse=None, *args):
16891689

16901690

16911691
def sharp_iferror(test, then='', Else=None, *args):
1692-
if re.match('<(?:strong|span|p|div)\s(?:[^\s>]*\s+)*?class="(?:[^"\s>]*\s+)*?error(?:\s[^">]*)?"', test):
1692+
if re.match(r'<(?:strong|span|p|div)\s(?:[^\s>]*\s+)*?class="(?:[^"\s>]*\s+)*?error(?:\s[^">]*)?"', test):
16931693
return then
16941694
elif Else is None:
16951695
return test.strip()
@@ -1860,7 +1860,7 @@ def define_template(title, page):
18601860
# title = normalizeTitle(title)
18611861

18621862
# check for redirects
1863-
m = re.match('#REDIRECT.*?\[\[([^\]]*)]]', page[0], re.IGNORECASE)
1863+
m = re.match(r'#REDIRECT.*?\[\[([^\]]*)]]', page[0], re.IGNORECASE)
18641864
if m:
18651865
redirects[title] = m.group(1) # normalizeTitle(m.group(1))
18661866
return

0 commit comments

Comments
 (0)