jenkins-bot has submitted this change and it was merged.
Change subject: [IMPROV] Namespace: Use default and fixed case
......................................................................
[IMPROV] Namespace: Use default and fixed case
For certain namespaces the case sensitivity is fixed and can't be
changed. This either asserts that the case or if the server doesn't
report the case sensitivity for the namespaces specifically uses that
default value.
This also applies to all namespaces created without the help of the API.
Change-Id: I097c4e52ad41bf531f2685e712bb0be27a225661
---
M pywikibot/site.py
1 file changed, 17 insertions(+), 2 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/site.py b/pywikibot/site.py
index 5848169..2becc09 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -368,10 +368,22 @@
% (self.__class__.__name__, self.id, self.custom_name,
self.canonical_name, self.aliases, kwargs)
+ @staticmethod
+ def default_case(id, default_case=None):
+ """Return the default fixed case value for the namespace ID."""
+ # https://www.mediawiki.org/wiki/Manual:$wgCapitalLinkOverrides#Warning
+ if id > 0 and id % 2 == 1: # the talk ns has the non-talk ns case
+ id -= 1
+ if id in (-1, 2, 8):
+ return 'first-letter'
+ else:
+ return default_case
+
@classmethod
def builtin_namespaces(cls, use_image_name=False, case='first-letter'):
"""Return a dict of the builtin namespaces."""
- return dict((i, cls(i, use_image_name=use_image_name, case=case))
+ return dict((i, cls(i, use_image_name=use_image_name,
+ case=cls.default_case(i, case)))
for i in range(-2, 16))
@staticmethod
@@ -2139,8 +2151,11 @@
if is_mw114:
canonical_name = nsdata.pop('canonical')
+ default_case = Namespace.default_case(ns)
if 'case' not in nsdata:
- nsdata['case'] = self.siteinfo['case']
+ nsdata['case'] = default_case or self.siteinfo['case']
+ elif default_case is not None:
+ assert(default_case == nsdata['case'])
namespace = Namespace(ns, canonical_name, custom_name,
use_image_name=not is_mw114,
--
To view, visit https://gerrit.wikimedia.org/r/205596
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I097c4e52ad41bf531f2685e712bb0be27a225661
Gerrit-PatchSet: 3
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: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: [IMPROV] Category: Query again on invalid category
......................................................................
[IMPROV] Category: Query again on invalid category
It shouldn't try jumping to a category without any name. Instead ask the
user again.
Change-Id: I53d470df16766b1d34f14248de2b8c7abb47243a
---
M scripts/category.py
1 file changed, 2 insertions(+), 1 deletion(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/category.py b/scripts/category.py
index 62d9b75..dd8fe46 100755
--- a/scripts/category.py
+++ b/scripts/category.py
@@ -921,7 +921,8 @@
flag = True
elif choice in ['j', 'J']:
newCatTitle = pywikibot.input(u'Please enter the category the '
- u'article should be moved to:')
+ u'article should be moved to:',
+ default=None) # require an answer
newCat = pywikibot.Category(pywikibot.Link('Category:' +
newCatTitle))
# recurse into chosen category
--
To view, visit https://gerrit.wikimedia.org/r/186335
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I53d470df16766b1d34f14248de2b8c7abb47243a
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: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: [IMPROV] Remove usage of 'case' method
......................................................................
[IMPROV] Remove usage of 'case' method
In acf2280a the 'case' method of APISite has been deprecated in favor of
the namespace's case value or using the siteinfo directly. This is
removing the usage from pagegenerators_tests and only validating the
case method returns the siteinfo value in site_tests.
It modifies the pagegenerator test testing the TextfilePageGenerator so
that the data is now first orderd by how they appear in the file and
then by the case sensitivity.
Change-Id: I3ebdfa6ffdbfae8e0fdaa533f7283e8a2acab707
---
M tests/pagegenerators_tests.py
M tests/site_tests.py
2 files changed, 21 insertions(+), 8 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/pagegenerators_tests.py b/tests/pagegenerators_tests.py
index 7269493..f88ba64 100755
--- a/tests/pagegenerators_tests.py
+++ b/tests/pagegenerators_tests.py
@@ -264,24 +264,36 @@
dry = True
- expected_titles = {
- 'case-sensitive': ('file', 'bracket', 'MediaWiki:Test',
- 'under score', 'Upper case'),
- 'first-letter': ('File', 'Bracket', 'MediaWiki:Test', 'Under score',
- 'Upper case'),
+ title_columns = {
+ 'case-sensitive': 0,
+ 'first-letter': 1,
}
+
+ expected_titles = (
+ ('file', 'File'),
+ ('bracket', 'Bracket'),
+ ('MediaWiki:Test', 'MediaWiki:Test'),
+ ('under score', 'Under score'),
+ ('Upper case', 'Upper case'),
+ )
def test_brackets(self):
filename = os.path.join(_data_dir, 'pagelist-brackets.txt')
site = self.get_site()
titles = list(pagegenerators.TextfilePageGenerator(filename, site))
- self.assertPagelistTitles(titles, self.expected_titles[site.case()])
+ self.assertEqual(len(titles), len(self.expected_titles))
+ expected_titles = [expected_title[self.title_columns[site.namespaces[page.namespace()].case]]
+ for expected_title, page in zip(self.expected_titles, titles)]
+ self.assertPageTitlesEqual(titles, expected_titles)
def test_lines(self):
filename = os.path.join(_data_dir, 'pagelist-lines.txt')
site = self.get_site()
titles = list(pagegenerators.TextfilePageGenerator(filename, site))
- self.assertPagelistTitles(titles, self.expected_titles[site.case()])
+ self.assertEqual(len(titles), len(self.expected_titles))
+ expected_titles = [expected_title[self.title_columns[site.namespaces[page.namespace()].case]]
+ for expected_title, page in zip(self.expected_titles, titles)]
+ self.assertPageTitlesEqual(titles, expected_titles)
class TestYearPageGenerator(DefaultSiteTestCase):
diff --git a/tests/site_tests.py b/tests/site_tests.py
index d8d305e..1fe5e1a 100644
--- a/tests/site_tests.py
+++ b/tests/site_tests.py
@@ -1593,7 +1593,8 @@
self.assertRegex(mysite.siteinfo['timezone'], "([A-Z]{3,4}|[A-Z][a-z]+/[A-Z][a-z]+)")
self.assertIsInstance(datetime.strptime(mysite.siteinfo['time'], "%Y-%m-%dT%H:%M:%SZ"), datetime)
self.assertGreater(mysite.siteinfo['maxuploadsize'], 0)
- self.assertIn(mysite.case(), ["first-letter", "case-sensitive"])
+ self.assertIn(mysite.siteinfo['case'], ["first-letter", "case-sensitive"])
+ self.assertEqual(mysite.case(), mysite.siteinfo['case'])
self.assertEqual(re.findall("\$1", mysite.siteinfo['articlepath']), ["$1"])
def entered_loop(iterable):
--
To view, visit https://gerrit.wikimedia.org/r/203641
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I3ebdfa6ffdbfae8e0fdaa533f7283e8a2acab707
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: Ricordisamoa <ricordisamoa(a)openmailbox.org>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: [FIX] script tests: Expect stdout text
......................................................................
[FIX] script tests: Expect stdout text
This adds support for text in stdout. Scripts either output parts of it
or nothing.
Bug: T96615
Change-Id: Ia454447bf55cb9c05da1204a26fe49004154cd14
---
M tests/script_tests.py
1 file changed, 16 insertions(+), 7 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/script_tests.py b/tests/script_tests.py
index 5731006..53bfa4e 100644
--- a/tests/script_tests.py
+++ b/tests/script_tests.py
@@ -17,6 +17,9 @@
from tests.aspects import unittest, DefaultSiteTestCase, MetaTestCaseClass, PwbTestCase
from tests.utils import allowed_failure, execute_pwb
+if sys.version_info[0] > 2:
+ basestring = (str, )
+
scripts_path = os.path.join(_root_dir, 'scripts')
# These dependencies are not always the package name which is in setup.py.
@@ -139,9 +142,10 @@
'pagefromfile': 'Please enter the file name',
'replace': 'Press Enter to use this automatic message',
'script_wui': 'Pre-loading all relevant page contents',
- 'shell': 'Welcome to the',
+ 'shell': ('>>> ', 'Welcome to the'),
'spamremove': 'No spam site specified',
'transferbot': 'Target site not different from source site', # Bug 68662
+ 'unusedfiles': ('Working on', None),
'version': 'unicode test: ',
'watchlist': 'Retrieving watchlist',
@@ -231,7 +235,12 @@
if expected_results and script_name in expected_results:
error = expected_results[script_name]
+ if isinstance(error, basestring):
+ stdout = None
+ else:
+ stdout, error = error
else:
+ stdout = None
error = None
result = execute_pwb(cmd, data_in, timeout=timeout, error=error)
@@ -284,13 +293,13 @@
if 'Global arguments available for all' not in result['stdout']:
# Specifically look for deprecated
self.assertNotIn('deprecated', result['stdout'].lower())
- # But also complain if there is any stdout
- # but ignore shell.py emiting its '>>> ' prompt.
- if ((script_name == 'shell' and
- set(result['stdout']).issubset(set('> \n'))) or
- result['stdout'] == ''):
+ if result['stdout'] == '':
result['stdout'] = None
- self.assertIsNone(result['stdout'])
+ # But also complain if there is any stdout
+ if stdout is not None and result['stdout'] is not None:
+ self.assertIn(stdout, result['stdout'])
+ else:
+ self.assertIsNone(result['stdout'])
self.assertIn(result['exit_code'], exit_codes)
--
To view, visit https://gerrit.wikimedia.org/r/205458
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ia454447bf55cb9c05da1204a26fe49004154cd14
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: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: Strips CFD comments on real cat moves too.
......................................................................
Strips CFD comments on real cat moves too.
Change-Id: If09a4b9b554f11264d4dfc3601a0d51b5d27df17
---
M scripts/category.py
1 file changed, 27 insertions(+), 7 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
Cyde: Looks good to me, but someone else must approve
jenkins-bot: Verified
diff --git a/scripts/category.py b/scripts/category.py
index 1342d45..62d9b75 100755
--- a/scripts/category.py
+++ b/scripts/category.py
@@ -101,10 +101,10 @@
# (C) Daniel Herding, 2004
# (C) Wikipedian, 2004-2008
# (C) leogregianin, 2004-2008
-# (C) Cyde, 2006-2010
+# (C) Ben McIlwain (CydeWeys), 2006-2015
# (C) Anreas J Schwab, 2007
-# (C) xqt, 2009-2014
-# (C) Pywikibot team, 2008-2014
+# (C) xqt, 2009-2015
+# (C) Pywikibot team, 2008-2015
#
# Distributed under the terms of the MIT license.
#
@@ -533,8 +533,10 @@
if self.can_move_cats:
if can_move_page:
oldcattitle = self.oldcat.title()
- self.oldcat.move(self.newcat.title(), reason=self.comment,
- movetalkpage=can_move_talk)
+ self.newcat = self.oldcat.move(self.newcat.title(),
+ reason=self.comment,
+ movetalkpage=can_move_talk)
+ self._strip_cfd_templates()
self.oldcat = pywikibot.Category(self.oldcat.site,
oldcattitle)
else:
@@ -628,7 +630,12 @@
return move_possible
def _movecat(self):
- """Private function to move the category page.
+ """Private function to move the category page by copying its contents.
+
+ Note that this method of moving category pages by copying over the raw
+ text been deprecated by the addition of true category moving (analogous
+ to page moving) in MediaWiki, and so the raw text method is no longer
+ the default.
Do not use this function from outside the class.
"""
@@ -640,17 +647,30 @@
template_vars = (self.oldcat.title(), authors)
comment = i18n.twtranslate(self.site, 'category-renamed', template_vars)
self.newcat.text = self.oldcat.text
- # Replace stuff
+ self._strip_cfd_templates(comment)
+
+ def _strip_cfd_templates(self, comment=None):
+ """Private function to strip out CFD templates from the new category.
+
+ The new category is saved.
+
+ Do not use this function from outside the class.
+ """
+ # Remove all substed CFD templates
REGEX = r"<!--BEGIN CFD TEMPLATE-->.*?<!--END CFD TEMPLATE-->"
match = re.compile(REGEX,
re.IGNORECASE | re.MULTILINE | re.DOTALL)
self.newcat.text = match.sub('', self.newcat.text)
+ # Remove all language-specified, non substed CFD templates
site_templates = i18n.translate(self.site, cfd_templates) or ()
for template_name in site_templates:
match = re.compile(r"{{%s.*?}}" % template_name, re.IGNORECASE)
self.newcat.text = match.sub('', self.newcat.text)
# Remove leading whitespace
self.newcat.text = self.newcat.text.lstrip()
+ if not comment:
+ comment = i18n.twtranslate(self.site,
+ 'category-strip-cfd-templates')
self.newcat.save(comment)
def _movetalk(self):
--
To view, visit https://gerrit.wikimedia.org/r/205098
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: If09a4b9b554f11264d4dfc3601a0d51b5d27df17
Gerrit-PatchSet: 3
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Cyde <cydeweys(a)gmail.com>
Gerrit-Reviewer: Cyde <cydeweys(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 <>
jenkins-bot has submitted this change and it was merged.
Change subject: [IMPROV] script_tests: Test for exit code later
......................................................................
[IMPROV] script_tests: Test for exit code later
As the test for exit code is not very descriptive it should do the tests
for the output first (which show the output when there is a problem).
Change-Id: Ic5100fe595baa49337c08f8c30b7bd68c4c63f87
---
M tests/script_tests.py
1 file changed, 5 insertions(+), 3 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/script_tests.py b/tests/script_tests.py
index dd44df3..5731006 100644
--- a/tests/script_tests.py
+++ b/tests/script_tests.py
@@ -253,7 +253,7 @@
if error:
self.assertIn(error, result['stderr'])
- self.assertIn(result['exit_code'], [0, 1, 2, -9])
+ exit_codes = [0, 1, 2, -9]
else:
if stderr_other == ['']:
stderr_other = None
@@ -261,10 +261,10 @@
self.assertIn('Global arguments available for all',
result['stdout'])
- self.assertEqual(result['exit_code'], 0)
+ exit_codes = [0]
else:
# auto-run
- self.assertIn(result['exit_code'], [0, -9])
+ exit_codes = [0, -9]
if (not result['stdout'] and not result['stderr']):
print(' auto-run script unresponsive after %d seconds'
@@ -292,6 +292,8 @@
result['stdout'] = None
self.assertIsNone(result['stdout'])
+ self.assertIn(result['exit_code'], exit_codes)
+
sys.stdout.flush()
return testScript
--
To view, visit https://gerrit.wikimedia.org/r/205233
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ic5100fe595baa49337c08f8c30b7bd68c4c63f87
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: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: [FIX] reflinks: Expect that urlopen return bytes
......................................................................
[FIX] reflinks: Expect that urlopen return bytes
With Python 3 an error occured on using the regex because it only allows
that either all three are bytes or are str but the result from urlopen
is bytes.
On Python 2 all strs are actually bytes by default so it worked fine
there. But with unicode_literals in 1e54a7d6 the replacement and pattern
changed into unicode. While the pattern works in Python 2 regardless the
replacement will force that the searched content is converted into
unicode. As that happens implicitly it'll use ASCII and cause an error
when it contains non-ASCII characters.
The getheader method has been removed Python 3 so it is using the
replacement in Python 3.
Bug: T94688
Change-Id: Icf7b5a02d12cea3ec969fc6a3420ea870ea37f0f
---
M scripts/reflinks.py
1 file changed, 8 insertions(+), 5 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/reflinks.py b/scripts/reflinks.py
index 41f8fc9..009e808 100755
--- a/scripts/reflinks.py
+++ b/scripts/reflinks.py
@@ -454,14 +454,14 @@
raise
# Regex to grasp content-type meta HTML tag in HTML source
- self.META_CONTENT = re.compile(r'(?i)<meta[^>]*content\-type[^>]*>')
+ self.META_CONTENT = re.compile(br'(?i)<meta[^>]*content\-type[^>]*>')
# Extract the encoding from a charset property (from content-type !)
- self.CHARSET = re.compile(r'(?i)charset\s*=\s*(?P<enc>[^\'",;>/]*)')
+ self.CHARSET = re.compile(br'(?i)charset\s*=\s*(?P<enc>[^\'",;>/]*)')
# Extract html title from page
self.TITLE = re.compile(r'(?is)(?<=<title>).*?(?=</title>)')
# Matches content inside <script>/<style>/HTML comments
self.NON_HTML = re.compile(
- r'(?is)<script[^>]*>.*?</script>|<style[^>]*>.*?</style>|<!--.*?-->|<!\[CDATA\[.*?\]\]>')
+ br'(?is)<script[^>]*>.*?</script>|<style[^>]*>.*?</style>|<!--.*?-->|<!\[CDATA\[.*?\]\]>')
# Authorized mime types for HTML pages
self.MIME = re.compile(
@@ -555,7 +555,10 @@
f = urlopen(ref.url)
# Try to get Content-Type from server
headers = f.info()
- contentType = headers.getheader('Content-Type')
+ if sys.version_info[0] > 2:
+ contentType = headers.get_content_type()
+ else:
+ contentType = headers.getheader('Content-Type')
if contentType and not self.MIME.search(contentType):
if ref.link.lower().endswith('.pdf') and \
not self.getOption('ignorepdf'):
@@ -645,7 +648,7 @@
f.close()
# remove <script>/<style>/comments/CDATA tags
- linkedpagetext = self.NON_HTML.sub('', linkedpagetext)
+ linkedpagetext = self.NON_HTML.sub(b'', linkedpagetext)
meta_content = self.META_CONTENT.search(linkedpagetext)
enc = []
--
To view, visit https://gerrit.wikimedia.org/r/205095
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Icf7b5a02d12cea3ec969fc6a3420ea870ea37f0f
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: Rubin <rubin(a)wikimedia.ru>
Gerrit-Reviewer: jenkins-bot <>