jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/638422 )
Change subject: [IMPR] create a Site from sitename ......................................................................
[IMPR] create a Site from sitename
like
s = pywikibot.Site('wikipedia:test')
Change-Id: I0ee625bbc8ed7ccae45679e5b92b53b84d7f51dc --- M pywikibot/__init__.py 1 file changed, 9 insertions(+), 2 deletions(-)
Approvals: Hazard-SJ: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py index e9f40c7..56252c1 100644 --- a/pywikibot/__init__.py +++ b/pywikibot/__init__.py @@ -1098,6 +1098,7 @@ using the method parameters.
@param code: language code (override config.mylang) + code may also be a sitename like 'wikipedia:test' @param fam: family name or object (override config.family) @type fam: str or pywikibot.family.Family @param user: bot user name to use on this site (override config.usernames) @@ -1123,13 +1124,19 @@ 'URL to the wiki OR a pair of code and family name ' 'should be provided') code, fam = _code_fam_from_url(url) + elif code and ':' in code: + if fam: + raise ValueError( + 'sitename OR a pair of code and family name ' + 'should be provided') + fam, _, code = code.partition(':') else: # Fallback to config defaults code = code or config.mylang fam = fam or config.family
- if not isinstance(fam, Family): - fam = Family.load(fam) + if not isinstance(fam, Family): + fam = Family.load(fam)
interface = interface or fam.interface(code)
pywikibot-commits@lists.wikimedia.org