jenkins-bot has submitted this change and it was merged.
Change subject: Deprecate SSL override configuration ......................................................................
Deprecate SSL override configuration
No sites use this functionality, as wikimedia sites changed from a https://secure.wikimedia.org front-end processor to using https on the target wiki.
Also remove the 'ssl' override parameter from http.request. The ssl param was only used with the site parameter, to support the configuration variables, and was ignored if a uri was provided.
Change-Id: I5834ca17972e888886d15524098331cd8839f1da --- M pywikibot/comms/http.py M pywikibot/config2.py M pywikibot/data/api.py M tests/dry_api_tests.py 4 files changed, 56 insertions(+), 26 deletions(-)
Approvals: John Vandenberg: Looks good to me, but someone else must approve Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/comms/http.py b/pywikibot/comms/http.py index 25af2a1..f2f6eaa 100644 --- a/pywikibot/comms/http.py +++ b/pywikibot/comms/http.py @@ -62,6 +62,7 @@ from pywikibot import config from pywikibot.exceptions import FatalServerError, Server504Error from pywikibot.comms import threadedhttp +from pywikibot.tools import deprecate_arg import pywikibot.version
_logger = "comm.http" @@ -204,29 +205,33 @@ return formatted
-def request(site, uri, ssl=False, *args, **kwargs): +@deprecate_arg('ssl', None) +def request(site=None, uri=None, *args, **kwargs): """Queue a request to be submitted to Site.
All parameters not listed below are the same as - L{httplib2.Http.request}, but the uri is relative + L{httplib2.Http.request}.
- If the site argument is None the uri has to be absolute and is - taken. In this case SSL is ignored. Used for requests to non wiki - pages. + If the site argument is provided, the uri is relative to the site's + scriptpath. + + If the site argument is None, the uri must be absolute, and is + used for requests to non wiki pages.
@param site: The Site to connect to - @param uri: the URI to retrieve (relative to the site's scriptpath) - @param ssl: Use HTTPS connection + @type site: L{pywikibot.site.Site} + @param uri: the URI to retrieve + @type uri: str @return: The received data (a unicode string).
""" + assert(site or uri) if site: - if ssl: - proto = "https" + proto = site.protocol() + if proto == 'https': host = site.ssl_hostname() uri = site.ssl_pathprefix() + uri else: - proto = site.protocol() host = site.hostname() baseuri = urlparse.urljoin("%s://%s" % (proto, host), uri) else: diff --git a/pywikibot/config2.py b/pywikibot/config2.py index 4da09e9..b021a05 100644 --- a/pywikibot/config2.py +++ b/pywikibot/config2.py @@ -38,6 +38,8 @@ # to other modules.
_private_values = ['authenticate', 'proxy', 'db_password'] +_deprecated_variables = ['use_SSL_onlogin', 'use_SSL_always', + 'available_ssl_project_comment']
# ############# ACCOUNT SETTINGS ##############
@@ -103,17 +105,15 @@ authenticate = {}
# -# Security Connection for Wikimedia Projects +# Secure connection overrides # +# These settings are deprecated. They existed to support the Wikimedia +# family which only served HTTPS on https://secure.wikimedia.org/<site>/<uri> +# Use Family.protocol() use_SSL_onlogin = False # if available, use SSL when logging in use_SSL_always = False # if available, use SSL for all API queries - -# Available security projects -available_ssl_project = [ - u'wikipedia', u'wikinews', u'wikisource', u'wiktionary', u'wikibooks', - u'wikiquote', u'wikiversity', u'meta', u'mediawiki', u'commons', - u'species', u'incubator' -] +# Available secure projects should be listed here. +available_ssl_project = []
# By default you are asked for a password on the terminal. # A password file may be used. e.g. password_file = ".passwd" @@ -786,6 +786,10 @@ for _key in _modified: globals()[_key] = _uc[_key]
+ if _key in _deprecated_variables: + print("WARNING: '%s' is no longer a supported configuration variable." + "\nPlease inform the maintainers if you depend on it." % _key) + # Fix up default console_encoding if console_encoding is None: if sys.platform == 'win32': diff --git a/pywikibot/data/api.py b/pywikibot/data/api.py index 2810150..cfc19e3 100644 --- a/pywikibot/data/api.py +++ b/pywikibot/data/api.py @@ -79,6 +79,25 @@ pass
+class EnableSSLSiteWrapper(object): + """Wrapper to change the site protocol to https.""" + + def __init__(self, site): + self._site = site + + def __repr__(self): + return repr(self._site) + + def __eq__(self, other): + return self._site == other + + def __getattr__(self, attr): + return getattr(self._site, attr) + + def protocol(self): + return 'https' + + class Request(MutableMapping):
"""A request to a Site's api.php interface. @@ -190,6 +209,11 @@ self.site.has_extension('AssertEdit'))): pywikibot.debug(u"Adding user assertion", _logger) self.params["assert"] = "user" # make sure user is logged in + + if (self.site.protocol() == 'http' and (config.use_SSL_always or ( + self.params["action"] == "login" and config.use_SSL_onlogin)) + and self.site.family.name in config.available_ssl_project): + self.site = EnableSSLSiteWrapper(self.site)
# implement dict interface def __getitem__(self, key): @@ -378,12 +402,6 @@ else: pywikibot.log("Action '{0}' is submitted not throttled.".format(action)) uri = self.site.scriptpath() + "/api.php" - ssl = False - if self.site.family.name in config.available_ssl_project: - if action == "login" and config.use_SSL_onlogin: - ssl = True - elif config.use_SSL_always: - ssl = True try: if self.mime: # construct a MIME message containing all API key/values @@ -412,10 +430,10 @@ body = body[eoh + len(marker):] # retrieve the headers from the MIME object mimehead = dict(list(container.items())) - rawdata = http.request(self.site, uri, ssl, method="POST", + rawdata = http.request(self.site, uri, method="POST", headers=mimehead, body=body) else: - rawdata = http.request(self.site, uri, ssl, method="POST", + rawdata = http.request(self.site, uri, method="POST", headers={'Content-Type': 'application/x-www-form-urlencoded'}, body=paramstring) # import traceback diff --git a/tests/dry_api_tests.py b/tests/dry_api_tests.py index de448c6..83dac6e 100644 --- a/tests/dry_api_tests.py +++ b/tests/dry_api_tests.py @@ -73,6 +73,9 @@ def version(self): return '1.13' # pre 1.14
+ def protocol(self): + return 'http' + def languages(self): return ['mock']
pywikibot-commits@lists.wikimedia.org