jenkins-bot has submitted this change and it was merged. (
https://gerrit.wikimedia.org/r/508071 )
Change subject: [cleanup] Reduce code complexity of Family.from_url
......................................................................
[cleanup] Reduce code complexity of Family.from_url
Reduce code complexity of Family.from_url method from C17 to C15
- remove "ignored" variable and use "_ignore_from_url" attribute
directly
- remove start marker "^" from match pattern
- exit from_url method if domain was not found in parsed.netloc
- don't use "elsif"/"else" statement if method was leaved
previously
Change-Id: I123ea6ed4180a22e07a4c95202f885464e831230
---
M pywikibot/family.py
1 file changed, 23 insertions(+), 23 deletions(-)
Approvals:
Dalba: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/family.py b/pywikibot/family.py
index b0be37b..d34938a 100644
--- a/pywikibot/family.py
+++ b/pywikibot/family.py
@@ -1293,12 +1293,11 @@
"""
if self._ignore_from_url is True:
return None
- else:
- ignored = self._ignore_from_url
parsed = urlparse.urlparse(url)
- if not re.match('^(https?)?$', parsed.scheme):
+ if not re.match('(https?)?$', parsed.scheme):
return None
+
path = parsed.path
if parsed.query:
path += '?' + parsed.query
@@ -1309,35 +1308,36 @@
raise ValueError('Text after the $1 placeholder is not supported '
'(T111513).')
- matched_sites = []
for domain in self.domains:
if domain in parsed.netloc:
break
else:
- domain = False
- if domain is not False:
- for code in chain(self.codes, getattr(self, 'test_codes', ())):
- if code in ignored:
- continue
- if self._hostname(code)[1] == parsed.netloc:
- # Use the code and family instead of the url
- # This is only creating a Site instance if domain matches
- site = pywikibot.Site(code, self.name)
- pywikibot.log('Found candidate {0}'.format(site))
+ return None
- for iw_url in site._interwiki_urls():
- if path.startswith(iw_url):
- matched_sites += [site]
- break
+ matched_sites = []
+ for code in chain(self.codes, getattr(self, 'test_codes', ())):
+ if code in self._ignore_from_url:
+ continue
+ if self._hostname(code)[1] == parsed.netloc:
+ # Use the code and family instead of the url
+ # This is only creating a Site instance if domain matches
+ site = pywikibot.Site(code, self.name)
+ pywikibot.log('Found candidate {0}'.format(site))
+
+ for iw_url in site._interwiki_urls():
+ if path.startswith(iw_url):
+ matched_sites += [site]
+ break
if len(matched_sites) == 1:
return matched_sites[0].code
- elif not matched_sites:
+
+ if not matched_sites:
return None
- else:
- raise RuntimeError(
- 'Found multiple matches for URL "{0}": {1}'
- .format(url, ', '.join(str(s) for s in matched_sites)))
+
+ raise RuntimeError(
+ 'Found multiple matches for URL "{0}": {1}'
+ .format(url, ', '.join(str(s) for s in matched_sites)))
def maximum_GET_length(self, code):
"""Return the maximum URL length for GET instead of
POST."""
--
To view, visit
https://gerrit.wikimedia.org/r/508071
To unsubscribe, or for help writing mail filters, visit
https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I123ea6ed4180a22e07a4c95202f885464e831230
Gerrit-Change-Number: 508071
Gerrit-PatchSet: 5
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: Zhuyifei1999 <zhuyifei1999(a)gmail.com>
Gerrit-Reviewer: jenkins-bot (75)