Ricordisamoa has uploaded a new change for review. https://gerrit.wikimedia.org/r/138285
Change subject: BREAKING: rename Claim._formatDataValue() into _formatValue() ...................................................................... BREAKING: rename Claim._formatDataValue() into _formatValue() and create a new _formatDataValue() method which returns _formatValue() as 'value' and the value type as 'type' for clarity reasons, and also to reduce code duplication in site.py and in Ibe77c51fc5cf3dae8ece533cc5787bf960f0ebed (yet to come) Change-Id: If8de1887f34d83a38e1a0b05279c5b8eb68a1e8a --- M pywikibot/page.py M pywikibot/site.py M tests/wikibase_tests.py 3 files changed, 21 insertions(+), 21 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core refs/changes/85/138285/1 diff --git a/pywikibot/page.py b/pywikibot/page.py index 33d3c6d..4f79a21 100644 --- a/pywikibot/page.py +++ b/pywikibot/page.py @@ -2775,6 +2775,12 @@ 'quantity': pywikibot.WbQuantity, } + value_types = {'wikibase-item': 'wikibase-entityid', + 'commonsMedia': 'string', + 'url': 'string', + 'globe-coordinate': 'globecoordinate', + } + def __init__(self, site, id=None): self.repo = site self.id = id.upper() @@ -3071,9 +3077,9 @@ self.on_item.lastrevid = data['pageinfo']['lastrevid'] self.qualifiers[qualifier.getID()].append(qualifier) - def _formatDataValue(self): + def _formatValue(self): """ - Format the target into the proper JSON datavalue that Wikibase wants + Format the target into the proper JSON value that Wikibase wants """ if self.type == 'wikibase-item': value = {'entity-type': 'item', @@ -3089,6 +3095,14 @@ % self.type) return value + def _formatDataValue(self): + """ + Format the target into the proper JSON datavalue that Wikibase wants + """ + return {'value': self._formatValue(), + 'type': self.value_types.get(*[self.type] * 2) + } + class Revision(object): """A structure holding information about a single revision of a Page.""" diff --git a/pywikibot/site.py b/pywikibot/site.py index ea1cbad..beb960b 100644 --- a/pywikibot/site.py +++ b/pywikibot/site.py @@ -3762,7 +3762,7 @@ if bot: params['bot'] = 1 if claim.getSnakType() == 'value': - params['value'] = json.dumps(claim._formatDataValue()) + params['value'] = json.dumps(claim._formatValue()) if 'summary' in kwargs: params['summary'] = kwargs['summary'] params['token'] = self.token(item, 'edit') @@ -3797,7 +3797,7 @@ params['summary'] = kwargs['summary'] params['token'] = self.token(claim, 'edit') if snaktype == 'value': - params['value'] = json.dumps(claim._formatDataValue()) + params['value'] = json.dumps(claim._formatValue()) params['baserevid'] = claim.on_item.lastrevid req = api.Request(site=self, **params) @@ -3833,21 +3833,7 @@ snak = {} for sourceclaim in sources: - if sourceclaim.type == 'wikibase-item': - datavalue = {'type': 'wikibase-entityid', - 'value': sourceclaim._formatDataValue(), - } - elif sourceclaim.type in ['string', 'url']: - datavalue = {'type': 'string', - 'value': sourceclaim._formatDataValue(), - } - elif sourceclaim.type == 'time': - datavalue = {'type': 'time', - 'value': sourceclaim._formatDataValue(), - } - else: - raise NotImplementedError('%s datatype is not supported yet.' - % sourceclaim.type) + datavalue = sourceclaim._formatDataValue(), valuesnaks = [] if sourceclaim.getID() in snak: valuesnaks = snak[sourceclaim.getID()] @@ -3897,7 +3883,7 @@ params['token'] = self.token(claim, 'edit') # build up the snak if qualifier.getSnakType() == 'value': - params['value'] = json.dumps(qualifier._formatDataValue()) + params['value'] = json.dumps(qualifier._formatValue()) params['snaktype'] = qualifier.getSnakType() params['property'] = qualifier.getID() diff --git a/tests/wikibase_tests.py b/tests/wikibase_tests.py index a8b52e1..0f72e47 100644 --- a/tests/wikibase_tests.py +++ b/tests/wikibase_tests.py @@ -54,7 +54,7 @@ claim = pywikibot.Claim(repo, 'p21') self.assertRaises(ValueError, claim.setTarget, value="test") claim.setTarget(pywikibot.ItemPage(repo, 'q1')) - self.assertEqual(claim._formatDataValue(), {'entity-type': 'item', 'numeric-id': 1}) + self.assertEqual(claim._formatValue(), {'entity-type': 'item', 'numeric-id': 1}) # test WbTime t = pywikibot.WbTime(site=wikidata, year=2010, hour=12, minute=43) -- To view, visit https://gerrit.wikimedia.org/r/138285 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: If8de1887f34d83a38e1a0b05279c5b8eb68a1e8a Gerrit-PatchSet: 1 Gerrit-Project: pywikibot/core Gerrit-Branch: master Gerrit-Owner: Ricordisamoa <ricordisa...@openmailbox.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits