jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/351921 )
Change subject: [doc] a better doc string for site.code and site.lang properties
......................................................................
[doc] a better doc string for site.code and site.lang properties
give a better explanation for the differences
Change-Id: I189ae24230e23b261a918f594c196a166453e161
---
M pywikibot/site.py
1 file changed, 2 insertions(+), 2 deletions(-)
Approvals:
Lokal Profil: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/site.py b/pywikibot/site.py
index 7f67d03..fa9385b 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -811,7 +811,7 @@
@property
def code(self):
"""
- The identifying code for this Site.
+ The identifying code for this Site equal to the wiki prefix.
By convention, this is usually an ISO language code, but it does
not have to be.
@@ -822,7 +822,7 @@
def lang(self):
"""The ISO language code for this Site.
- Presumed to be equal to the wiki prefix, but this can be overridden.
+ Presumed to be equal to the site code, but this can be overridden.
"""
return self.__code
--
To view, visit https://gerrit.wikimedia.org/r/351921
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I189ae24230e23b261a918f594c196a166453e161
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: Lokal Profil <lokal.profil(a)gmail.com>
Gerrit-Reviewer: Magul <tomasz.magulski(a)gmail.com>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/351880 )
Change subject: Replace private mylang variables with mycode in misspelling.py
......................................................................
Replace private mylang variables with mycode in misspelling.py
site.code is the identifying code of a site presumed to be equal to the
wiki prefix whereas site language is the ISO language code for a site.
e.g. 'als' is a site code whereas its site language is 'gsw'
'meta' is a site code whereas its language is 'en'
Change-Id: I2c6d7ddd457b0889ff3430739c966cfbd5520e09
---
M scripts/misspelling.py
1 file changed, 6 insertions(+), 6 deletions(-)
Approvals:
Dalba: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/misspelling.py b/scripts/misspelling.py
index 1a3aea1..fb65d41 100755
--- a/scripts/misspelling.py
+++ b/scripts/misspelling.py
@@ -22,7 +22,7 @@
wikipedia, user, etc. namespaces.
"""
# (C) Daniel Herding, 2007
-# (C) Pywikibot team, 2007-2016
+# (C) Pywikibot team, 2007-2017
#
# Distributed under the terms of the MIT license.
#
@@ -83,9 +83,9 @@
@rtype: generator
"""
- mylang = self.site.code
- if mylang in self.misspellingCategory:
- categories = self.misspellingCategory[mylang]
+ mycode = self.site.code
+ if mycode in self.misspellingCategory:
+ categories = self.misspellingCategory[mycode]
if isinstance(categories, basestring):
categories = (categories, )
generators = (
@@ -93,8 +93,8 @@
pywikibot.Category(self.site, misspellingCategoryTitle),
recurse=True, start=firstPageTitle)
for misspellingCategoryTitle in categories)
- elif mylang in self.misspellingTemplate:
- templates = self.misspellingTemplate[mylang]
+ elif mycode in self.misspellingTemplate:
+ templates = self.misspellingTemplate[mycode]
if isinstance(templates, basestring):
templates = (templates, )
generators = (
--
To view, visit https://gerrit.wikimedia.org/r/351880
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I2c6d7ddd457b0889ff3430739c966cfbd5520e09
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Dalba <dalba.wiki(a)gmail.com>
Gerrit-Reviewer: Lokal Profil <lokal.profil(a)gmail.com>
Gerrit-Reviewer: Magul <tomasz.magulski(a)gmail.com>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/351697 )
Change subject: Add support for tabular-data Wikibase data type
......................................................................
Add support for tabular-data Wikibase data type
Introduce the WbTabularData class to provide handling of tabular-data
values and do some basic validation on indata.
There are significant overlaps with WbGeoShapes as they only differ
in which repository they (can) use and the required ending of the
page name (.tab rather than .map). As such they should probably be
rebuilt on a shared base at a later stage.
Bug: T163981
Change-Id: I3f15d9732f7bbb552b1d000530d295fccca2fd5f
---
M pywikibot/__init__.py
M pywikibot/families/wikidata_family.py
M pywikibot/page.py
M pywikibot/site.py
M tests/paraminfo_tests.py
M tests/wikibase_edit_tests.py
M tests/wikibase_tests.py
7 files changed, 178 insertions(+), 4 deletions(-)
Approvals:
jenkins-bot: Verified
Xqt: Looks good to me, approved
diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py
index abcf274..8a1ea57 100644
--- a/pywikibot/__init__.py
+++ b/pywikibot/__init__.py
@@ -915,7 +915,7 @@
if not geo_shape_site:
raise ValueError('the provided site does not support geo-shapes.')
if page.site != geo_shape_site:
- raise ValueError('page must be on the image repository site.')
+ raise ValueError('page must be on the geo-shape repository site.')
# validate page title fulfills hard-coded Wikibase requirement
# pcre regexp: '/^Data:[^\\[\\]#\\\:{|}]+\.map$/u'
@@ -944,6 +944,8 @@
@param page_name: page name from Wikibase value
@type page_name: str
+ @param site: The Wikibase site
+ @type site: pywikibot.site.DataSite
@rtype: pywikibot.WbGeoShape
"""
geo_shape_site = site.geo_shape_repository()
@@ -951,6 +953,77 @@
return cls(page, site)
+class WbTabularData(_WbRepresentation):
+ """
+ A Wikibase tabular-data representation.
+
+ A temporary implementation until T162336 has been resolved.
+ """
+
+ _items = ('page', )
+
+ def __init__(self, page, site=None):
+ """
+ Create a new WbTabularData object.
+
+ @param page: page containing the tabular data
+ @type text: pywikibot.Page
+ @param site: The Wikibase site
+ @type site: pywikibot.site.DataSite
+ """
+ site = site or Site().data_repository()
+ if not isinstance(page, Page):
+ raise ValueError('page must be a pywikibot.Page object.')
+
+ # validate page exists
+ if not page.exists():
+ raise ValueError('page must exist.')
+
+ # validate page is on the right site, and site supports tabular-data
+ tabular_data_site = site.tabular_data_repository()
+ if not tabular_data_site:
+ raise ValueError(
+ 'the provided site does not support tabular-data.')
+ if page.site != tabular_data_site:
+ raise ValueError(
+ 'page must be on the tabular-data repository site.')
+
+ # validate page title fulfills hard-coded Wikibase requirement
+ # pcre regexp: '/^Data:[^\\[\\]#\\\:{|}]+\.tab$/u'
+ # As we have already checked for existence the following simplified
+ # check should be enough.
+ if not page.title().startswith('Data:') or \
+ not page.title().endswith('.tab'):
+ raise ValueError(
+ "page must be a '.tab' page in the 'Data:' namespace.")
+
+ self.page = page
+
+ def toWikibase(self):
+ """
+ Convert the data to the value required by the Wikibase API.
+
+ @return: title of the tabular-data page incl. namespace
+ @rtype: str
+ """
+ return self.page.title()
+
+ @classmethod
+ def fromWikibase(cls, page_name, site):
+ """
+ Create a WbTabularData from the JSON data given by the Wikibase API.
+
+ @param page_name: page name from Wikibase value
+ @type page_name: str
+ @param site: The Wikibase site
+ @type site: pywikibot.site.DataSite
+ @rtype: pywikibot.WbTabularData
+ """
+ tabular_data_site = site.tabular_data_repository()
+ page = Page(tabular_data_site, page_name)
+ return cls(page, site)
+
+
_sites = {}
_url_cache = {} # The code/fam pair for each URL
diff --git a/pywikibot/families/wikidata_family.py b/pywikibot/families/wikidata_family.py
index 4b30106..095af3d 100644
--- a/pywikibot/families/wikidata_family.py
+++ b/pywikibot/families/wikidata_family.py
@@ -55,6 +55,11 @@
# Per geoShapeStorageFrontendUrl settings in Wikibase
return ('commons', 'commons')
+ def shared_tabular_data_repository(self, code):
+ """Return Wikimedia Commons as the repository for tabular-datas."""
+ # Per tabularDataStorageFrontendUrl settings in Wikibase
+ return ('commons', 'commons')
+
def globes(self, code):
"""Supported globes for Coordinate datatype."""
return {
diff --git a/pywikibot/page.py b/pywikibot/page.py
index 69ae094..cb4a17a 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -4405,6 +4405,7 @@
'math': basestring,
'external-id': basestring,
'geo-shape': pywikibot.WbGeoShape,
+ 'tabular-data': pywikibot.WbTabularData,
}
value_types = {'wikibase-item': 'wikibase-entityid',
@@ -4415,6 +4416,7 @@
'math': 'string',
'external-id': 'string',
'geo-shape': 'string',
+ 'tabular-data': 'string',
}
def __init__(self, site, id, datatype=None):
@@ -4550,6 +4552,7 @@
FilePage(pywikibot.Site('commons', 'commons'), value), # T90492
'globe-coordinate': pywikibot.Coordinate.fromWikibase,
'geo-shape': pywikibot.WbGeoShape.fromWikibase,
+ 'tabular-data': pywikibot.WbTabularData.fromWikibase,
'time': pywikibot.WbTime.fromWikibase,
'quantity': pywikibot.WbQuantity.fromWikibase,
'monolingualtext': lambda value, site:
@@ -4976,7 +4979,7 @@
value = self.getTarget().title(withNamespace=False)
elif self.type in ('globe-coordinate', 'time',
'quantity', 'monolingualtext',
- 'geo-shape'):
+ 'geo-shape', 'tabular-data'):
value = self.getTarget().toWikibase()
else:
raise NotImplementedError('%s datatype is not supported yet.'
diff --git a/pywikibot/site.py b/pywikibot/site.py
index a16bdea..7f67d03 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -7269,11 +7269,18 @@
def geo_shape_repository(self):
"""Return Site object for the geo-shapes repository e.g. commons."""
- # Do this via API instead if T162561 is implemented.
+ # Do this via API instead when T162561 is implemented.
code, fam = self.shared_geo_shape_repository()
if bool(code or fam):
return pywikibot.Site(code, fam, self.username())
+ def tabular_data_repository(self):
+ """Return Site object for the tabular-datas repository e.g. commons."""
+ # Do this via API instead when T164413 is implemented.
+ code, fam = self.shared_tabular_data_repository()
+ if bool(code or fam):
+ return pywikibot.Site(code, fam, self.username())
+
def loadcontent(self, identification, *props):
"""
Fetch the current content of a Wikibase item.
diff --git a/tests/paraminfo_tests.py b/tests/paraminfo_tests.py
index b1f7232..e2e4263 100644
--- a/tests/paraminfo_tests.py
+++ b/tests/paraminfo_tests.py
@@ -229,7 +229,7 @@
def test_datatypes(self):
"""Test that all encountered datatypes are known."""
- unsupported = set(['tabular-data'])
+ unsupported = set()
known = set(Property.types) | unsupported
self._check_param_superset(
self.repo, 'wbformatvalue', 'datatype', known)
diff --git a/tests/wikibase_edit_tests.py b/tests/wikibase_edit_tests.py
index f5ffab4..7ae5dd0 100644
--- a/tests/wikibase_edit_tests.py
+++ b/tests/wikibase_edit_tests.py
@@ -341,6 +341,26 @@
claim = item.claims['P27199'][0]
self.assertEqual(claim.getTarget(), target)
+ def test_WbTabularData_edit(self):
+ """Attempt adding a tabular-data with valid input."""
+ # Clean the slate in preparation for test.
+ testsite = self.get_repo()
+ item = self._clean_item(testsite, 'P30175')
+
+ # set new claim
+ claim = pywikibot.page.Claim(
+ testsite, 'P30175', datatype='tabular-data')
+ commons_site = pywikibot.Site('commons', 'commons')
+ page = pywikibot.Page(commons_site, 'Data:Bea.gov/GDP by state.tab')
+ target = pywikibot.WbGeoShape(page)
+ claim.setTarget(target)
+ item.addClaim(claim)
+
+ # confirm new claim
+ item.get(force=True)
+ claim = item.claims['P30175'][0]
+ self.assertEqual(claim.getTarget(), target)
+
class TestWikibaseRemoveQualifier(WikibaseTestCase):
diff --git a/tests/wikibase_tests.py b/tests/wikibase_tests.py
index 8cdaf70..d66a9d9 100644
--- a/tests/wikibase_tests.py
+++ b/tests/wikibase_tests.py
@@ -680,6 +680,72 @@
non_map_page, self.get_repo())
+class TestWbTabularDataNonDry(WikidataTestCase):
+
+ """
+ Test Wikibase WbTabularData data type (non-dry).
+
+ These require non dry tests due to the page.exists() call.
+ """
+
+ def setUp(self):
+ """Setup tests."""
+ self.commons = pywikibot.Site('commons', 'commons')
+ self.page = Page(self.commons, 'Data:Bea.gov/GDP by state.tab')
+ super(TestWbTabularDataNonDry, self).setUp()
+
+ def test_WbTabularData_page(self):
+ """Test WbTabularData page."""
+ q = pywikibot.WbTabularData(self.page)
+ q_val = u'Data:Bea.gov/GDP by state.tab'
+ self.assertEqual(q.toWikibase(), q_val)
+
+ def test_WbTabularData_page_and_site(self):
+ """Test WbTabularData from page and site."""
+ q = pywikibot.WbTabularData(self.page, self.get_repo())
+ q_val = u'Data:Bea.gov/GDP by state.tab'
+ self.assertEqual(q.toWikibase(), q_val)
+
+ def test_WbTabularData_equality(self):
+ """Test WbTabularData equality."""
+ q = pywikibot.WbTabularData(self.page, self.get_repo())
+ self.assertEqual(q, q)
+
+ def test_WbTabularData_fromWikibase(self):
+ """Test WbTabularData.fromWikibase() instantiating."""
+ repo = self.get_repo()
+ q = pywikibot.WbTabularData.fromWikibase(
+ 'Data:Bea.gov/GDP by state.tab', repo)
+ self.assertEqual(q.toWikibase(), 'Data:Bea.gov/GDP by state.tab')
+
+ def test_WbTabularData_error_on_non_page(self):
+ """Test WbTabularData error handling when given a non-page."""
+ self.assertRaises(ValueError, pywikibot.WbTabularData,
+ 'A string', self.get_repo())
+
+ def test_WbTabularData_error_on_non_exitant_page(self):
+ """Test WbTabularData error handling of a non-existant page."""
+ page = Page(self.commons, 'Non-existant page... really')
+ self.assertRaises(ValueError, pywikibot.WbTabularData,
+ page, self.get_repo())
+
+ def test_WbTabularData_error_on_wrong_site(self):
+ """Test WbTabularData error handling of a page on non-filerepo site."""
+ repo = self.get_repo()
+ page = Page(repo, 'Q123')
+ self.assertRaises(ValueError, pywikibot.WbTabularData,
+ page, self.get_repo())
+
+ def test_WbTabularData_error_on_wrong_page_type(self):
+ """Test WbTabularData error handling of a non-map page."""
+ non_data_page = Page(self.commons, 'File:Foo.jpg')
+ non_map_page = Page(self.commons, 'Data:Lyngby Hovedgade.map')
+ self.assertRaises(ValueError, pywikibot.WbTabularData,
+ non_data_page, self.get_repo())
+ self.assertRaises(ValueError, pywikibot.WbTabularData,
+ non_map_page, self.get_repo())
+
+
class TestItemPageExtensibility(TestCase):
"""Test ItemPage extensibility."""
--
To view, visit https://gerrit.wikimedia.org/r/351697
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I3f15d9732f7bbb552b1d000530d295fccca2fd5f
Gerrit-PatchSet: 4
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Lokal Profil <lokal.profil(a)gmail.com>
Gerrit-Reviewer: Dalba <dalba.wiki(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: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>