Xqt has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1340519?usp=email )
Change subject: Use partition for title delimiter parsing
......................................................................
Use partition for title delimiter parsing
Replace pipe checks and index-based slicing with partition when
reading page titles and language links. Use partition for namespace
prefixes where an existing guard establishes that a colon is present.
Preserve title handling and existing namespace validation.
Change-Id: Ib32d4204c40e9eacdf0b7b19f8bddecf7e304c98
---
M pywikibot/page/_links.py
M pywikibot/pagegenerators/_generators.py
M pywikibot/textlib.py
3 files changed, 5 insertions(+), 7 deletions(-)
Approvals:
Xqt: Verified; Looks good to me, approved
diff --git a/pywikibot/page/_links.py b/pywikibot/page/_links.py
index 5804693..1999933 100644
--- a/pywikibot/page/_links.py
+++ b/pywikibot/page/_links.py
@@ -344,7 +344,7 @@
# remove any subsequent whitespace
t = t.lstrip(':').lstrip(' ')
continue
- prefix = t[:t.index(':')].lower() # part of text before :
+ prefix = t.partition(':')[0].lower() # part of text before :
ns = self._source.namespaces.lookup_name(prefix)
if ns:
# The prefix is a namespace in the source wiki
@@ -437,7 +437,7 @@
if self._namespace % 2 else
self._namespace + 1]
if '' in other_ns: # other namespace uses empty str as ns
- next_ns = t[:t.index(':')]
+ next_ns = t.partition(':')[0]
if self._site.namespaces.lookup_name(next_ns):
raise InvalidTitleError(
f"The (non-)talk page of '{self._text}' is a valid"
diff --git a/pywikibot/pagegenerators/_generators.py
b/pywikibot/pagegenerators/_generators.py
index 3456f6a..4dcf807 100644
--- a/pywikibot/pagegenerators/_generators.py
+++ b/pywikibot/pagegenerators/_generators.py
@@ -452,8 +452,7 @@
f.seek(0)
for title in f:
title = title.strip()
- if '|' in title:
- title = title[:title.index('|')]
+ title = title.partition('|')[0]
if title:
yield pywikibot.Page(site, title)
diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py
index c4f9343..e65b96b 100644
--- a/pywikibot/textlib.py
+++ b/pywikibot/textlib.py
@@ -1437,9 +1437,8 @@
# language, or if it's e.g. a category tag or an internal link
lang = fam.obsolete.get(lang, lang)
if lang in fam.langs:
- if '|' in pagetitle:
- # ignore text after the pipe
- pagetitle = pagetitle[:pagetitle.index('|')]
+ # ignore text after the pipe
+ pagetitle = pagetitle.partition('|')[0]
# we want the actual page objects rather than the titles
site = pywikibot.Site(code=lang, fam=fam)
# skip language links to its own site
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1340519?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: Ib32d4204c40e9eacdf0b7b19f8bddecf7e304c98
Gerrit-Change-Number: 1340519
Gerrit-PatchSet: 2
Gerrit-Owner: Mahveotm <[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]