jenkins-bot has submitted this change and it was merged.
Change subject: Add option of user_agent in user-config.py ......................................................................
Add option of user_agent in user-config.py
It will use a format string and people can change it
Change-Id: If1bfcbb62e0bf126abc2b5847d03e7e004c7bfe4 --- M pywikibot/comms/http.py M pywikibot/config2.py 2 files changed, 16 insertions(+), 9 deletions(-)
Approvals: John Vandenberg: Looks good to me, approved jenkins-bot: Verified
diff --git a/pywikibot/comms/http.py b/pywikibot/comms/http.py index 4f69291..d8adef3 100644 --- a/pywikibot/comms/http.py +++ b/pywikibot/comms/http.py @@ -43,11 +43,13 @@ import Queue import urlparse import cookielib + from urllib2 import quote else: from ssl import SSLError as SSLHandshakeError import queue as Queue import urllib.parse as urlparse from http import cookiejar as cookielib + from urlparse import quote
from pywikibot import config from pywikibot.exceptions import FatalServerError, Server504Error @@ -65,12 +67,7 @@ # cf. `openssl errstr 14090086` SSL_CERT_VERIFY_FAILED = ":14090086:"
-# the User-agent: header. The default is -# '<script>/<revision> Pywikibot/2.0', where '<script>' is the currently -# executing script and version is the Git revision of Pywikibot. -USER_AGENT_FORMAT = '{script}/r{version[rev]} Pywikibot/2.0' -useragent = USER_AGENT_FORMAT.format(script=pywikibot.calledModuleName(), - version=pywikibot.version.getversiondict()) + numthreads = 1 threads = []
@@ -148,9 +145,12 @@ else: baseuri = uri
- # set default user-agent string - kwargs.setdefault("headers", {}) - kwargs["headers"].setdefault("user-agent", useragent) + kwargs["headers"]["user-agent"] = config.USER_AGENT_FORMAT.format( + script=pywikibot.calledModuleName(), + version=pywikibot.version.getversiondict()['rev'], + username=quote(site.username()), + lang=site.lang, + family=site.family.name) request = threadedhttp.HttpRequest(baseuri, *args, **kwargs) http_queue.put(request) while not request.lock.acquire(False): diff --git a/pywikibot/config2.py b/pywikibot/config2.py index 2d3ce38..eadcf88 100644 --- a/pywikibot/config2.py +++ b/pywikibot/config2.py @@ -57,6 +57,13 @@ sysopnames = {} disambiguation_comment = {}
+# User agent format. +# For the meaning and more help in customization see: +# https://www.mediawiki.org/wiki/Manual:Pywikibot/User-agent +# The default is script, revision number and user name +# For more information see https://meta.wikimedia.org/wiki/User-agent_policy +USER_AGENT_FORMAT = '{script}/{version} Pywikibot/2.0 (User:{username})' + # The default interface for communicating with the site # currently the only defined interface is 'APISite', so don't change this! site_interface = 'APISite'
pywikibot-commits@lists.wikimedia.org