jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/343698 )

Change subject: Encode default globe in family file.
......................................................................


Encode default globe in family file.

The current default assumes that every Wikibase installation has a
globe named 'earth' which need not be the case. It also assigns
this globe even if overridden by globe_item.

Instead encode the default globe in the family file and only fall
back on the default if neither globe nor globe_item has been set.
Also clarifies that globe_item takes precedence by mentioning this
in docstring and using entity instead of globe in representation.

Note that 'earth' is still implicitly implied in
Coordinate.precision.

Change-Id: I1a13153ebd62e6eb4efbe05cbe09f0bac748ed99
---
M pywikibot/__init__.py
M pywikibot/families/wikidata_family.py
2 files changed, 25 insertions(+), 19 deletions(-)

Approvals:
  Merlijn van Deen: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py
index 42ac0dd..a79f385 100644
--- a/pywikibot/__init__.py
+++ b/pywikibot/__init__.py
@@ -234,10 +234,10 @@
     in the future we can use it for the GeoData extension.
     """
 
-    _items = ('lat', 'lon', 'globe')
+    _items = ('lat', 'lon', 'entity')
 
     @_deprecate_arg('entity', 'globe_item')
-    def __init__(self, lat, lon, alt=None, precision=None, globe='earth',
+    def __init__(self, lat, lon, alt=None, precision=None, globe=None,
                  typ='', name='', dim=None, site=None, globe_item=None):
         """
         Represent a geo coordinate.
@@ -260,26 +260,34 @@
         @param site: The Wikibase site
         @type site: pywikibot.site.DataSite
         @param globe_item: The Wikibase item for the globe, or the entity URI
-                           of this Wikibase item.
+                           of this Wikibase item. Takes precedence over 'globe'
+                           if present.
         @type globe_item: pywikibot.ItemPage or str
         """
         self.lat = lat
         self.lon = lon
         self.alt = alt
         self._precision = precision
-        if globe:
-            globe = globe.lower()
-        self.globe = globe
         self._entity = globe_item
         self.type = typ
         self.name = name
         self._dim = dim
         self.site = site or Site().data_repository()
 
+        if globe:
+            globe = globe.lower()
+        elif not globe_item:
+            globe = site.default_globe()
+        self.globe = globe
+
     @property
     def entity(self):
         """Return the entity uri of the globe."""
         if not self._entity:
+            if self.globe not in self.site.globes():
+                raise CoordinateGlobeUnknownException(
+                    u"%s is not supported in Wikibase yet."
+                    % self.globe)
             return self.site.globes()[self.globe]
 
         if isinstance(self._entity, ItemPage):
@@ -296,10 +304,6 @@
         @return: Wikibase JSON
         @rtype: dict
         """
-        if self.globe not in self.site.globes():
-            raise CoordinateGlobeUnknownException(
-                u"%s is not supported in Wikibase yet."
-                % self.globe)
         return {'latitude': self.lat,
                 'longitude': self.lon,
                 'altitude': self.alt,
@@ -318,16 +322,14 @@
         @type site: pywikibot.site.DataSite
         @rtype: pywikibot.Coordinate
         """
-        globes = {}
-        for k in site.globes():
-            globes[site.globes()[k]] = k
+        globe = None
 
-        globekey = data['globe']
-        if globekey:
+        if data['globe']:
+            globes = {}
+            for name, entity in site.globes().items():
+                globes[entity] = name
+
             globe = globes.get(data['globe'])
-        else:
-            # Default to earth or should we use None here?
-            globe = 'earth'
 
         return cls(data['latitude'], data['longitude'],
                    data['altitude'], data['precision'],
diff --git a/pywikibot/families/wikidata_family.py 
b/pywikibot/families/wikidata_family.py
index 095af3d..392da62 100644
--- a/pywikibot/families/wikidata_family.py
+++ b/pywikibot/families/wikidata_family.py
@@ -1,7 +1,7 @@
 # -*- coding: utf-8 -*-
 """Family module for Wikidata."""
 #
-# (C) Pywikibot team, 2012-2016
+# (C) Pywikibot team, 2012-2017
 #
 # Distributed under the terms of the MIT license.
 #
@@ -60,6 +60,10 @@
         # Per tabularDataStorageFrontendUrl settings in Wikibase
         return ('commons', 'commons')
 
+    def default_globe(self, code):
+        """Default globe for Coordinate datatype."""
+        return 'earth'
+
     def globes(self, code):
         """Supported globes for Coordinate datatype."""
         return {

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I1a13153ebd62e6eb4efbe05cbe09f0bac748ed99
Gerrit-PatchSet: 8
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Lokal Profil <[email protected]>
Gerrit-Reviewer: John Vandenberg <[email protected]>
Gerrit-Reviewer: Lokal Profil <[email protected]>
Gerrit-Reviewer: Magul <[email protected]>
Gerrit-Reviewer: Merlijn van Deen <[email protected]>
Gerrit-Reviewer: Multichill <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to