Xqt has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/337224 )
Change subject: piper.py: fix bytes/str handling in python3
......................................................................
piper.py: fix bytes/str handling in python3
Avoid to convert to bytes in python3.
Bug: T157215
Change-Id: I2c3d7611b5aca32b4b51339c4a162851e13bacf7
---
M scripts/piper.py
1 file changed, 8 insertions(+), 4 deletions(-)
Approvals:
jenkins-bot: Verified
Merlijn van Deen: Looks good to me, approved
diff --git a/scripts/piper.py b/scripts/piper.py
index d15e4c8..4a373ec 100755
--- a/scripts/piper.py
+++ b/scripts/piper.py
@@ -47,6 +47,7 @@
from pywikibot import pagegenerators
from pywikibot.bot import (MultipleSitesBot, ExistingPageBot,
NoRedirectPageBot, AutomaticTWSummaryBot)
+from pywikibot.tools import UnicodeType
# This is required for the text that is shown when you run this script
# with the parameter -help.
@@ -86,9 +87,10 @@
@return: processed text after piping
@rtype: unicode
"""
- text = text.encode('utf-8')
+ if not isinstance(text, str): # py2-py3 compatibility
+ text = text.encode('utf-8')
pipe = pipes.Template()
- pipe.append(program.encode('ascii'), '--')
+ pipe.append(str(program), '--') # py2-py3 compatibility
# Create a temporary filename to save the piped stuff to
tempFilename = '%s.%s' % (tempfile.mktemp(), 'txt')
@@ -96,8 +98,10 @@
file.write(text)
# Now retrieve the munged text
- with open(tempFilename, 'r') as mungedText:
- unicode_text = mungedText.read().decode('utf-8')
+ with open(tempFilename, 'r') as file:
+ unicode_text = file.read()
+ if not isinstance(unicode_text, UnicodeType): # py2-py3 compatibility
+ unicode_text = unicode_text.decode('utf-8')
# clean up
os.unlink(tempFilename)
--
To view, visit https://gerrit.wikimedia.org/r/337224
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I2c3d7611b5aca32b4b51339c4a162851e13bacf7
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Magul <tomasz.magulski(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>
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 <lokal.profil(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Lokal Profil <lokal.profil(a)gmail.com>
Gerrit-Reviewer: Magul <tomasz.magulski(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Multichill <maarten(a)mdammers.nl>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>