jenkins-bot has submitted this change and it was merged.
Change subject: Fix encode_url dict support on Python 3
......................................................................
Fix encode_url dict support on Python 3
Bug: T85321
Bug: T121310
Change-Id: I796c78aa2b8fd2ee42b646c801a6a51bb634a425
---
M pywikibot/data/api.py
M tests/api_tests.py
2 files changed, 4 insertions(+), 3 deletions(-)
Approvals:
Merlijn van Deen: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py
index efbab77..abeafdf 100644
--- a/pywikibot/data/api.py
+++ b/pywikibot/data/api.py
@@ -3043,9 +3043,11 @@
@rtype: str
"""
if hasattr(query, 'items'):
- query = query.items()
+ query = list(query.items())
+
if PY2:
query = [(pair[0], pair[1].encode('utf-8')) for pair in query]
+
# parameters ending on 'token' should go last
# wpEditToken should go very last
query.sort(key=lambda x: x[0].lower().endswith('token') +
diff --git a/tests/api_tests.py b/tests/api_tests.py
index 0b06b80..1cbb9de 100644
--- a/tests/api_tests.py
+++ b/tests/api_tests.py
@@ -977,8 +977,7 @@
"""Test url_encode."""
- family = 'wikipedia'
- code = 'test'
+ net = False
def test_url_encoding_from_list(self):
"""Test moving 'token' parameters from a list to the end."""
--
To view, visit https://gerrit.wikimedia.org/r/258683
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I796c78aa2b8fd2ee42b646c801a6a51bb634a425
Gerrit-PatchSet: 3
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: Add encode_url to pywikibot.data.api
......................................................................
Add encode_url to pywikibot.data.api
Use it instead of stock urlencode from urllib so that token parameters are
moved to the end (and 'wpEditToken' to the very and) to comply with
https://www.mediawiki.org/wiki/API:Edit#Parameters
Bug: T85321
Change-Id: Idb24ef35e290b26479fdff328833fab4eb63b5c4
---
M pywikibot/data/api.py
M pywikibot/site.py
M tests/api_tests.py
3 files changed, 69 insertions(+), 3 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py
index 86cf089..efbab77 100644
--- a/pywikibot/data/api.py
+++ b/pywikibot/data/api.py
@@ -1764,7 +1764,7 @@
URL encodes the parameters provided by _encoded_items()
"""
- return urlencode(self._encoded_items())
+ return encode_url(self._encoded_items())
def __str__(self):
"""Return a string representation."""
@@ -3028,6 +3028,31 @@
http.cookie_jar.save()
+def encode_url(query):
+ """
+ Encode parameters to pass with a url.
+
+ Reorder parameters so that token parameters go last and call wraps
+ L{urlencode}. Return an HTTP URL query fragment which complies with
+ https://www.mediawiki.org/wiki/API:Edit#Parameters
+ (See the 'token' bullet.)
+
+ @param query: keys and values to be uncoded for passing with a url
+ @type query: mapping object or a sequence of two-element tuples
+ @return: encoded parameters with token parameters at the end
+ @rtype: str
+ """
+ if hasattr(query, 'items'):
+ query = query.items()
+ if PY2:
+ query = [(pair[0], pair[1].encode('utf-8')) for pair in query]
+ # parameters ending on 'token' should go last
+ # wpEditToken should go very last
+ query.sort(key=lambda x: x[0].lower().endswith('token') +
+ (x[0] == 'wpEditToken'))
+ return urlencode(query)
+
+
def update_page(page, pagedict, props=[]):
"""Update attributes of Page object page, based on query data in pagedict.
diff --git a/pywikibot/site.py b/pywikibot/site.py
index e4aebcd..0c486d7 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -1212,10 +1212,10 @@
"""Return Family object for this Site."""
return self.family
- @deprecated("urllib.urlencode()")
+ @deprecated("pywikibot.data.api.encode_url")
def urlEncode(self, query):
"""DEPRECATED."""
- return urlencode(query)
+ return api.encode_url(query)
@deprecated('pywikibot.data.api.Request or pywikibot.comms.http.request')
@deprecated_args(compress=None, no_hostname=None, cookies_only=None,
diff --git a/tests/api_tests.py b/tests/api_tests.py
index 481504c..0b06b80 100644
--- a/tests/api_tests.py
+++ b/tests/api_tests.py
@@ -973,6 +973,47 @@
page.save(summary='Bad token test')
+class TestUrlEncoding(TestCase):
+
+ """Test url_encode."""
+
+ family = 'wikipedia'
+ code = 'test'
+
+ def test_url_encoding_from_list(self):
+ """Test moving 'token' parameters from a list to the end."""
+ query = [('action', 'edit'), ('token', 'a'), ('supertoken', 'b'),
+ ('text', 'text')]
+ expect = 'action=edit&text=text&token=a&supertoken=b'
+ result = api.encode_url(query)
+ self.assertEqual(result, expect)
+ self.assertIsInstance(result, str)
+
+ def test_url_encoding_from_dict(self):
+ """Test moving 'token' parameters from a dict to the end."""
+ # do not add other keys because dictionary is not deterministic
+ query = {'supertoken': 'b', 'text': 'text'}
+ expect = 'text=text&supertoken=b'
+ result = api.encode_url(query)
+ self.assertEqual(result, expect)
+ self.assertIsInstance(result, str)
+
+ def test_url_encoding_from_unicode(self):
+ """Test encoding unicode values."""
+ query = {'token': 'токен'}
+ expect = 'token=%D1%82%D0%BE%D0%BA%D0%B5%D0%BD'
+ result = api.encode_url(query)
+ self.assertEqual(result, expect)
+ self.assertIsInstance(result, str)
+
+ def test_moving_special_tokens(self):
+ """Test moving wpEditToken to the very end."""
+ query = {'wpEditToken': 'c', 'token': 'b', 'text': 'a'}
+ expect = 'text=a&token=b&wpEditToken=c'
+ result = api.encode_url(query)
+ self.assertEqual(result, expect)
+ self.assertIsInstance(result, str)
+
if __name__ == '__main__':
try:
unittest.main()
--
To view, visit https://gerrit.wikimedia.org/r/258433
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Idb24ef35e290b26479fdff328833fab4eb63b5c4
Gerrit-PatchSet: 7
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Murfel <murnatty(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Murfel <murnatty(a)gmail.com>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: [FIX] imagetransfer: Compare image repositories
......................................................................
[FIX] imagetransfer: Compare image repositories
It checks if the file is already shared and skips transferring them. But that
is assuming the target site is using the same image repository.
Bug: T87082
Change-Id: I3da1f7b5a8738b649f0eec2da330518f9efb3b35
---
M scripts/imagetransfer.py
1 file changed, 5 insertions(+), 2 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/imagetransfer.py b/scripts/imagetransfer.py
index 670c809..b207cda 100755
--- a/scripts/imagetransfer.py
+++ b/scripts/imagetransfer.py
@@ -294,9 +294,12 @@
break
todo = int(todo)
if todo in range(len(imagelist)):
- if imagelist[todo].fileIsShared():
+ if (imagelist[todo].fileIsShared() and
+ imagelist[todo].site.image_repository() ==
+ self.targetSite.image_repository()):
pywikibot.output(
- u'The image is already on Wikimedia Commons.')
+ 'The image is already shared on {0}.'.format(
+ self.targetSite.image_repository()))
else:
self.transferImage(imagelist[todo])
# remove the selected image from the list
--
To view, visit https://gerrit.wikimedia.org/r/235466
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I3da1f7b5a8738b649f0eec2da330518f9efb3b35
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: Improve claimit.py intro docs
......................................................................
Improve claimit.py intro docs
Any pagegenerator can be used, not just categories.
Change-Id: I35fb61b9a4103978a7c0298517fb9552c0769981
---
M scripts/claimit.py
1 file changed, 3 insertions(+), 3 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/claimit.py b/scripts/claimit.py
index cfbb5e6..93a7a4d 100755
--- a/scripts/claimit.py
+++ b/scripts/claimit.py
@@ -1,7 +1,7 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
-A script that adds claims to Wikidata items based on categories.
+A script that adds claims to Wikidata items based on a list of pages.
------------------------------------------------------------------------------
@@ -9,8 +9,8 @@
python pwb.py claimit [pagegenerators] P1 Q2 P123 Q456
-You can use any typical pagegenerator to provide with a list of pages.
-Then list the property-->target pairs to add.
+You can use any typical pagegenerator (like categories) to provide with a
+list of pages. Then list the property-->target pairs to add.
------------------------------------------------------------------------------
--
To view, visit https://gerrit.wikimedia.org/r/257212
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I35fb61b9a4103978a7c0298517fb9552c0769981
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Legoktm <legoktm.wikipedia(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: Do not specify pep8 explicitly in dev-requirements
......................................................................
Do not specify pep8 explicitly in dev-requirements
It is installed by installing flake8 automatically
Change-Id: Id645deb3e4c7bf610b1790f888972928ef26e375
---
M dev-requirements.txt
1 file changed, 0 insertions(+), 1 deletion(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/dev-requirements.txt b/dev-requirements.txt
index 373c987..81f4b4a 100644
--- a/dev-requirements.txt
+++ b/dev-requirements.txt
@@ -6,7 +6,6 @@
nose
-pep8
pep257>=0.6
pyflakes>=0.9
flake8
--
To view, visit https://gerrit.wikimedia.org/r/257862
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Id645deb3e4c7bf610b1790f888972928ef26e375
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Yuvipanda <yuvipanda(a)wikimedia.org>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: jenkins-bot <>