jenkins-bot has submitted this change and it was merged.

Change subject: move string properties normalization into 
WikibasePage#__normalizeData()
......................................................................


move string properties normalization into WikibasePage#__normalizeData()

away from editLabels, editDescriptions and editAliases,
thus allowing to call it from other functions

== use cases ==

currently, to edit some labels, the only valid syntaxes are:
* editLabels({'lang': 'val'})
* editEntity({'labels': {'lang': {'language': 'lang', 'value': 'val'}}})

this change adds the following possibilities:
* editLabels({'lang': {'language': 'lang', 'value': 'val'}})
* editEntity({'labels': {'lang': 'val'}})

Change-Id: Iba1fdce1cc199cda0b7f83febdf48ce6a11100e0
---
M pywikibot/page.py
1 file changed, 17 insertions(+), 9 deletions(-)

Approvals:
  John Vandenberg: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/pywikibot/page.py b/pywikibot/page.py
index 2232a49..cf6f367 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -2740,6 +2740,20 @@
                 del data[key]
         return data
 
+    def __normalizeData(self, data):
+        for prop in ('labels', 'descriptions', 'aliases'):
+            if prop in data:
+                data[prop] = self.__normalizeLanguages(data[prop])
+                if prop == 'aliases':
+                    for key, values in data[prop].iteritems():
+                        for index, value in enumerate(values):
+                            data[prop][key][index] = {'language': key,
+                                                      'value': value}
+                else:
+                    for key, value in data[prop].iteritems():
+                        data[prop][key] = {'language': key, 'value': value}
+        return data
+
     def getdbName(self, site):
         """
         Helper function to obtain a dbName for a Site.
@@ -2768,6 +2782,9 @@
             baserevid = self.lastrevid
         else:
             baserevid = None
+
+        data = self.__normalizeData(data)
+
         updates = self.repo.editEntity(self._defined_by(singular=True), data,
                                        baserevid=baserevid, **kwargs)
         self.lastrevid = updates['entity']['lastrevid']
@@ -2781,9 +2798,6 @@
         value should be the string to set it to.
         You can set it to '' to remove the label.
         """
-        labels = self.__normalizeLanguages(labels)
-        for key in labels:
-            labels[key] = {'language': key, 'value': labels[key]}
         data = {'labels': labels}
         self.editEntity(data, **kwargs)
 
@@ -2796,9 +2810,6 @@
         value should be the string to set it to.
         You can set it to '' to remove the description.
         """
-        descriptions = self.__normalizeLanguages(descriptions)
-        for key in descriptions:
-            descriptions[key] = {'language': key, 'value': descriptions[key]}
         data = {'descriptions': descriptions}
         self.editEntity(data, **kwargs)
 
@@ -2810,9 +2821,6 @@
         as a language or a site object. The
         value should be a list of strings.
         """
-        aliases = self.__normalizeLanguages(aliases)
-        for (key, strings) in list(aliases.items()):
-            aliases[key] = [{'language': key, 'value': i} for i in strings]
         data = {'aliases': aliases}
         self.editEntity(data, **kwargs)
 

-- 
To view, visit https://gerrit.wikimedia.org/r/135139
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Iba1fdce1cc199cda0b7f83febdf48ce6a11100e0
Gerrit-PatchSet: 5
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Ricordisamoa <[email protected]>
Gerrit-Reviewer: John Vandenberg <[email protected]>
Gerrit-Reviewer: Ladsgroup <[email protected]>
Gerrit-Reviewer: Merlijn van Deen <[email protected]>
Gerrit-Reviewer: Ricordisamoa <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
Pywikibot-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikibot-commits

Reply via email to