Sn1per has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/329360 )

Change subject: Query string dictionary parameter for pwb.comms.http.fetch
......................................................................

Query string dictionary parameter for pwb.comms.http.fetch

New "params" parameter to pass unencoded query string parameters as a
dictionary to pywikibot.comms.http.fetch.
PetScanPageGenerator has been updated to use this new parameter.

Bug: T153559
Change-Id: I96da6d4c719aba24d35e58dd5f0694e628be86a3
---
M pywikibot/comms/http.py
M pywikibot/comms/threadedhttp.py
M pywikibot/pagegenerators.py
3 files changed, 11 insertions(+), 14 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/60/329360/1

diff --git a/pywikibot/comms/http.py b/pywikibot/comms/http.py
index 7bf6235..a55dd71 100644
--- a/pywikibot/comms/http.py
+++ b/pywikibot/comms/http.py
@@ -350,6 +350,7 @@
 def _http_process(session, http_request):
     method = http_request.method
     uri = http_request.uri
+    params = http_request.params
     body = http_request.body
     headers = http_request.headers
     if PY2 and headers:
@@ -370,8 +371,8 @@
         # Note that the connections are pooled which mean that a future
         # HTTPS request can succeed even if the certificate is invalid and
         # verify=True, when a request with verify=False happened before
-        response = session.request(method, uri, data=body, headers=headers,
-                                   auth=auth, timeout=timeout,
+        response = session.request(method, uri, params=params, data=body,
+                                   headers=headers, auth=auth, timeout=timeout,
                                    verify=not ignore_validation)
     except Exception as e:
         http_request.data = e
@@ -407,7 +408,7 @@
         warning('Http response status {0}'.format(request.data.status_code))
 
 
-def _enqueue(uri, method="GET", body=None, headers=None, **kwargs):
+def _enqueue(uri, method="GET", params=None, body=None, headers=None, 
**kwargs):
     """
     Enqueue non-blocking threaded HTTP request with callback.
 
@@ -451,12 +452,12 @@
         all_headers['user-agent'] = user_agent(None, user_agent_format_string)
 
     request = threadedhttp.HttpRequest(
-        uri, method, body, all_headers, callbacks, **kwargs)
+        uri, method, params, body, all_headers, callbacks, **kwargs)
     _http_process(session, request)
     return request
 
 
-def fetch(uri, method="GET", body=None, headers=None,
+def fetch(uri, method="GET", params=None, body=None, headers=None,
           default_error_handling=True, use_fake_user_agent=False, **kwargs):
     """
     Blocking HTTP request.
@@ -489,7 +490,7 @@
         elif use_fake_user_agent is True:
             headers['user-agent'] = fake_user_agent()
 
-    request = _enqueue(uri, method, body, headers, **kwargs)
+    request = _enqueue(uri, method, params, body, headers, **kwargs)
     assert(request._data is not None)  # if there's no data in the answer 
we're in trouble
     # Run the error handling callback in the callers thread so exceptions
     # may be caught.
diff --git a/pywikibot/comms/threadedhttp.py b/pywikibot/comms/threadedhttp.py
index a166929..03386cf 100644
--- a/pywikibot/comms/threadedhttp.py
+++ b/pywikibot/comms/threadedhttp.py
@@ -31,7 +31,7 @@
     * an exception
     """
 
-    def __init__(self, uri, method="GET", body=None, headers=None,
+    def __init__(self, uri, method="GET", params=None, body=None, headers=None,
                  callbacks=None, charset=None, **kwargs):
         """
         Constructor.
@@ -40,6 +40,7 @@
         """
         self.uri = uri
         self.method = method
+        self.params = params
         self.body = body
         self.headers = headers
         if isinstance(charset, codecs.CodecInfo):
diff --git a/pywikibot/pagegenerators.py b/pywikibot/pagegenerators.py
index 3db16a7..e30668f 100644
--- a/pywikibot/pagegenerators.py
+++ b/pywikibot/pagegenerators.py
@@ -2840,14 +2840,9 @@
 
     def query(self):
         """Query PetScan."""
-        url = urlparse.urlunparse(('https',                   # scheme
-                                   'petscan.wmflabs.org',     # netloc
-                                   '',                        # path
-                                   '',                        # params
-                                   urlencode(self.opts),      # query
-                                   ''))                       # fragment
+        url = 'https://petscan.wmflabs.org'
 
-        req = http.fetch(url)
+        req = http.fetch(url, params=self.opts)
         j = json.loads(req.content)
         raw_pages = j['*'][0]['a']['*']
         for raw_page in raw_pages:

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I96da6d4c719aba24d35e58dd5f0694e628be86a3
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Sn1per <[email protected]>

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

Reply via email to