jenkins-bot has submitted this change and it was merged.
Change subject: [FIX] Config2: Don't decode user-config
......................................................................
[FIX] Config2: Don't decode user-config
It doesn't try to decode the user-config.py by itself but let compile()
handle a byte string. That does interpret the header in the file and
decode it accordingly.
Change-Id: I32b26e31d1d838d08d91b2c480d4800effb6995a
---
M pywikibot/config2.py
1 file changed, 2 insertions(+), 1 deletion(-)
Approvals:
XZise: Looks good to me, but someone else must approve
Merlijn van Deen: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/config2.py b/pywikibot/config2.py
index fb68ec1..0d9d670 100644
--- a/pywikibot/config2.py
+++ b/pywikibot/config2.py
@@ -830,7 +830,8 @@
_fileuid = _filestatus[4]
if sys.platform == 'win32' or _fileuid in [os.getuid(), 0]:
if sys.platform == 'win32' or _filemode & 0o02 == 0:
- exec(compile(open(_filename).read(), _filename, 'exec'), _uc)
+ with open(_filename, 'rb') as f:
+ exec(compile(f.read(), _filename, 'exec'), _uc)
else:
print("WARNING: Skipped '%(fn)s': writeable by others."
% {'fn': _filename})
--
To view, visit https://gerrit.wikimedia.org/r/190785
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I32b26e31d1d838d08d91b2c480d4800effb6995a
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: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: Log & warn about Site instantiation oddities
......................................................................
Log & warn about Site instantiation oddities
BaseSite constructor has a few branches that perform changes
which may not be expected by the end user, and may be useful
information when debugging a script.
Add a few asserts in Family.load to detect problems early.
Change-Id: I374461c8b7481e9edae7d5c5db6ef8d39416243b
---
M pywikibot/__init__.py
M pywikibot/families/wikisource_family.py
M pywikibot/family.py
M pywikibot/site.py
4 files changed, 59 insertions(+), 9 deletions(-)
Approvals:
XZise: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py
index b7161d8..53aaa13 100644
--- a/pywikibot/__init__.py
+++ b/pywikibot/__init__.py
@@ -21,6 +21,8 @@
else:
from Queue import Queue
+from warnings import warn
+
# Use pywikibot. prefix for all in-package imports; this is to prevent
# confusion with similarly-named modules in version 1 framework, for users
# who want to continue using both
@@ -601,6 +603,11 @@
_sites[key] = interface(code=code, fam=fam, user=user, sysop=sysop)
debug(u"Instantiated %s object '%s'"
% (interface.__name__, _sites[key]), _logger)
+
+ if _sites[key].code != code:
+ warn('Site %s instantiated using different code "%s"'
+ % (_sites[key], code), UserWarning, 2)
+
return _sites[key]
diff --git a/pywikibot/families/wikisource_family.py b/pywikibot/families/wikisource_family.py
index 2996a08..2abbaaa 100644
--- a/pywikibot/families/wikisource_family.py
+++ b/pywikibot/families/wikisource_family.py
@@ -26,6 +26,8 @@
self.langs = dict([(lang, '%s.wikisource.org' % lang)
for lang in self.languages_by_size])
+ # FIXME: '-' is invalid at the beginning of a hostname, and
+ # '-' is not a valid subdomain.
self.langs['-'] = 'wikisource.org'
# Global bot allowed languages on https://meta.wikimedia.org/wiki/Bot_policy/Implementation#Current_implement…
diff --git a/pywikibot/family.py b/pywikibot/family.py
index 0969041..4848c6b 100644
--- a/pywikibot/family.py
+++ b/pywikibot/family.py
@@ -13,6 +13,7 @@
import re
import collections
import imp
+import string
import warnings
if sys.version_info[0] > 2:
@@ -20,13 +21,19 @@
else:
import urlparse
+from warnings import warn
+
import pywikibot
from pywikibot import config2 as config
from pywikibot.tools import deprecated, deprecate_arg
-from pywikibot.exceptions import UnknownFamily, Error
+from pywikibot.exceptions import Error, UnknownFamily, FamilyMaintenanceWarning
logger = logging.getLogger("pywiki.wiki.family")
+
+# Legal characters for Family.name and Family.langs keys
+NAME_CHARACTERS = string.ascii_letters + string.digits
+CODE_CHARACTERS = string.ascii_lowercase + string.digits + '-'
class Family(object):
@@ -858,6 +865,9 @@
"""
if fam is None:
fam = config.family
+
+ assert(all(x in NAME_CHARACTERS for x in fam))
+
if fam in Family._families:
return Family._families[fam]
@@ -881,11 +891,26 @@
# RuntimeWarning's while loading.
with warnings.catch_warnings():
warnings.simplefilter("ignore", RuntimeWarning)
- myfamily = imp.load_source(fam, config.family_files[fam])
+ mod = imp.load_source(fam, config.family_files[fam])
except (ImportError, KeyError):
- raise UnknownFamily("Family %s does not exist" % fam)
- Family._families[fam] = myfamily.Family()
- return Family._families[fam]
+ raise UnknownFamily(u'Family %s does not exist' % fam)
+ cls = mod.Family()
+ if cls.name != fam:
+ warn(u'Family name %s does not match family module name %s'
+ % (cls.name, fam), FamilyMaintenanceWarning)
+ # Family 'name' and the 'langs' codes must be ascii, and the
+ # codes must be lower-case due to the Site loading algorithm.
+ if not all(x in NAME_CHARACTERS for x in cls.name):
+ warn(u'Family name %s contains non-ascii characters' % cls.name,
+ FamilyMaintenanceWarning)
+ # FIXME: wikisource uses code '-' for www.wikisource.org
+ if not all(all(x in CODE_CHARACTERS for x in code) and
+ (cls.name == 'wikisource' or code[0] != '-')
+ for code in cls.langs.keys()):
+ warn(u'Family %s codes contains non-ascii characters',
+ FamilyMaintenanceWarning)
+ Family._families[fam] = cls
+ return cls
@property
def iwkeys(self):
diff --git a/pywikibot/site.py b/pywikibot/site.py
index 525e98e..a6a5330 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -493,7 +493,15 @@
@type sysop: str
"""
- self.__code = code.lower()
+ if code.lower() != code:
+ # Note the Site function in __init__ also emits a UserWarning
+ # for this condition, showing the callers file and line no.
+ pywikibot.log(u'BaseSite: code "%s" converted to lowercase' % code)
+ code = code.lower()
+ if not all(x in pywikibot.family.CODE_CHARACTERS for x in str(code)):
+ pywikibot.log(u'BaseSite: code "%s" contains invalid characters'
+ % code)
+ self.__code = code
if isinstance(fam, basestring) or fam is None:
self.__family = pywikibot.family.Family.load(fam)
else:
@@ -504,19 +512,27 @@
if self.__code in self.__family.obsolete:
if self.__family.obsolete[self.__code] is not None:
self.__code = self.__family.obsolete[self.__code]
+ # Note the Site function in __init__ emits a UserWarning
+ # for this condition, showing the callers file and line no.
+ pywikibot.log(u'Site %s instantiated using code %s'
+ % (self, code))
else:
# no such language anymore
self.obsolete = True
+ pywikibot.log(u'Site %s instantiated and marked "obsolete" '
+ u'to prevent access' % self)
elif self.__code not in self.languages():
if self.__family.name in list(self.__family.langs.keys()) and \
len(self.__family.langs) == 1:
- oldcode = self.__code
self.__code = self.__family.name
if self.__family == pywikibot.config.family \
- and oldcode == pywikibot.config.mylang:
+ and code == pywikibot.config.mylang:
pywikibot.config.mylang = self.__code
+ warn(u'Global configuration variable "mylang" changed to '
+ u'"%s" while instantiating site %s'
+ % (self.__code, self), UserWarning)
else:
- raise UnknownSite("Language '%s' does not exist in family %s"
+ raise UnknownSite(u"Language '%s' does not exist in family %s"
% (self.__code, self.__family.name))
self.nocapitalize = self.code in self.family.nocapitalize
--
To view, visit https://gerrit.wikimedia.org/r/190512
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I374461c8b7481e9edae7d5c5db6ef8d39416243b
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: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>
Build Update for wikimedia/pywikibot-core
-------------------------------------
Build: #1994
Status: Broken
Duration: 35 minutes and 37 seconds
Commit: 54e9727 (master)
Author: Fabian Neundorf
Message: [FIX] W503 errors
With a recent version of PEP8 (and thus flake8) binary operators (like
and) are not allowed at the start of a line and instead at the end of
the previous one. Double quotes in the affected lines too were changed.
Change-Id: I5d89afa1d7bd4711a80d8b6c831ee63afe440ef5
View the changeset: https://github.com/wikimedia/pywikibot-core/compare/5da634bf88fc...54e9727c…
View the full build log and details: https://travis-ci.org/wikimedia/pywikibot-core/builds/50886428
--
You can configure recipients for build notifications in your .travis.yml file. See http://docs.travis-ci.com/user/notifications
jenkins-bot has submitted this change and it was merged.
Change subject: RCStream: Ignore changes after total is reached
......................................................................
RCStream: Ignore changes after total is reached
There could be 'on_change' messages queued that are still processed
before the thread fully shuts down. This prevents those messages from
appearing in the queue.
As far as I know, the message pump is single threaded, so the previous
on_change call is guaranteed to finish before the next one is called.
Bug: T85716
Change-Id: Ibe6aba6a42028568dbd956da14168fec1bbd920e
---
M pywikibot/comms/rcstream.py
1 file changed, 3 insertions(+), 0 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/comms/rcstream.py b/pywikibot/comms/rcstream.py
index 688e0f6..fb310f9 100644
--- a/pywikibot/comms/rcstream.py
+++ b/pywikibot/comms/rcstream.py
@@ -83,6 +83,9 @@
class RCListener(socketIO_client.BaseNamespace):
def on_change(self, change):
debug('Received change %r' % change, _logger)
+ if not thread.running:
+ debug('Thread in shutdown mode; ignoring change.', _logger)
+ return
thread.count += 1
thread.queue.put(change)
--
To view, visit https://gerrit.wikimedia.org/r/190719
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ibe6aba6a42028568dbd956da14168fec1bbd920e
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Merlijn van Deen <valhallasw(a)arctus.nl>
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: [FIX] Wikibase test: Use valid alias
......................................................................
[FIX] Wikibase test: Use valid alias
With revision 197062264 of Q5296 on wikidata, aliases have been deleted,
including one used by our test.
Change-Id: I67fd42c4738cea2c28831985dd7310a91c107d93
---
M tests/wikibase_tests.py
1 file changed, 1 insertion(+), 1 deletion(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/wikibase_tests.py b/tests/wikibase_tests.py
index 41e90c2..fc1038e 100644
--- a/tests/wikibase_tests.py
+++ b/tests/wikibase_tests.py
@@ -54,7 +54,7 @@
self.assertIn('en', item.labels)
self.assertTrue(item.labels['en'].lower().endswith('main page'))
self.assertIn('en', item.aliases)
- self.assertIn('HomePage', item.aliases['en'])
+ self.assertIn('Home page', item.aliases['en'])
self.assertEqual(item.namespace(), 0)
item2 = pywikibot.ItemPage(repo, 'q5296')
self.assertEqual(item2.getID(), 'Q5296')
--
To view, visit https://gerrit.wikimedia.org/r/190750
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I67fd42c4738cea2c28831985dd7310a91c107d93
Gerrit-PatchSet: 1
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: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>