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'
--
To view, visit https://gerrit.wikimedia.org/r/147381
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: If1bfcbb62e0bf126abc2b5847d03e7e004c7bfe4
Gerrit-PatchSet: 15
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: BinĂ¡ris <wikiposta(a)gmail.com>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Legoktm <legoktm.wikipedia(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Nullzero <nullzero.free(a)gmail.com>
Gerrit-Reviewer: Ricordisamoa <ricordisamoa(a)openmailbox.org>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: Add support for nosetests
......................................................................
Add support for nosetests
nosetests finds tests automatically, including test_data_ingestion.py
which fails on the import.
It has slightly different rules for auto-detecting tests, and it
tries to use get_test_unconnected_page as a test.
Change-Id: I49fc3cbda3f1f3b42c795b4f007e59d9bb1d6cf5
---
M scripts/tests/test_data_ingestion.py
M tests/wikibase_tests.py
2 files changed, 3 insertions(+), 3 deletions(-)
Approvals:
Ladsgroup: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/tests/test_data_ingestion.py b/scripts/tests/test_data_ingestion.py
index 36fa0fb..c34033d 100644
--- a/scripts/tests/test_data_ingestion.py
+++ b/scripts/tests/test_data_ingestion.py
@@ -6,7 +6,7 @@
import os
import unittest
-import data_ingestion
+from scripts import data_ingestion
class TestPhoto(unittest.TestCase):
diff --git a/tests/wikibase_tests.py b/tests/wikibase_tests.py
index aca60b3..b5f5780 100644
--- a/tests/wikibase_tests.py
+++ b/tests/wikibase_tests.py
@@ -26,7 +26,7 @@
# fetch a page which is very likely to be unconnected, which doesnt have
# a generator, and unit tests may be used to test old versions of pywikibot
-def get_test_unconnected_page(site):
+def _get_test_unconnected_page(site):
gen = pagegenerators.NewpagesPageGenerator(site=site, total=10,
namespaces=[1, ])
for page in gen:
@@ -348,7 +348,7 @@
def test_fromPage_noitem(self):
# this is a new page, and should not have a wikidata item yet
- page = get_test_unconnected_page(site)
+ page = _get_test_unconnected_page(site)
link = page._link
self._test_fromPage_noitem(link)
--
To view, visit https://gerrit.wikimedia.org/r/151591
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I49fc3cbda3f1f3b42c795b4f007e59d9bb1d6cf5
Gerrit-PatchSet: 4
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: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: Fix support for site where lang != code
......................................................................
Fix support for site where lang != code
APISite.lang may change based on the siteinfo.
For local files, the family 'lang' code should be used.
e.g. This code may be 'wikidata' or 'commons'.
Change-Id: If71b3ab3e7ad14f873862954457b0cd7f0efb646
---
M scripts/watchlist.py
M tests/script_tests.py
2 files changed, 5 insertions(+), 10 deletions(-)
Approvals:
John Vandenberg: Looks good to me, but someone else must approve
Ladsgroup: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/watchlist.py b/scripts/watchlist.py
index 34f8590..31236ad 100755
--- a/scripts/watchlist.py
+++ b/scripts/watchlist.py
@@ -45,7 +45,7 @@
else:
fn = config.datafilepath('watchlists',
'watchlist-%s-%s.dat'
- % (site.family.name, site.lang))
+ % (site.family.name, site.code))
try:
# find out how old our saved dump is (in seconds)
file_age = time.time() - os.path.getmtime(fn)
@@ -98,16 +98,11 @@
else:
break
- if site.family.name == 'wikidata':
- lang = 'wikidata'
- else:
- lang = site.lang
-
# Save the watchlist to disk
# The file is stored in the watchlists subdir. Create if necessary.
f = open(config.datafilepath('watchlists',
'watchlist-%s-%s%s.dat'
- % (site.family.name, lang,
+ % (site.family.name, site.code,
'-sysop' if sysop else '')),
'w')
pickle.dump(watchlist, f)
@@ -158,9 +153,10 @@
elif new:
refresh_all(new, sysop=sysop)
else:
- refresh(pywikibot.Site(), sysop=sysop)
+ site = pywikibot.Site()
+ refresh(site, sysop=sysop)
- watchlist = get(pywikibot.Site())
+ watchlist = get(site)
pywikibot.output(u'%i pages in the watchlist.' % len(watchlist))
for pageName in watchlist:
pywikibot.output(pageName, toStdout=True)
diff --git a/tests/script_tests.py b/tests/script_tests.py
index ef151ed..0651c63 100644
--- a/tests/script_tests.py
+++ b/tests/script_tests.py
@@ -55,7 +55,6 @@
and check_script_deps(name)
and name != 'login.py' # this is moved to be first
and name != 'imageuncat.py' # this halts indefinitely
- and name != 'watchlist.py' # result depends on speed
and name != 'welcome.py' # result depends on speed
and name != 'script_wui.py' # depends on lua compiling
]
--
To view, visit https://gerrit.wikimedia.org/r/151040
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: If71b3ab3e7ad14f873862954457b0cd7f0efb646
Gerrit-PatchSet: 3
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: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>