jenkins-bot has submitted this change and it was merged.
Change subject: [FIX] Prevent string comparison for Coordinate
......................................................................
[FIX] Prevent string comparison for Coordinate
When it tries to compare a string to `Coordinate` it previously parsed the
string and returned True if the string matched the coordinate. Otherwise it
just continued to work on it and compared the object with the string directly
which never evaluated to …
[View More]True, so it always returned False.
But with 4f4770f3 `Coordinate` implements `__eq__` and now that method tries to
compare a string to a `Coordinate` and that raises a `AttributeError`. So
instead of just returning True and falling back to the default comparison
otherwise it directly returns False if the comparison with the parsed string
failed.
Change-Id: Ibe322383a319c57fd20db43758f87864550ea0e4
---
M pywikibot/page.py
1 file changed, 2 insertions(+), 3 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
Hashar: Looks good to me, but someone else must approve
jenkins-bot: Verified
diff --git a/pywikibot/page.py b/pywikibot/page.py
index a69f09a..652773e 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -4428,9 +4428,8 @@
except TypeError:
pass
- if (abs(self.target.lat - coord_args[0]) <= precision and
- abs(self.target.lon - coord_args[1]) <= precision):
- return True
+ return (abs(self.target.lat - coord_args[0]) <= precision and
+ abs(self.target.lon - coord_args[1]) <= precision)
if self.target == value:
return True
--
To view, visit https://gerrit.wikimedia.org/r/247042
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ibe322383a319c57fd20db43758f87864550ea0e4
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: Hashar <hashar(a)free.fr>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: jenkins-bot <>
[View Less]
jenkins-bot has submitted this change and it was merged.
Change subject: Allow APISite._request expiry = None
......................................................................
Allow APISite._request expiry = None
Revise APISite.watched_pages to use expiry=None
when force=True
Change-Id: Iaa199b2dd8b255346f5cddd4ba945b6c26d93418
---
M pywikibot/data/api.py
M pywikibot/site.py
M tests/site_tests.py
3 files changed, 39 insertions(+), 8 deletions(-)
Approvals:
John Vandenberg: Looks …
[View More]good to me, but someone else must approve
XZise: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py
index 8ce923b..15c1c4d 100644
--- a/pywikibot/data/api.py
+++ b/pywikibot/data/api.py
@@ -1513,6 +1513,9 @@
@return: The normalized keyword arguments.
@rtype: dict
"""
+ if 'expiry' in kwargs and kwargs['expiry'] is None:
+ del kwargs['expiry']
+
args = set()
for super_cls in inspect.getmro(cls):
if not super_cls.__name__.endswith('Request'):
@@ -2194,6 +2197,7 @@
@param expiry: either a number of days or a datetime.timedelta object
"""
+ assert expiry is not None
super(CachedRequest, self).__init__(*args, **kwargs)
if not isinstance(expiry, datetime.timedelta):
expiry = datetime.timedelta(expiry)
diff --git a/pywikibot/site.py b/pywikibot/site.py
index 25dedf7..9dc34b3 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -1885,13 +1885,16 @@
# This checks expiry in kwargs and not kwargs['parameters'] so it won't
# create a CachedRequest when there is an expiry in an API parameter
# and kwargs here are actually in parameters mode.
- if 'expiry' in kwargs:
+ if 'expiry' in kwargs and kwargs['expiry'] is not None:
return api.CachedRequest
else:
return api.Request
def _request(self, **kwargs):
"""Create a request by forwarding all parameters directly."""
+ if 'expiry' in kwargs and kwargs['expiry'] is None:
+ del kwargs['expiry']
+
return self._request_class(kwargs)(site=self, **kwargs)
def _simple_request(self, **kwargs):
@@ -6362,13 +6365,10 @@
self.login(sysop=sysop)
if not total:
total = pywikibot.config.special_page_limit
- if force:
- gen = api.PageGenerator(site=self, generator='watchlistraw',
- step=step, gwrlimit=total)
- else:
- gen = api.PageGenerator(
- site=self, generator='watchlistraw', step=step,
- expiry=pywikibot.config.API_config_expiry, gwrlimit=total)
+ expiry = None if force else pywikibot.config.API_config_expiry
+ gen = api.PageGenerator(site=self, generator='watchlistraw',
+ expiry=expiry,
+ step=step, gwrlimit=total)
return gen
# aliases for backwards compatibility
diff --git a/tests/site_tests.py b/tests/site_tests.py
index b0b51f8..99ef485 100644
--- a/tests/site_tests.py
+++ b/tests/site_tests.py
@@ -1239,6 +1239,33 @@
self.assertNotIn("patrolled", change)
+class TestUserWatchedPages(DefaultSiteTestCase):
+
+ """Test user watched pages."""
+
+ user = True
+
+ def test_watched_pages(self):
+ """Test the site.watched_pages() method."""
+ gen = self.site.watched_pages(total=5, force=False)
+ self.assertIsInstance(gen.request, api.CachedRequest)
+ for page in gen:
+ self.assertIsInstance(page, pywikibot.Page)
+ # repeat to use the cache
+ gen = self.site.watched_pages(total=5, force=False)
+ self.assertIsInstance(gen.request, api.CachedRequest)
+ for page in gen:
+ self.assertIsInstance(page, pywikibot.Page)
+
+ def test_watched_pages_uncached(self):
+ """Test the site.watched_pages() method uncached."""
+ gen = self.site.watched_pages(total=5, force=True)
+ self.assertIsInstance(gen.request, api.Request)
+ self.assertFalse(issubclass(gen.request_class, api.CachedRequest))
+ for page in gen:
+ self.assertIsInstance(page, pywikibot.Page)
+
+
class SearchTestCase(DefaultSiteTestCase):
"""Test search method."""
--
To view, visit https://gerrit.wikimedia.org/r/237009
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Iaa199b2dd8b255346f5cddd4ba945b6c26d93418
Gerrit-PatchSet: 7
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>
[View Less]
jenkins-bot has submitted this change and it was merged.
Change subject: Use RecentChangesTestCase for two tests using RC
......................................................................
Use RecentChangesTestCase for two tests using RC
RecentChangesTestCase avoids running RecentChanges
related tests on sites which do not have a regular
flow of RecentChanges data.
Change-Id: Idf0efff747b402a7c604f5decc3c3d9fe2b49b57
---
M tests/pagegenerators_tests.py
1 file changed, 4 insertions(+), …
[View More]3 deletions(-)
Approvals:
John Vandenberg: Looks good to me, but someone else must approve
XZise: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/pagegenerators_tests.py b/tests/pagegenerators_tests.py
index 3f9cb4f..5c5e207 100755
--- a/tests/pagegenerators_tests.py
+++ b/tests/pagegenerators_tests.py
@@ -828,8 +828,8 @@
self.assertTrue(all(isinstance(item, pywikibot.Page) for item in pages))
-class PageGeneratorIntersectTestCase(DefaultSiteTestCase,
- GeneratorIntersectTestCase):
+class PageGeneratorIntersectTestCase(GeneratorIntersectTestCase,
+ RecentChangesTestCase):
"""Page intersect_generators test cases."""
@@ -846,7 +846,8 @@
pagegenerators.RecentChangesPageGenerator(site=site, total=200)])
-class EnglishWikipediaPageGeneratorIntersectTestCase(GeneratorIntersectTestCase):
+class EnWikipediaPageGeneratorIntersectTestCase(GeneratorIntersectTestCase,
+ RecentChangesTestCase):
"""Page intersect_generators test cases."""
--
To view, visit https://gerrit.wikimedia.org/r/246805
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Idf0efff747b402a7c604f5decc3c3d9fe2b49b57
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>
[View Less]
jenkins-bot has submitted this change and it was merged.
Change subject: Remove panoramiopicker Site object creation
......................................................................
Remove panoramiopicker Site object creation
b866f7d1 introduced a requirement that Site objects
must not be created during script tests command line
argument handling, such as when invoked using -help
and -simulate without arguments.
The script panoramiopicker was added after this, and
had automatic Site …
[View More]object creation during import,
similar to those removed in 537ad64.
Bug: T74120
Change-Id: I94c449fa665afc71506baf1abebc97897e80f223
---
M scripts/panoramiopicker.py
1 file changed, 21 insertions(+), 11 deletions(-)
Approvals:
John Vandenberg: Looks good to me, but someone else must approve
XZise: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/panoramiopicker.py b/scripts/panoramiopicker.py
index d5927ed..34dc169 100644
--- a/scripts/panoramiopicker.py
+++ b/scripts/panoramiopicker.py
@@ -61,8 +61,7 @@
return StringIO.StringIO(imageFile)
-def findDuplicateImages(photo=None,
- site=pywikibot.Site(u'commons', u'commons')):
+def findDuplicateImages(photo=None, site=None):
"""Return list of duplicate images.
Takes the photo, calculates the SHA1 hash and asks the mediawiki api
@@ -71,6 +70,9 @@
TODO: Add exception handling, fix site thing
"""
+ if not site:
+ site = pywikibot.Site('commons', 'commons')
+
hashObject = hashlib.sha1()
hashObject.update(photo.getvalue())
return site.allimages(sha1=base64.b16encode(hashObject.digest()))
@@ -95,12 +97,15 @@
return photoInfo
-def getFilename(photoInfo=None, site=pywikibot.Site(u'commons', u'commons'),
+def getFilename(photoInfo=None, site=None,
project=u'Panoramio'):
"""Build a good filename for the upload.
The name is based on the username and the title. Prevents naming collisions.
"""
+ if not site:
+ site = pywikibot.Site('commons', 'commons')
+
username = photoInfo.get(u'owner_name')
title = photoInfo.get(u'photo_title')
if title:
@@ -195,18 +200,21 @@
def processPhoto(photoInfo=None, panoramioreview=False, reviewer=u'',
- override=u'', addCategory=u'', autonomous=False):
+ override=u'', addCategory=u'', autonomous=False, site=None):
"""Process a single Panoramio photo."""
+ if not site:
+ site = pywikibot.Site('commons', 'commons')
+
if isAllowedLicense(photoInfo) or override:
# Should download the photo only once
photo = downloadPhoto(photoInfo.get(u'photo_file_url'))
# Don't upload duplicate images, should add override option
- duplicates = findDuplicateImages(photo)
+ duplicates = findDuplicateImages(photo, site=site)
if duplicates:
pywikibot.output(u'Found duplicate image at %s' % duplicates.pop())
else:
- filename = getFilename(photoInfo)
+ filename = getFilename(photoInfo, site=site)
pywikibot.output(filename)
description = getDescription(photoInfo, panoramioreview,
reviewer, override, addCategory)
@@ -236,7 +244,7 @@
description=newDescription,
useFilename=newFilename,
keepFilename=True,
- verifyDescription=False)
+ verifyDescription=False, site=site)
bot.upload_image(debug=False)
return 1
return 0
@@ -289,9 +297,6 @@
def main(*args):
"""Process command line arguments and perform task."""
- site = pywikibot.Site(u'commons', u'commons')
- config.family = site.family
- config.lang = site.lang
# imagerecat.initLists()
photoset = u'' # public (popular photos), full (all photos), user ID number
@@ -362,12 +367,17 @@
autonomous = True
if photoset:
+ site = pywikibot.Site()
+ if site != pywikibot.Site('commons', 'commons'):
+ pywikibot.warning(
+ 'Using {0} instead of Wikimedia Commons'.format(site))
+
for photoInfo in getPhotos(photoset, start_id, end_id):
photoInfo = getLicense(photoInfo)
# time.sleep(10)
uploadedPhotos += processPhoto(photoInfo, panoramioreview,
reviewer, override, addCategory,
- autonomous)
+ autonomous, site=site)
totalPhotos += 1
else:
usage()
--
To view, visit https://gerrit.wikimedia.org/r/246128
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I94c449fa665afc71506baf1abebc97897e80f223
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>
[View Less]
jenkins-bot has submitted this change and it was merged.
Change subject: Desupport Python 2.6 for Pywikibot 2.0 release branch
......................................................................
Desupport Python 2.6 for Pywikibot 2.0 release branch
Prevent setup.py and pwb.py from executing under Python 2.6.
Adapted from 1db58db (Unicode Python issue #10254)
Bug: T114464
Change-Id: I4db6e5f5d6d87dbf90c16a38ee6f69a7b7f66f1f
---
M pwb.py
M setup.py
2 files changed, 42 insertions(+), 0 …
[View More]deletions(-)
Approvals:
John Vandenberg: Looks good to me, but someone else must approve
XZise: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pwb.py b/pwb.py
index 9ccb5df..601c2d4 100755
--- a/pwb.py
+++ b/pwb.py
@@ -29,6 +29,27 @@
from warnings import warn
+PYTHON_VERSION = sys.version_info[:3]
+PY2 = (PYTHON_VERSION[0] == 2)
+
+versions_required_message = """
+Pywikibot 2.0 is not available on:
+%s
+
+Pywikibot is only supported under Python 2.7.2+ or 3.3+
+"""
+
+
+def python_is_supported():
+ """Check that Python is supported."""
+ # Any change to this must be copied to setup.py
+ return (PYTHON_VERSION >= (3, 3, 0) or
+ (PY2 and PYTHON_VERSION >= (2, 7, 2)))
+
+
+if not python_is_supported():
+ raise RuntimeError(versions_required_message % sys.version)
+
pwb = None
diff --git a/setup.py b/setup.py
index 3456b78..723f1ff 100644
--- a/setup.py
+++ b/setup.py
@@ -17,6 +17,27 @@
except ImportError:
pass
+PYTHON_VERSION = sys.version_info[:3]
+PY2 = (PYTHON_VERSION[0] == 2)
+
+versions_required_message = """
+Pywikibot 2.0 is not available on:
+%s
+
+Pywikibot is only supported under Python 2.7.2+ or 3.3+
+"""
+
+
+def python_is_supported():
+ """Check that Python is supported."""
+ # Any change to this must be copied to pwb.py
+ return (PYTHON_VERSION >= (3, 3, 0) or
+ (PY2 and PYTHON_VERSION >= (2, 7, 2)))
+
+
+if not python_is_supported():
+ raise RuntimeError(versions_required_message % sys.version)
+
test_deps = []
dependencies = ['httplib2>=0.9']
--
To view, visit https://gerrit.wikimedia.org/r/243349
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I4db6e5f5d6d87dbf90c16a38ee6f69a7b7f66f1f
Gerrit-PatchSet: 3
Gerrit-Project: pywikibot/core
Gerrit-Branch: 2.0
Gerrit-Owner: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Ricordisamoa <ricordisamoa(a)openmailbox.org>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>
[View Less]