jenkins-bot has submitted this change and it was merged.
Change subject: Implement support for monolingual text values ......................................................................
Implement support for monolingual text values
Bug: T85385 Change-Id: Ide81dafa520dfd52629d17f919c7ccc40335bea2 --- M pywikibot/__init__.py M pywikibot/page.py 2 files changed, 41 insertions(+), 1 deletion(-)
Approvals: Ladsgroup: Looks good to me, approved Multichill: Looks good to me, but someone else must approve jenkins-bot: Verified
diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py index 114c204..609d4f8 100644 --- a/pywikibot/__init__.py +++ b/pywikibot/__init__.py @@ -540,6 +540,43 @@ return cls(amount, wb['unit'], error)
+class WbMonolingualText(_WbRepresentation): + """A Wikibase monolingual text representation.""" + + def __init__(self, text, language): + """ + Create a new WbMonolingualText object. + + @param text: text string + @type text: str + @param language: language code of the string + @type language: str + """ + self.text = text + self.language = language + + def toWikibase(self): + """ + Convert the data to a JSON object for the Wikibase API. + + @return: Wikibase JSON + @rtype: dict + """ + json = {'text': self.text, + 'language': self.language + } + return json + + @classmethod + def fromWikibase(cls, wb): + """ + Create a WbMonolingualText from the JSON data given by the Wikibase API. + + @param wb: Wikibase JSON + @type wb: dict + """ + return cls(wb['text'], wb['language']) + _sites = {} _url_cache = {} # The code/fam pair for each URL
diff --git a/pywikibot/page.py b/pywikibot/page.py index a532664..cbaeb49 100644 --- a/pywikibot/page.py +++ b/pywikibot/page.py @@ -4114,6 +4114,8 @@ 'globe-coordinate': pywikibot.Coordinate.fromWikibase, 'time': lambda value, site: pywikibot.WbTime.fromWikibase(value), 'quantity': lambda value, site: pywikibot.WbQuantity.fromWikibase(value), + 'monolingualtext': lambda value, site: + pywikibot.WbMonolingualText.fromWikibase(value) }
SNAK_TYPES = ('value', 'somevalue', 'novalue') @@ -4532,7 +4534,8 @@ value = self.getTarget() elif self.type == 'commonsMedia': value = self.getTarget().title(withNamespace=False) - elif self.type in ('globe-coordinate', 'time', 'quantity'): + elif self.type in ('globe-coordinate', 'time', + 'quantity', 'monolingualtext'): value = self.getTarget().toWikibase() else: raise NotImplementedError('%s datatype is not supported yet.'