Smalyshev has uploaded a new change for review.
https://gerrit.wikimedia.org/r/232406
Change subject: T85385: implement support for monolingual text
......................................................................
T85385: implement support for monolingual text
Change-Id: Ide81dafa520dfd52629d17f919c7ccc40335bea2
---
M pywikibot/__init__.py
M pywikibot/page.py
2 files changed, 46 insertions(+), 0 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core
refs/changes/06/232406/1
diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py
index b1d2cc3..4197937 100644
--- a/pywikibot/__init__.py
+++ b/pywikibot/__init__.py
@@ -524,6 +524,50 @@
return (u"WbQuantity(amount=%(amount)s, upperBound=%(upperBound)s, "
u"lowerBound=%(lowerBound)s, unit=%(unit)s)" % self.__dict__)
+class WbMonolingualText(object):
+ """A Wikibase monolingual text representation."""
+
+ def __init__(self, text, language):
+ u"""
+ Create a new WbMonolingualText object.
+
+ @param text: number representing this quantity
+ @type text: string
+ @param language: not used (only unit-less quantities are supported)
+ @type text: string
+ """
+ self.text = text
+ self.language = language
+
+ def toWikibase(self):
+ """
+ Convert the data to a JSON object for the Wikibase API.
+
+ @return: 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
+ """
+ return cls(wb['text'], wb['language'])
+
+ def __str__(self):
+ return json.dumps(self.toWikibase(), indent=4, sort_keys=True,
+ separators=(',', ': '))
+
+ def __eq__(self, other):
+ return self.__dict__ == other.__dict__
+
+ def __repr__(self):
+ return (u"WbMonolingualText(text=%(text)s, language=%(language)s)" %
self.__dict__)
_sites = {}
_url_cache = {} # The code/fam pair for each URL
diff --git a/pywikibot/page.py b/pywikibot/page.py
index 5c0ee75..aabdf12 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -3914,6 +3914,7 @@
'url': basestring,
'time': pywikibot.WbTime,
'quantity': pywikibot.WbQuantity,
+ 'monolingualtext': pywikibot.WbMonolingualText,
}
value_types = {'wikibase-item': 'wikibase-entityid',
@@ -4038,6 +4039,7 @@
'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),
}
def __init__(self, site, pid, snak=None, hash=None, isReference=False,
--
To view, visit https://gerrit.wikimedia.org/r/232406
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ide81dafa520dfd52629d17f919c7ccc40335bea2
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Smalyshev <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits