jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1086028?usp=email )
Change subject: [IMPR] use long regex flags which are more readable
......................................................................
[IMPR] use long regex flags which are more readable
Change-Id: I2946c23d2ac0f0c31f2c9a7310cf478a90a8812b
---
M pywikibot/comms/http.py
M pywikibot/cosmetic_changes.py
M pywikibot/pagegenerators/_filters.py
M pywikibot/textlib.py
M pywikibot/tools/__init__.py
M scripts/category.py
M scripts/category_redirect.py
M scripts/checkimages.py
M scripts/commonscat.py
M scripts/solve_disambiguation.py
M scripts/upload.py
M scripts/welcome.py
12 files changed, 19 insertions(+), 19 deletions(-)
Approvals:
jenkins-bot: Verified
Xqt: Looks good to me, approved
diff --git a/pywikibot/comms/http.py b/pywikibot/comms/http.py
index 71d629b..71345d6 100644
--- a/pywikibot/comms/http.py
+++ b/pywikibot/comms/http.py
@@ -457,7 +457,7 @@
# Extract charset (from content-type header)
CHARSET_RE = re.compile(
r'charset\s*=\s*(?P<q>[\'"]?)(?P<charset>[^\'",;>/]+)(?P=q)',
- flags=re.I,
+ flags=re.IGNORECASE,
)
diff --git a/pywikibot/cosmetic_changes.py b/pywikibot/cosmetic_changes.py
index effc1cd..cf3df33 100644
--- a/pywikibot/cosmetic_changes.py
+++ b/pywikibot/cosmetic_changes.py
@@ -529,7 +529,7 @@
exceptions = ['comment', 'nowiki', 'pre', 'syntaxhighlight']
regex = re.compile(
FILE_LINK_REGEX % '|'.join(self.site.namespaces[6]),
- flags=re.X)
+ flags=re.VERBOSE)
return textlib.replaceExcept(
text, regex, replace_magicword, exceptions)
@@ -729,7 +729,7 @@
if self.site.code in skip_templates:
for template in skip_templates[self.site.code]:
skip_regexes.append(
- re.compile(r'\{\{\s*%s\s*\}\}' % template, re.I))
+ re.compile(r'\{\{\s*%s\s*\}\}' % template, re.IGNORECASE))
# empty lists
skip_regexes.append(re.compile(r'(?m)^[\*#] *$'))
diff --git a/pywikibot/pagegenerators/_filters.py
b/pywikibot/pagegenerators/_filters.py
index 660ec16..85e811a 100644
--- a/pywikibot/pagegenerators/_filters.py
+++ b/pywikibot/pagegenerators/_filters.py
@@ -291,7 +291,7 @@
quantifier = 'any'
elif quantifier is True:
quantifier = 'none'
- reg = cls.__precompile(regex, re.I)
+ reg = cls.__precompile(regex, re.IGNORECASE)
for page in generator:
title = page.title(with_ns=not ignore_namespace)
if cls.__filter_match(reg, title, quantifier):
diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py
index dc4d46e..d8e67f9 100644
--- a/pywikibot/textlib.py
+++ b/pywikibot/textlib.py
@@ -1571,10 +1571,10 @@
title = case_escape(site.namespaces[14].case, title, underscore=True)
categoryR = re.compile(
rf'\[\[\s*({catNamespace})\s*:\s*{title}[\s\u200e\u200f]*'
- r'((?:\|[^]]+)?\]\])', re.I)
+ r'((?:\|[^]]+)?\]\])', re.IGNORECASE)
categoryRN = re.compile(
rf'^[^\S\n]*\[\[\s*({catNamespace})\s*:\s*{title}[\s\u200e\u200f]*'
- r'((?:\|[^]]+)?\]\])[^\S\n]*\n', re.I | re.M)
+ r'((?:\|[^]]+)?\]\])[^\S\n]*\n', re.IGNORECASE | re.MULTILINE)
exceptions = ['comment', 'math', 'nowiki', 'pre', 'syntaxhighlight']
if newcat is None:
# First go through and try the more restrictive regex that removes
@@ -1621,7 +1621,7 @@
if site is None:
site = pywikibot.Site()
if re.search(r'\{\{ *(' + r'|'.join(site.getmagicwords('defaultsort'))
- + r')', oldtext, flags=re.I):
+ + r')', oldtext, flags=re.IGNORECASE):
separator = '\n'
else:
separator = site.family.category_text_separator
@@ -1668,15 +1668,15 @@
if site.sitename == 'wikipedia:de':
personendaten = re.compile(r'\{\{ *Personendaten.*?\}\}',
- re.I | re.DOTALL)
+ re.IGNORECASE | re.DOTALL)
under_categories.append(personendaten)
if site.sitename == 'wikipedia:yi':
- stub = re.compile(r'\{\{.*?שטומף *\}\}', re.I)
+ stub = re.compile(r'\{\{.*?שטומף *\}\}', re.IGNORECASE)
under_categories.append(stub)
if site.family.name == 'wikipedia' and site.code in ('simple', 'en'):
- stub = re.compile(r'\{\{.*?stub *\}\}', re.I)
+ stub = re.compile(r'\{\{.*?stub *\}\}', re.IGNORECASE)
under_categories.append(stub)
if under_categories:
diff --git a/pywikibot/tools/__init__.py b/pywikibot/tools/__init__.py
index 3a782b7..e23a89c 100644
--- a/pywikibot/tools/__init__.py
+++ b/pywikibot/tools/__init__.py
@@ -217,7 +217,7 @@
the start of the path to the warning module must match.
(case-sensitive)
"""
- self.message_match = re.compile(message, re.I).match
+ self.message_match = re.compile(message, re.IGNORECASE).match
self.category = category
self.filename_match = re.compile(filename).match
super().__init__(record=True)
diff --git a/scripts/category.py b/scripts/category.py
index 8d601e6..12ac25e 100755
--- a/scripts/category.py
+++ b/scripts/category.py
@@ -197,7 +197,7 @@
CFD_TEMPLATE_REGEX = re.compile(r'<!--\s*BEGIN CFD TEMPLATE\s*-->.*?'
r'<!--\s*END CFD TEMPLATE\s*-->\n?',
- flags=re.I | re.M | re.S)
+ flags=re.IGNORECASE | re.MULTILINE | re.DOTALL)
cfd_templates = {
'wikipedia': {
@@ -531,7 +531,7 @@
if self.includeonly == ['includeonly']:
tagname = 'includeonly'
tagnameregexp = re.compile(fr'(.*)(<\/{tagname}>)',
- re.I | re.DOTALL)
+ re.IGNORECASE | re.DOTALL)
categorytitle = catpl.title(
as_link=True, allow_interwiki=False)
if tagnameregexp.search(text):
diff --git a/scripts/category_redirect.py b/scripts/category_redirect.py
index 462f365..aadb8bf 100755
--- a/scripts/category_redirect.py
+++ b/scripts/category_redirect.py
@@ -339,7 +339,7 @@
template='|'.join(item.replace(' ', '[ _]+')
for item in self.template_list),
catns=self.site.namespace(14)),
- re.I | re.X)
+ re.IGNORECASE | re.VERBOSE)
nonemptypages = []
catpages = set()
diff --git a/scripts/checkimages.py b/scripts/checkimages.py
index 9f4741c..ca695d8 100755
--- a/scripts/checkimages.py
+++ b/scripts/checkimages.py
@@ -1358,7 +1358,7 @@
if '{{' in i:
regex_pattern = re.compile(
r'\{\{(?:template)?%s ?(?:\||\r?\n|\}|<|/) ?'
- % i.split('{{')[1].replace(' ', '[ _]'), re.I)
+ % i.split('{{')[1].replace(' ', '[ _]'), re.IGNORECASE)
result = regex_pattern.findall(self.image_check_text)
if result:
return True
diff --git a/scripts/commonscat.py b/scripts/commonscat.py
index c2ce678..9074deb 100755
--- a/scripts/commonscat.py
+++ b/scripts/commonscat.py
@@ -492,7 +492,7 @@
r'(?P<newcat1>[^\|\}]+)(\|[^\}]+)?\]\]|'
r'Robot: Changing Category:(.+) '
r'to Category:(?P<newcat2>.+)')
- m = re.search(regex, logcomment, flags=re.I)
+ m = re.search(regex, logcomment, flags=re.IGNORECASE)
if not m:
pywikibot.info(
diff --git a/scripts/solve_disambiguation.py b/scripts/solve_disambiguation.py
index 367086e..3da88c5 100755
--- a/scripts/solve_disambiguation.py
+++ b/scripts/solve_disambiguation.py
@@ -674,7 +674,7 @@
\[\[ (?P<title> [^\[\]\|#]*)
(?P<section> \#[^\]\|]*)?
(\|(?P<label> [^\]]*))? \]\]
- (?P<linktrail>{linktrail})""", flags=re.X)
+ (?P<linktrail>{linktrail})""", flags=re.VERBOSE)
@staticmethod
def firstlinks(page) -> Generator[str]:
diff --git a/scripts/upload.py b/scripts/upload.py
index 9432928..a64ef92 100755
--- a/scripts/upload.py
+++ b/scripts/upload.py
@@ -83,7 +83,7 @@
CHUNK_SIZE_REGEX = re.compile(
- r'-chunked(?::(\d+(?:\.\d+)?)[ \t]*(k|ki|m|mi)?b?)?', re.I)
+ r'-chunked(?::(\d+(?:\.\d+)?)[ \t]*(k|ki|m|mi)?b?)?', re.IGNORECASE)
def get_chunk_size(match) -> int:
diff --git a/scripts/welcome.py b/scripts/welcome.py
index 430da3a..4d86298 100755
--- a/scripts/welcome.py
+++ b/scripts/welcome.py
@@ -752,7 +752,7 @@
return self._random_signature
sign_text = ''
- creg = re.compile(r'^\* ?(.*?)$', re.M)
+ creg = re.compile(r'^\* ?(.*?)$', re.MULTILINE)
if not globalvar.sign_file_name:
sign_page_name = i18n.translate(self.site, RANDOM_SIGN)
if not sign_page_name:
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1086028?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.wikimedia.org/r/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: I2946c23d2ac0f0c31f2c9a7310cf478a90a8812b
Gerrit-Change-Number: 1086028
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <[email protected]>
Gerrit-Reviewer: D3r1ck01 <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]