John Vandenberg has uploaded a new change for review.
https://gerrit.wikimedia.org/r/181880
Change subject: pywikibot.Site() code and fam defaults
......................................................................
pywikibot.Site() code and fam defaults
pywikibot.Site allowed overriding only one of code or fam.
pywikibot.Site(code=None, fam='foo') is now prevented by an assertion,
and pywikibot.Site(code='en') is now deprecated with a warning that
also informs the user which family was selected by default.
Change-Id: Ice0f11c9f46ace5b93e124f7cb668b4dd09ff223
---
M pywikibot/__init__.py
M pywikibot/textlib.py
M scripts/interwiki.py
3 files changed, 21 insertions(+), 7 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core
refs/changes/80/181880/1
diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py
index 40dde82..41ccc79 100644
--- a/pywikibot/__init__.py
+++ b/pywikibot/__init__.py
@@ -529,6 +529,8 @@
By default rely on config settings. These defaults may all be overridden
using the method parameters.
+ fam and code should always be overridden together.
+
@param code: language code (override config.mylang)
@type code: string
@param fam: family name or object (override config.family)
@@ -571,9 +573,16 @@
# AutoFamily
raise Error("Unknown URL '{0}'.".format(url))
else:
+ if fam:
+ assert(code)
+ if code and not fam:
+ pywikibot.warning(u'pywikibot.Site(code=%r) is deprecated; please '
+ u'specify the family. Defaulting to family %s.'
+ % (code, config.family))
# Fallback to config defaults
code = code or config.mylang
fam = fam or config.family
+
interface = interface or config.site_interface
# config.usernames is initialised with a dict for each family name
diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py
index 530dc70..f7a8da6 100644
--- a/pywikibot/textlib.py
+++ b/pywikibot/textlib.py
@@ -624,11 +624,15 @@
def interwikiFormat(links, insite=None):
"""Convert interwiki link dict into a wikitext string.
- 'links' should be a dict with the Site objects as keys, and Page
- or Link objects as values.
-
- Return a unicode string that is formatted for inclusion in insite
- (defaulting to the current site).
+ @param links: interwiki links to be formatted
+ @type links: dict with the Site objects as keys, and Page
+ or Link objects as values.
+ @param insite: site the interwiki links will be formatted for
+ (defaulting to the current site).
+ @type insite: BaseSite
+ @return: string including wiki links formatted for inclusion
+ in insite
+ @rtype: unicode
"""
if insite is None:
insite = pywikibot.Site()
@@ -644,7 +648,8 @@
link = title.replace('[[:', '[[')
s.append(link)
except AttributeError:
- s.append(pywikibot.Site(code=site).linkto(links[site],
othersite=insite))
+ s.append(pywikibot.Site(site, insite.family).linkto(
+ links[site], othersite=insite))
if insite.lang in insite.family.interwiki_on_one_line:
sep = u' '
else:
diff --git a/scripts/interwiki.py b/scripts/interwiki.py
index 396a085..cafbbbc 100755
--- a/scripts/interwiki.py
+++ b/scripts/interwiki.py
@@ -1680,7 +1680,7 @@
frgnSiteDone = False
for siteCode in lclSite.family.languages_by_size:
- site = pywikibot.Site(siteCode)
+ site = pywikibot.Site(siteCode, lclSite.family)
if (not lclSiteDone and site == lclSite) or \
(not frgnSiteDone and site != lclSite and site in new):
if site == lclSite:
--
To view, visit https://gerrit.wikimedia.org/r/181880
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ice0f11c9f46ace5b93e124f7cb668b4dd09ff223
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits