diff --git a/pywikibot/comms/http.py b/pywikibot/comms/http.py index 71d629b7d1..71345d6128 100644 --- a/pywikibot/comms/http.py +++ b/pywikibot/comms/http.py @@ -457,7 +457,7 @@ def assign_user_agent(user_agent_format_string): # Extract charset (from content-type header) CHARSET_RE = re.compile( r'charset\s*=\s*(?P[\'"]?)(?P[^\'",;>/]+)(?P=q)', - flags=re.I, + flags=re.IGNORECASE, ) diff --git a/pywikibot/cosmetic_changes.py b/pywikibot/cosmetic_changes.py index effc1cdac4..cf3df33299 100644 --- a/pywikibot/cosmetic_changes.py +++ b/pywikibot/cosmetic_changes.py @@ -529,7 +529,7 @@ def replace_magicword(match: Match[str]) -> str: 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 @@ def removeEmptySections(self, text: str) -> str: 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 660ec16f15..85e811a733 100644 --- a/pywikibot/pagegenerators/_filters.py +++ b/pywikibot/pagegenerators/_filters.py @@ -291,7 +291,7 @@ def titlefilter(cls, 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 dc4d46e418..d8e67f9878 100644 --- a/pywikibot/textlib.py +++ b/pywikibot/textlib.py @@ -1571,10 +1571,10 @@ def replaceCategoryInPlace(oldtext, oldcat, newcat, site=None, 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 @@ def replaceCategoryLinks(oldtext: str, 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 @@ def replaceCategoryLinks(oldtext: str, 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 3a782b75c2..e23a89c863 100644 --- a/pywikibot/tools/__init__.py +++ b/pywikibot/tools/__init__.py @@ -217,7 +217,7 @@ def __init__( 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 8d601e6b2a..12ac25e042 100755 --- a/scripts/category.py +++ b/scripts/category.py @@ -197,7 +197,7 @@ CFD_TEMPLATE_REGEX = re.compile(r'.*?' r'\n?', - flags=re.I | re.M | re.S) + flags=re.IGNORECASE | re.MULTILINE | re.DOTALL) cfd_templates = { 'wikipedia': { @@ -531,7 +531,7 @@ def treat(self, page) -> None: 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 462f36525f..aadb8bfc5a 100755 --- a/scripts/category_redirect.py +++ b/scripts/category_redirect.py @@ -339,7 +339,7 @@ def setup_soft_redirect(self): 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 9f4741c9f2..ca695d8571 100755 --- a/scripts/checkimages.py +++ b/scripts/checkimages.py @@ -1358,7 +1358,7 @@ def is_tagged(self) -> bool: 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 c2ce6786f8..9074deb8f1 100755 --- a/scripts/commonscat.py +++ b/scripts/commonscat.py @@ -492,7 +492,7 @@ def checkCommonscatLink(self, name: str = ''): r'(?P[^\|\}]+)(\|[^\}]+)?\]\]|' r'Robot: Changing Category:(.+) ' r'to Category:(?P.+)') - 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 367086e5fb..3da88c5dc3 100755 --- a/scripts/solve_disambiguation.py +++ b/scripts/solve_disambiguation.py @@ -674,7 +674,7 @@ def setup(self) -> None: \[\[ (?P [^\[\]\|#]*) (?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 9432928060..a64ef92c1f 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 430da3a6cd..4d86298b0a 100755 --- a/scripts/welcome.py +++ b/scripts/welcome.py @@ -752,7 +752,7 @@ def define_sign(self, force: bool = False) -> list[str]: 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: