jenkins-bot has submitted this change and it was merged.
Change subject: Make arguments consistent across .protect() methods
......................................................................
Make arguments consistent across .protect() methods
Page.protect():
- use a single 'protections' argument as in APISite.protect()
although it defaults to 'None' it should be supplied.
- use **kwargs to pass 'expiry' and 'cascade' to APISite.protect()
- deprecated the 'edit', 'move', 'create' and 'upload' arguments
they will be translated into 'protections' but ONLY if it was
set to None (which is the case in exisiting scripts).
- deprecated the 'unprotect' argument (not present in the API)
APISite.protect():
- rename the 'summary' argument into 'reason' for consistency
with the Page method and the API
- use **kwargs to pass 'cascade' directly to Request()
Logic of 'edit', 'move', 'create' and 'upload':
- If protections is not None, it will warn for each value which
is not None and ignores them
- If protections is None, it'll create protections dict from them.
It will also warn for each value which is not None.
- 'edit' and 'move' are now default to False, so it warns only
if they are set explicitly in conjunction with an existing
protections dict. It'll also warn when they are False and
protections is None.
APISite:
- .protection_types(): return a set of available protection types
- .protection_levels(): return a set of available protection levels
- ._add_siteinfo(): queries additional siteinfo
- .getmagicwords(): uses _add_siteinfo()
Page.applicable_protections():
- return a set of protections applicable to that page, but this
is mostly hardcoded. But a future api.php update might fix it.
Change-Id: Ifc20770b7bbae8c86b920f8376e27d0bff47d2a3
---
M pywikibot/page.py
M pywikibot/site.py
2 files changed, 162 insertions(+), 56 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page.py b/pywikibot/page.py
index cf6f367..1450642 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -824,6 +824,30 @@
"""
return self.site.page_restrictions(self)
+ def applicable_protections(self):
+ """
+ Return the protection types allowed for that page.
+
+ If the page doesn't exists it only returns "create". Otherwise it
+ returns all protection types provided by the site, except "create".
+ It also removes "upload" if that page is not in the File namespace.
+
+ It is possible, that it returns an empty set, but only if original
+ protection types were removed.
+
+ @return: set of unicode
+ """
+ # Currently hard coded, but a future API update might allow us to
+ # properly determine the applicable protection types
+ p_types = set(self.site.protection_types())
+ if not self.exists():
+ return set(['create']) if 'create' in p_types else set()
+ else:
+ p_types.remove('create') # no existing page allows that
+ if not self.isImage(): # only file pages allow upload
+ p_types.remove('upload')
+ return p_types
+
def canBeEdited(self):
"""Determine whether the page may be edited.
@@ -1557,60 +1581,76 @@
return self.site.undelete(self, comment)
@deprecate_arg("throttle", None)
- def protect(self, edit='sysop', move='sysop', create=None, upload=None,
- unprotect=False, reason=None, prompt=True, expiry=None):
+ def protect(self, edit=False, move=False, create=None, upload=None,
+ unprotect=False, reason=None, prompt=True, protections=None,
+ **kwargs):
"""(Un)protect a wiki page. Requires administrator status.
Valid protection levels (in MediaWiki 1.12) are '' (equivalent to
'none'), 'autoconfirmed', and 'sysop'. If None is given, however,
that protection will be skipped.
- @param edit: Level of edit protection
- @param move: Level of move protection
- @param create: Level of create protection
- @param upload: Level of upload protection
- @param unprotect: If true, unprotect page editing and moving
- (equivalent to set both edit and move to '')
- @param reason: Edit summary.
- @param prompt: If true, ask user for confirmation.
- @param expiry: When the block should expire. This expiry will be
- applied to all protections.
- None, 'infinite', 'indefinite', 'never', and '' mean no expiry.
- @type expiry: pywikibot.Timestamp, string in GNU timestamp format
- (including ISO 8601).
+ @param protections: A dict mapping type of protection to protection
+ level of that type.
+ @type protections: dict
+ @param reason: Reason for the action
+ @type reason: basestring
+ @param prompt: Whether to ask user for confirmation
+ @type prompt: bool
"""
- if reason is None:
- if unprotect:
- un = u'un'
+ def deprecated(value, arg_name):
+ # if protections was set and value is None, don't interpret that
+ # argument. But otherwise warn that the parameter was set
+ # (even implicit)
+ if called_using_deprecated_arg:
+ if value is False: # explicit test for False (don't use not)
+ value = "sysop"
+ if value == "none": # 'none' doesn't seem do be accepted
+ value = ""
+ if value is not None: # empty string is allowed
+ protections[arg_name] = value
+ pywikibot.bot.warning(u'"protections" argument of '
+ 'protect() replaces "{}".'.format(arg_name))
else:
- un = u''
- pywikibot.output(u'Preparing to %sprotect %s.'
- % (un, self.title(asLink=True)))
+ if value:
+ pywikibot.bot.warning(u'"protections" argument of '
+ 'protect() replaces "{}"; cannot '
+ 'use both.'.format(arg_name))
+
+ # buffer that, because it might get changed
+ called_using_deprecated_arg = protections is None
+ if called_using_deprecated_arg:
+ protections = {}
+ deprecated(edit, "edit")
+ deprecated(move, "move")
+ deprecated(create, "create")
+ deprecated(upload, "upload")
+
+ if reason is None:
+ pywikibot.output(u'Preparing to protection change of %s.'
+ % (self.title(asLink=True)))
reason = pywikibot.input(u'Please enter a reason for the action:')
if unprotect:
- edit = move = ""
- # Apply to only edit and move for backward compatibility.
- # To unprotect article creation, for example,
- # create must be set to '' and the rest must be None
+ pywikibot.bot.warning(u'"unprotect" argument of protect() is '
+ 'deprecated')
+ protections = dict(
+ [(p_type, "") for p_type in self.applicable_protections()])
answer = 'y'
+ if prompt:
+ pywikibot.bot.warning(u'"prompt" argument of protect() is '
+ 'deprecated')
if prompt and not hasattr(self.site, '_noProtectPrompt'):
answer = pywikibot.inputChoice(
u'Do you want to change the protection level of %s?'
% self.title(asLink=True, forceInterwiki=True),
['Yes', 'No', 'All'],
- ['Y', 'N', 'A'],
+ ['y', 'N', 'a'],
'N')
- if answer in ['a', 'A']:
+ if answer == 'a':
answer = 'y'
self.site._noProtectPrompt = True
- if answer in ['y', 'Y']:
- protections = {
- 'edit': edit,
- 'move': move,
- 'create': create,
- 'upload': upload,
- }
- return self.site.protect(self, protections, reason, expiry)
+ if answer == 'y':
+ return self.site.protect(self, protections, reason, **kwargs)
def change_category(self, oldCat, newCat, comment=None, sortKey=None,
inPlace=True):
diff --git a/pywikibot/site.py b/pywikibot/site.py
index b70ad2d..25bfa07 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -1126,23 +1126,11 @@
def getmagicwords(self, word):
"""Return list of localized "word" magic words for the site."""
if not hasattr(self, "_magicwords"):
- sirequest = api.CachedRequest(
- expiry=config.API_config_expiry,
- site=self,
- action="query",
- meta="siteinfo",
- siprop="magicwords"
- )
try:
- sidata = sirequest.submit()
- assert 'query' in sidata, \
- "API siteinfo response lacks 'query' key"
- sidata = sidata['query']
- assert 'magicwords' in sidata, \
- "API siteinfo response lacks 'magicwords' key"
+ # don't cache in _siteinfo, because we cache it in _magicwords
+ magicwords = self._add_siteinfo("magicwords", False)
self._magicwords = dict((item["name"], item["aliases"])
- for item in sidata["magicwords"])
-
+ for item in magicwords)
except api.APIError:
# hack for older sites that don't support 1.13 properties
# probably should delete if we're not going to support pre-1.13
@@ -1186,6 +1174,44 @@
def pagename2codes(self, default=True):
"""Return list of localized PAGENAMEE tags for the site."""
return self.getmagicwords("pagenamee")
+
+ def _add_siteinfo(self, prop, cache, force=False):
+ """
+ Retrieve additional siteinfo and optionally cache it.
+
+ Queries the site and returns the properties. It can cache the value
+ so that future queries will access the cache. With C{force} set to
+ True it won't access the cache but it can still cache the value. If
+ the property doesn't exists it returns None.
+
+ @param prop: The property name of the siteinfo.
+ @type prop: str
+ @param cache: Should this be cached?
+ @type cache: bool
+ @param force: Should the cache be skipped?
+ @type force: bool
+ @return: The properties of the site.
+ @rtype: various (depends on prop)
+ """
+ if not hasattr(self, '_siteinfo'):
+ force = True # if it doesn't exists there won't be a cache
+ if cache: # but only initialise cache if that is requested
+ self._getsiteinfo()
+ if not force and prop in self._siteinfo:
+ return self._siteinfo[prop]
+ data = pywikibot.data.api.CachedRequest(
+ expiry=0 if force else pywikibot.config.API_config_expiry,
+ site=self,
+ action='query',
+ meta='siteinfo',
+ siprop=prop).submit()
+ try:
+ prop_data = data['query'][prop]
+ except KeyError:
+ prop_data = None
+ if cache:
+ self._siteinfo[prop] = prop_data
+ return prop_data
def _getsiteinfo(self, force=False):
"""Retrieve siteinfo and namespaces from site."""
@@ -3202,8 +3228,45 @@
"protect-invalidlevel": "Invalid protection level"
}
+ def protection_types(self):
+ """
+ Return the protection types available on this site.
+
+ With MediaWiki version 1.23 protection types can be retrieved. To
+ support older wikis, the default protection types 'create', 'edit',
+ 'move' and 'upload' are returned.
+
+ @return protection types available
+ @rtype: set of unicode instances
+ """
+ # implemented in b73b5883d486db0e9278ef16733551f28d9e096d
+ restrictions = self._add_siteinfo('restrictions', True)
+ if restrictions is None or 'types' not in restrictions:
+ return set([u'create', u'edit', u'move', u'upload'])
+ else:
+ return set(restrictions['types'])
+
+ def protection_levels(self):
+ """
+ Return the protection levels available on this site.
+
+ With MediaWiki version 1.23 protection levels can be retrieved. To
+ support older wikis, the default protection levels '', 'autoconfirmed',
+ and 'sysop' are returned.
+
+ @return protection types available
+ @rtype: set of unicode instances
+ """
+ # implemented in b73b5883d486db0e9278ef16733551f28d9e096d
+ restrictions = self._add_siteinfo('restrictions', True)
+ if restrictions is None or 'levels' not in restrictions:
+ return set([u'', u'autoconfirmed', u'sysop'])
+ else:
+ return set(restrictions['levels'])
+
@must_be(group='sysop')
- def protect(self, page, protections, summary, expiry=None):
+ @deprecate_arg("summary", "reason")
+ def protect(self, page, protections, reason, expiry=None, **kwargs):
"""(Un)protect a wiki page. Requires administrator status.
@param protections: A dict mapping type of protection to protection
@@ -3211,22 +3274,25 @@
'create', and 'upload'. Valid protection levels (in MediaWiki 1.12)
are '' (equivalent to 'none'), 'autoconfirmed', and 'sysop'.
If None is given, however, that protection will be skipped.
- @param summary: Edit summary.
+ @type protections: dict
+ @param reason: Reason for the action
+ @type reason: basestring
@param expiry: When the block should expire. This expiry will be applied
to all protections. If None, 'infinite', 'indefinite', 'never', or ''
is given, there is no expiry.
@type expiry: pywikibot.Timestamp, string in GNU timestamp format
(including ISO 8601).
"""
- token = self.token(page, "protect")
+ token = self.token(page, 'protect')
self.lock_page(page)
- protectList = [type + '=' + level for type, level in protections.items()
+ protectList = [ptype + '=' + level for ptype, level in protections.items()
if level is not None]
- req = api.Request(site=self, action="protect", token=token,
+ req = api.Request(site=self, action='protect', token=token,
title=page.title(withSection=False),
protections=protectList,
- reason=summary)
+ reason=reason,
+ **kwargs)
if isinstance(expiry, pywikibot.Timestamp):
expiry = expiry.toISOformat()
if expiry:
--
To view, visit https://gerrit.wikimedia.org/r/152187
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ifc20770b7bbae8c86b920f8376e27d0bff47d2a3
Gerrit-PatchSet: 8
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Ricordisamoa <ricordisamoa(a)openmailbox.org>
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: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: Nullzero <nullzero.free(a)gmail.com>
Gerrit-Reviewer: Ricordisamoa <ricordisamoa(a)openmailbox.org>
Gerrit-Reviewer: Russell Blau <russblau(a)imapmail.org>
Gerrit-Reviewer: XZise <CommodoreFabianus(a)gmx.de>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: Update test after the imagerecat script was fixed
......................................................................
Update test after the imagerecat script was fixed
The imagerecat script is now an auto-run script, and needs to
be killed after a few seconds.
Change-Id: I033d2ab10e2510c9c651e2ed66cf64ac1bf5485a
---
M tests/script_tests.py
1 file changed, 1 insertion(+), 1 deletion(-)
Approvals:
Ricordisamoa: Looks good to me, approved
jenkins-bot: Verified
diff --git a/tests/script_tests.py b/tests/script_tests.py
index b02d25c..8c80ade 100644
--- a/tests/script_tests.py
+++ b/tests/script_tests.py
@@ -83,6 +83,7 @@
'cfd',
'clean_sandbox',
'disambredir',
+ 'imagerecat',
'lonelypages',
'misspelling',
'revertbot',
@@ -215,7 +216,6 @@
if script_name in ['checkimages', # bug 68613
'data_ingestion', # bug 68611
'flickrripper', # bug 68606 (and deps)
- 'imagerecat', # bug 68658
'upload', # raises custom ValueError
] or (
((config.family != 'wikipedia' or config.mylang != 'en') and script_name == 'cfd') or
--
To view, visit https://gerrit.wikimedia.org/r/154238
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I033d2ab10e2510c9c651e2ed66cf64ac1bf5485a
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: 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: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: Bug 68660: pagefromfile handles not existing file
......................................................................
Bug 68660: pagefromfile handles not existing file
Handling of not existing file added.
Filename existence is checked, user can input a new filename in case or
quit.
Help is shown if user quits or should IOError still occurs.
Change-Id: Ide672e331c9084c74641be7b4633ace7216ef31b
---
M scripts/pagefromfile.py
M tests/script_tests.py
2 files changed, 40 insertions(+), 9 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/pagefromfile.py b/scripts/pagefromfile.py
index 221065e..8753db6 100644
--- a/scripts/pagefromfile.py
+++ b/scripts/pagefromfile.py
@@ -17,6 +17,7 @@
-start:xxx Specify the text that marks the beginning of a page
-end:xxx Specify the text that marks the end of a page
-file:xxx Give the filename we are getting our material from
+ (default: dict.txt)
-include The beginning and end markers should be included
in the page.
-titlestart:xxx Use xxx in place of ''' for identifying the
@@ -25,7 +26,7 @@
end of page title
-notitle do not include the title, including titlestart, and
titleend, in the page
--nocontent If page has this statment it dosen't append
+-nocontent If page has this statment it doesn't append
(example: -nocontent:"{{infobox")
-summary:xxx Use xxx as the edit summary for the upload - if
a page exists, standard messages are appended
@@ -49,8 +50,10 @@
__version__ = '$Id$'
#
+import os
import re
import codecs
+
import pywikibot
from pywikibot import config, Bot, i18n
@@ -154,9 +157,18 @@
Responsible for reading the file.
The run() method yields a (title, contents) tuple for each found page.
+
"""
+
def __init__(self, filename, pageStartMarker, pageEndMarker,
titleStartMarker, titleEndMarker, include, notitle):
+ """Constructor.
+
+ Check if self.file name exists. If not, ask for a new filename.
+ User can quit.
+
+ """
+
self.filename = filename
self.pageStartMarker = pageStartMarker
self.pageEndMarker = pageEndMarker
@@ -166,13 +178,15 @@
self.notitle = notitle
def run(self):
- pywikibot.output('Reading \'%s\'...' % self.filename)
+ """Read file and yield page title and content."""
+
+ pywikibot.output('\n\nReading \'%s\'...' % self.filename)
try:
f = codecs.open(self.filename, 'r',
encoding=config.textfile_encoding)
except IOError as err:
pywikibot.output(str(err))
- return
+ raise IOError
text = f.read()
position = 0
@@ -264,11 +278,27 @@
else:
pywikibot.output(u"Disregarding unknown argument %s." % arg)
- reader = PageFromFileReader(filename, pageStartMarker, pageEndMarker,
- titleStartMarker, titleEndMarker, include,
- notitle)
- bot = PageFromFileRobot(reader, **options)
- bot.run()
+ failed_filename = False
+ while not os.path.isfile(filename):
+ pywikibot.output('\nFile \'%s\' does not exist. ' % filename)
+ _input = pywikibot.input(
+ 'Please enter the file name [q to quit]:')
+ if _input == 'q':
+ failed_filename = True
+ break
+ else:
+ filename = _input
+
+ # show help text from the top of this file if reader failed
+ # or User quit.
+ if failed_filename:
+ pywikibot.showHelp()
+ else:
+ reader = PageFromFileReader(filename, pageStartMarker, pageEndMarker,
+ titleStartMarker, titleEndMarker, include,
+ notitle)
+ bot = PageFromFileRobot(reader, **options)
+ bot.run()
if __name__ == "__main__":
main()
diff --git a/tests/script_tests.py b/tests/script_tests.py
index abfdcc4..b02d25c 100644
--- a/tests/script_tests.py
+++ b/tests/script_tests.py
@@ -66,6 +66,7 @@
'editarticle': 'Test page\n',
'interwiki': 'Test page\n',
# 'misspelling': 'q\n', # pressing 'q' doesnt work. bug 68663
+ 'pagefromfile': 'q\n',
'replace': 'foo\nbar\n\n\n', # match, replacement,
# Enter to begin, Enter for default summary.
'shell': '\n', # exits on end of stdin
@@ -111,6 +112,7 @@
'imageuncat': 'You have to specify the generator ',
'interwiki': 'does not exist. Skipping.', # 'Test page' does not exist
'login': 'Logged in on ',
+ 'pagefromfile': 'Please enter the file name',
'replace': 'Press Enter to use this default message',
'replicate_wiki': 'error: too few arguments',
'script_wui': 'Pre-loading all relevant page contents',
@@ -214,7 +216,6 @@
'data_ingestion', # bug 68611
'flickrripper', # bug 68606 (and deps)
'imagerecat', # bug 68658
- 'pagefromfile', # bug 68660
'upload', # raises custom ValueError
] or (
((config.family != 'wikipedia' or config.mylang != 'en') and script_name == 'cfd') or
--
To view, visit https://gerrit.wikimedia.org/r/152181
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ide672e331c9084c74641be7b4633ace7216ef31b
Gerrit-PatchSet: 8
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Mpaa <mpaa.wiki(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: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: Bug 69551-add Vietnamese to timestripper_tests.py plus bug fixing
......................................................................
Bug 69551-add Vietnamese to timestripper_tests.py plus bug fixing
Added Vietnamese language to timestripper_tests.py.
Fixed also a bug in TimeStripper.last_match_and_replace() found
debugging Vietnamese.
Month was not replaced correctly.
Inserted proper logic to handle when months are expressed as digits or
in words.
Updated timestripper_tests.py to cover the logic in
last_match_and_replace(), using sites with the two formats.
Change-Id: I148663b7c694c499c194e993526ea8f928e4c174
---
M pywikibot/textlib.py
M tests/timestripper_tests.py
2 files changed, 130 insertions(+), 13 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py
index c6997a1..03c2d0a 100644
--- a/pywikibot/textlib.py
+++ b/pywikibot/textlib.py
@@ -1201,9 +1201,11 @@
# work around for cs wiki: if month are in digits, we assume
# that format is dd. mm. (with dot and spaces optional)
if any(_.isdigit() for _ in self.origNames2monthNum):
+ self.is_digit_month = True
monthR = r'(?P<month>(%s)|\d{1,2}\.?)' % u'|'.join(escaped_months)
dayR = r'(?P<day>(3[01]|[12]\d|0?[1-9]))\.?\s*[01]?\d\.?'
else:
+ self.is_digit_month = False
monthR = r'(?P<month>(%s))' % u'|'.join(escaped_months)
dayR = r'(?P<day>(3[01]|[12]\d|0?[1-9]))\.?'
@@ -1244,8 +1246,11 @@
# replace all matches but the last two
# (i.e. allow to search for dd. mm.)
if pat == self.pmonthR:
- if cnt > 2:
- txt = pat.sub(marker, txt, cnt - 2)
+ if self.is_digit_month:
+ if cnt > 2:
+ txt = pat.sub(marker, txt, cnt - 2)
+ else:
+ txt = pat.sub(marker, txt)
else:
txt = pat.sub(marker, txt)
return (txt, m.groupdict())
diff --git a/tests/timestripper_tests.py b/tests/timestripper_tests.py
index 1b3f171..9d12b04 100644
--- a/tests/timestripper_tests.py
+++ b/tests/timestripper_tests.py
@@ -16,13 +16,13 @@
from pywikibot.textlib import TimeStripper, tzoneFixedOffset
-class TestTimeStripper(PywikibotTestCase):
- """Test cases for Link objects"""
+class TestTimeStripperWithNoDigitsAsMonths(PywikibotTestCase):
+ """Test cases for TimeStripper methods"""
def setUp(self):
site = pywikibot.Site('fr', 'wikipedia')
self.ts = TimeStripper(site)
- super(TestTimeStripper, self).setUp()
+ super(TestTimeStripperWithNoDigitsAsMonths, self).setUp()
def test_findmarker(self):
"""Test that string which is not part of text is found"""
@@ -32,15 +32,43 @@
'@@@@@@')
def test_last_match_and_replace(self):
- """Test that pattern matches the righmost item"""
+ """Test that pattern matches and removes items correctly."""
- txtWithMatch = u'this string has one 1998, 1999 and 3000 in it'
+ txtWithOneMatch = u'this string has 3000, 1999 and 3000 in it'
+ txtWithTwoMatch = u'this string has 1998, 1999 and 3000 in it'
txtWithNoMatch = u'this string has no match'
pat = self.ts.pyearR
- self.assertEqual(self.ts.last_match_and_replace(txtWithMatch, pat),
- (u'this string has one @@, @@ and 3000 in it',
+ self.assertEqual(self.ts.last_match_and_replace(txtWithOneMatch, pat),
+ (u'this string has 3000, @@ and 3000 in it',
{'year': u'1999'})
+ )
+ self.assertEqual(self.ts.last_match_and_replace(txtWithTwoMatch, pat),
+ (u'this string has @@, @@ and 3000 in it',
+ {'year': u'1999'})
+ )
+ self.assertEqual(self.ts.last_match_and_replace(txtWithNoMatch, pat),
+ (txtWithNoMatch,
+ None)
+ )
+
+ txtWithOneMatch = u'this string has XXX, YYY and fév in it'
+ txtWithTwoMatch = u'this string has XXX, mars and fév in it'
+ txtWithThreeMatch = u'this string has avr, mars and fév in it'
+ txtWithNoMatch = u'this string has no match'
+ pat = self.ts.pmonthR
+
+ self.assertEqual(self.ts.last_match_and_replace(txtWithOneMatch, pat),
+ (u'this string has XXX, YYY and @@ in it',
+ {'month': u'fév'})
+ )
+ self.assertEqual(self.ts.last_match_and_replace(txtWithTwoMatch, pat),
+ (u'this string has XXX, @@ and @@ in it',
+ {'month': u'fév'})
+ )
+ self.assertEqual(self.ts.last_match_and_replace(txtWithThreeMatch, pat),
+ (u'this string has @@, @@ and @@ in it',
+ {'month': u'fév'})
)
self.assertEqual(self.ts.last_match_and_replace(txtWithNoMatch, pat),
(txtWithNoMatch,
@@ -62,8 +90,55 @@
self.assertEqual(self.ts.timestripper(txtNoMatch), None)
+class TestTimeStripperWithDigitsAsMonths(PywikibotTestCase):
+ """Test cases for TimeStripper methods"""
+
+ def setUp(self):
+ site = pywikibot.Site('cs', 'wikipedia')
+ self.ts = TimeStripper(site)
+ super(TestTimeStripperWithDigitsAsMonths, self).setUp()
+
+ def test_last_match_and_replace(self):
+ """Test that pattern matches and removes items correctly."""
+
+ txtWithOneMatch = u'this string has XX. YY. 12. in it'
+ txtWithTwoMatch = u'this string has XX. 1. 12. in it'
+ txtWithThreeMatch = u'this string has 1. 1. 12. in it'
+ txtWithNoMatch = u'this string has no match'
+ pat = self.ts.pmonthR
+
+ self.assertEqual(self.ts.last_match_and_replace(txtWithOneMatch, pat),
+ (u'this string has XX. YY. 12. in it',
+ {'month': u'12.'})
+ )
+ self.assertEqual(self.ts.last_match_and_replace(txtWithTwoMatch, pat),
+ (u'this string has XX. 1. 12. in it',
+ {'month': u'12.'})
+ )
+ self.assertEqual(self.ts.last_match_and_replace(txtWithThreeMatch, pat),
+ (u'this string has @@ 1. 12. in it',
+ {'month': u'12.'})
+ )
+ self.assertEqual(self.ts.last_match_and_replace(txtWithNoMatch, pat),
+ (txtWithNoMatch,
+ None)
+ )
+
+ def test_timestripper(self):
+ txtMatch = u'3. 2. 2010, 19:48 (UTC) 7. 2. 2010 19:48 (UTC)'
+ txtNoMatch = u'3 March 2010 19:48 (UTC) 7 March 2010 19:48 (UTC)'
+
+ tzone = tzoneFixedOffset(self.ts.site.siteinfo['timeoffset'],
+ self.ts.site.siteinfo['timezone'])
+
+ res = datetime.datetime(2010, 2, 7, 19, 48, tzinfo=tzone)
+
+ self.assertEqual(self.ts.timestripper(txtMatch), res)
+ self.assertEqual(self.ts.timestripper(txtNoMatch), None)
+
+
class TestEnglishTimeStripper(PywikibotTestCase):
- """Test cases for Link objects"""
+ """Test cases for English language"""
def setUp(self):
site = pywikibot.Site('en', 'wikipedia')
@@ -86,7 +161,7 @@
class TestCzechTimeStripper(PywikibotTestCase):
- """Test cases for Link objects"""
+ """Test cases for Czech language"""
def setUp(self):
site = pywikibot.Site('cs', 'wikipedia')
@@ -109,7 +184,7 @@
class TestPortugueseTimeStripper(PywikibotTestCase):
- """Test cases for Link objects"""
+ """Test cases for Portuguese language"""
def setUp(self):
site = pywikibot.Site('pt', 'wikipedia')
@@ -132,7 +207,7 @@
class TestNorwegianTimeStripper(PywikibotTestCase):
- """Test cases for Link objects"""
+ """Test cases for Norwegian language"""
def setUp(self):
site = pywikibot.Site('no', 'wikipedia')
@@ -154,6 +229,43 @@
self.assertEqual(self.ts.timestripper(txtNoMatch), None)
+class TestVietnameseTimeStripper(PywikibotTestCase):
+ """Test cases for Vietnamese language"""
+
+ def setUp(self):
+ site = pywikibot.Site('vi', 'wikipedia')
+ self.ts = TimeStripper(site)
+ super(TestVietnameseTimeStripper, self).setUp()
+
+ def test_timestripper_01(self):
+ """Test that correct date is matched"""
+
+ txtMatch = u'16:41, ngày 15 tháng 9 năm 2008 (UTC) 16:41, ngày 12 tháng 9 năm 2008 (UTC)'
+ txtNoMatch = u'16:41, ngày 15 March 9 năm 2008 (UTC) 16:41, ngày 12 March 9 năm 2008 (UTC)'
+
+ tzone = tzoneFixedOffset(self.ts.site.siteinfo['timeoffset'],
+ self.ts.site.siteinfo['timezone'])
+
+ res = datetime.datetime(2008, 9, 12, 16, 41, tzinfo=tzone)
+
+ self.assertEqual(self.ts.timestripper(txtMatch), res)
+ self.assertEqual(self.ts.timestripper(txtNoMatch), None)
+
+ def test_timestripper_02(self):
+ """Test that correct date is matched"""
+
+ txtMatch = u'21:18, ngày 13 tháng 8 năm 2014 (UTC) 21:18, ngày 14 tháng 8 năm 2014 (UTC)'
+ txtNoMatch = u'21:18, ngày 13 March 8 năm 2014 (UTC) 21:18, ngày 14 March 8 năm 2014 (UTC)'
+
+ tzone = tzoneFixedOffset(self.ts.site.siteinfo['timeoffset'],
+ self.ts.site.siteinfo['timezone'])
+
+ res = datetime.datetime(2014, 8, 14, 21, 18, tzinfo=tzone)
+
+ self.assertEqual(self.ts.timestripper(txtMatch), res)
+ self.assertEqual(self.ts.timestripper(txtNoMatch), None)
+
+
if __name__ == '__main__':
try:
unittest.main()
--
To view, visit https://gerrit.wikimedia.org/r/154209
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I148663b7c694c499c194e993526ea8f928e4c174
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Mpaa <mpaa.wiki(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: Remove implicit use of textlib in page module
......................................................................
Remove implicit use of textlib in page module
Use of textlib in the page module should be trackable, so each
use should have an explicit textlib module name.
Change-Id: Iabede1697aa1f5c8e3039b2b404029bc6cfd55ff
---
M pywikibot/page.py
1 file changed, 9 insertions(+), 9 deletions(-)
Approvals:
Ricordisamoa: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page.py b/pywikibot/page.py
index 5d5114a..dbb3be5 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -24,6 +24,7 @@
import pywikibot.site
from pywikibot.exceptions import AutoblockUser, UserActionRefuse
from pywikibot.tools import ComparableMixin
+from pywikibot import textlib
import hashlib
try:
@@ -616,8 +617,8 @@
@return bool
"""
txt = self.get()
- txt = pywikibot.removeLanguageLinks(txt, site=self.site)
- txt = pywikibot.removeCategoryLinks(txt, site=self.site)
+ txt = textlib.removeLanguageLinks(txt, site=self.site)
+ txt = textlib.removeCategoryLinks(txt, site=self.site)
return len(txt) < 4
def isTalkPage(self):
@@ -1094,7 +1095,7 @@
else:
text = self.text
for linkmatch in pywikibot.link_regex.finditer(
- pywikibot.removeDisabledParts(text)):
+ textlib.removeDisabledParts(text)):
linktitle = linkmatch.group("title")
link = Link(linktitle, self.site)
# only yield links that are to a different site and that
@@ -1229,7 +1230,7 @@
# WARNING: may not return all templates used in particularly
# intricate cases such as template substitution
titles = list(t.title() for t in self.templates())
- templates = pywikibot.extract_templates_and_params(self.text)
+ templates = textlib.extract_templates_and_params(self.text)
# backwards-compatibility: convert the dict returned as the second
# element into a list in the format used by old scripts
result = []
@@ -1633,8 +1634,7 @@
# get list of Category objects the article is in and remove possible
# duplicates
cats = []
- for cat in pywikibot.textlib.getCategoryLinks(self.text,
- site=self.site):
+ for cat in textlib.getCategoryLinks(self.text, site=self.site):
if cat not in cats:
cats.append(cat)
@@ -1659,8 +1659,8 @@
if inPlace or self.namespace() == 10:
oldtext = self.get(get_redirect=True)
- newtext = pywikibot.replaceCategoryInPlace(oldtext, oldCat, newCat,
- site=self.site)
+ newtext = textlib.replaceCategoryInPlace(oldtext, oldCat, newCat,
+ site=self.site)
else:
if newCat:
cats[cats.index(oldCat)] = Category(site, newCat.title(),
@@ -1670,7 +1670,7 @@
cats.pop(cats.index(oldCat))
oldtext = self.get(get_redirect=True)
try:
- newtext = pywikibot.replaceCategoryLinks(oldtext, cats)
+ newtext = textlib.replaceCategoryLinks(oldtext, cats)
except ValueError:
# Make sure that the only way replaceCategoryLinks() can return
# a ValueError is in the case of interwiki links to self.
--
To view, visit https://gerrit.wikimedia.org/r/154079
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Iabede1697aa1f5c8e3039b2b404029bc6cfd55ff
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(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: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: Update Pywikipedia to Pywikibot and fix (C) lines
......................................................................
Update Pywikipedia to Pywikibot and fix (C) lines
- Replace pywikibot with Pywikibot where possible.
- Standardise content and layout of copyright info at the top of files.
- Update year of last substantive code change on touched files.
- Revise the intro prose of externals/README
Change-Id: I8822e3f978f5113df778d835030f372d3c98e68e
---
M CREDITS
M README.rst
M externals/README
M generate_family_file.py
M generate_user_files.py
M pywikibot/botirc.py
M pywikibot/comms/__init__.py
M pywikibot/date.py
M pywikibot/editor.py
M pywikibot/families/__init__.py
M pywikibot/pagegenerators.py
M pywikibot/userinterfaces/__init__.py
M pywikibot/userinterfaces/terminal_interface_win32.py
M scripts/blockpageschecker.py
M scripts/capitalize_redirects.py
M scripts/checkimages.py
M scripts/coordinate_import.py
M scripts/delete.py
M scripts/disambredir.py
M scripts/editarticle.py
M scripts/fixing_redirects.py
M scripts/illustrate_wikidata.py
M scripts/imagerecat.py
M scripts/imageuncat.py
M scripts/maintenance/make_i18n_dict.py
M scripts/makecat.py
M scripts/protect.py
M scripts/reflinks.py
M scripts/replace.py
M scripts/replicate_wiki.py
M scripts/spamremove.py
M scripts/template.py
M scripts/templatecount.py
M scripts/transferbot.py
M scripts/version.py
M scripts/welcome.py
M tests/__init__.py
M tests/api_tests.py
M tests/i18n_tests.py
M tests/pwb_tests.py
M tests/weblib_tests.py
M tests/wikidataquery_tests.py
42 files changed, 56 insertions(+), 52 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/CREDITS b/CREDITS
index a87d3e5..5807c00 100644
--- a/CREDITS
+++ b/CREDITS
@@ -1,4 +1,4 @@
-pywikibot is an open-source project that cannot exist without your
+Pywikibot is an open-source project that cannot exist without your
contributions. We would therefore like to thank everyone who has
contributed:
diff --git a/README.rst b/README.rst
index e340093..131da86 100644
--- a/README.rst
+++ b/README.rst
@@ -1,7 +1,7 @@
Pywikibot Framework
===================
-The pywikibot framework is a Python library that interfaces with the
+The Pywikibot framework is a Python library that interfaces with the
`MediaWiki API <https://www.mediawiki.org/wiki/Special:MyLanguage/API:Main_page>`_. Also included are
various general function scripts that can be adapted for different
tasks.
diff --git a/externals/README b/externals/README
index 52cb293..2195f75 100644
--- a/externals/README
+++ b/externals/README
@@ -1,4 +1,4 @@
-This package is only necessary to run pywikibot from a fully self-sufficient
+This package is only necessary to run Pywikibot from a fully self-sufficient
(no other dependencies other than python 2.6+) directory.
This is especially useful on Windows.
diff --git a/generate_family_file.py b/generate_family_file.py
index fd5aa0d..5a8f6e5 100644
--- a/generate_family_file.py
+++ b/generate_family_file.py
@@ -8,7 +8,7 @@
print_function, unicode_literals)
#
# (C) Merlijn van Deen, 2010-2013
-# (C) Pywikibot team, 2010-2013
+# (C) Pywikibot team, 2010-2014
#
# Distributed under the terms of the MIT license
#
@@ -39,7 +39,8 @@
def urlopen(url):
req = urllib2.Request(
url,
- headers={'User-agent': 'Pywikibot Family File Generator 2.0 - https://www.mediawiki.org/wiki/pywikibot'})
+ headers={'User-agent': 'Pywikibot Family File Generator 2.0'
+ ' - https://www.mediawiki.org/wiki/Pywikibot'})
uo = urllib2.urlopen(req)
try:
if sys.version_info[0] == 2:
diff --git a/generate_user_files.py b/generate_user_files.py
index 328ba53..9cf7aeb 100644
--- a/generate_user_files.py
+++ b/generate_user_files.py
@@ -333,7 +333,7 @@
if os.path.exists(os.path.join(base_dir, "user-config.py")):
break
do_copy = raw_input("Do you want to copy user files from an existing "
- "pywikibot installation? ").upper().strip()
+ "Pywikibot installation? ").upper().strip()
if do_copy and "YES".startswith(do_copy):
oldpath = raw_input("Path to existing wikipedia.py? ")
if not os.path.exists(oldpath):
diff --git a/pywikibot/botirc.py b/pywikibot/botirc.py
index f2138d3..6ec058e 100644
--- a/pywikibot/botirc.py
+++ b/pywikibot/botirc.py
@@ -6,7 +6,7 @@
http://python-irclib.sourceforge.net/
"""
#
-# (C) Balasyum
+# (C) Balasyum, 2008
# (C) Pywikibot team, 2008-2014
#
# Distributed under the terms of the MIT license.
diff --git a/pywikibot/comms/__init__.py b/pywikibot/comms/__init__.py
index 22a940a..df0dcca 100644
--- a/pywikibot/comms/__init__.py
+++ b/pywikibot/comms/__init__.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
-# (C) Pywikipedia bot team, 2007
+# (C) Pywikibot team, 2007-2008
#
# Distributed under the terms of the MIT license.
#
diff --git a/pywikibot/date.py b/pywikibot/date.py
index 4e6de5a..c6b1944 100644
--- a/pywikibot/date.py
+++ b/pywikibot/date.py
@@ -8,7 +8,7 @@
# (C) Daniel Herding, 2004
# (C) Ævar Arnfjörð Bjarmason, 2004
# (C) Andre Engels, 2004-2005
-# (C) Yuri Astrakhan, 2005-2006 FirstnameLastname(a)gmail.com
+# (C) Yuri Astrakhan, 2005-2006 (<Firstname><Lastname>@gmail.com)
# (years/decades/centuries/millenniums str <=> int conversions)
# (C) Pywikibot team, 2004-2014
#
diff --git a/pywikibot/editor.py b/pywikibot/editor.py
index 22a0d7a..e921d49 100644
--- a/pywikibot/editor.py
+++ b/pywikibot/editor.py
@@ -5,8 +5,8 @@
"""
#
-# (C) Gerrit Holl 2004
-# (C) Pywikibot team, 2004-2013
+# (C) Gerrit Holl, 2004
+# (C) Pywikibot team, 2004-2014
#
# Distributed under the terms of the MIT license.
#
diff --git a/pywikibot/families/__init__.py b/pywikibot/families/__init__.py
index 22a940a..5041b19 100644
--- a/pywikibot/families/__init__.py
+++ b/pywikibot/families/__init__.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
-# (C) Pywikipedia bot team, 2007
+# (C) Pywikibot team, 2007
#
# Distributed under the terms of the MIT license.
#
diff --git a/pywikibot/pagegenerators.py b/pywikibot/pagegenerators.py
index aad6df1..247e3e5 100644
--- a/pywikibot/pagegenerators.py
+++ b/pywikibot/pagegenerators.py
@@ -1312,7 +1312,7 @@
displayed in or along with [Google] Services.
Both of those issues should be managed by the package 'google',
- however pywikibot will at least ensure the user sees the TOS
+ however Pywikibot will at least ensure the user sees the TOS
in order to comply with the second condition.
"""
try:
diff --git a/pywikibot/userinterfaces/__init__.py b/pywikibot/userinterfaces/__init__.py
index 22a940a..5041b19 100644
--- a/pywikibot/userinterfaces/__init__.py
+++ b/pywikibot/userinterfaces/__init__.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
-# (C) Pywikipedia bot team, 2007
+# (C) Pywikibot team, 2007
#
# Distributed under the terms of the MIT license.
#
diff --git a/pywikibot/userinterfaces/terminal_interface_win32.py b/pywikibot/userinterfaces/terminal_interface_win32.py
index d6e1d28..098ae80 100755
--- a/pywikibot/userinterfaces/terminal_interface_win32.py
+++ b/pywikibot/userinterfaces/terminal_interface_win32.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
-# (C) Pywikipedia bot team, 2003-2012
+# (C) Pywikibot team, 2003-2013
#
# Distributed under the terms of the MIT license.
#
diff --git a/scripts/blockpageschecker.py b/scripts/blockpageschecker.py
index c026b20..9297349 100755
--- a/scripts/blockpageschecker.py
+++ b/scripts/blockpageschecker.py
@@ -49,7 +49,7 @@
#
# (C) Monobi a.k.a. Wikihermit, 2007
# (C) Filnik, 2007-2011
-# (C) NicDumZ, 2008-2009
+# (C) Nicolas Dumazet (NicDumZ), 2008-2009
# (C) Pywikibot team, 2007-2014
#
# Distributed under the terms of the MIT license.
diff --git a/scripts/capitalize_redirects.py b/scripts/capitalize_redirects.py
index 814d771..35906ff 100644
--- a/scripts/capitalize_redirects.py
+++ b/scripts/capitalize_redirects.py
@@ -18,11 +18,14 @@
Example: "python capitalize_redirects.py -start:B -always"
"""
#
-# (C) Yrithinnd
+# (C) Yrithinnd, 2006
# (C) Pywikibot team, 2007-2014
#
# Distributed under the terms of the MIT license.
#
+# Originally derived from:
+# http://en.wikipedia.org/wiki/User:Drinibot/CapitalizationRedirects
+#
# Automatically converted from compat branch by compat2core.py script
#
__version__ = '$Id$'
diff --git a/scripts/checkimages.py b/scripts/checkimages.py
index 24b3b64..75bff69 100644
--- a/scripts/checkimages.py
+++ b/scripts/checkimages.py
@@ -6,7 +6,7 @@
description.
This script will have to be configured for each language. Please submit
-translations as addition to the pywikibot framework.
+translations as addition to the Pywikibot framework.
Everything that needs customisation is indicated by comments.
diff --git a/scripts/coordinate_import.py b/scripts/coordinate_import.py
index 6407683..1998cf8 100644
--- a/scripts/coordinate_import.py
+++ b/scripts/coordinate_import.py
@@ -17,7 +17,7 @@
¶ms;
"""
#
-# (C) Multichill 2014
+# (C) Multichill, 2014
# (C) Pywikibot team, 2013-2014
#
# Distributed under the terms of MIT License.
diff --git a/scripts/delete.py b/scripts/delete.py
index 8b023ac..3211852 100644
--- a/scripts/delete.py
+++ b/scripts/delete.py
@@ -25,7 +25,7 @@
python delete.py -cat:"To delete" -always
"""
#
-# (c) Pywikibot team, 2014
+# (C) Pywikibot team, 2014
#
# Distributed under the terms of the MIT license.
#
diff --git a/scripts/disambredir.py b/scripts/disambredir.py
index 058e90a..4cbc419 100644
--- a/scripts/disambredir.py
+++ b/scripts/disambredir.py
@@ -11,8 +11,8 @@
"""
#
-# (c) André Engels and others, 2006-2009
-# (c) pywikibot team, 2006-2014
+# (C) André Engels, 2006-2009
+# (C) Pywikibot team, 2006-2014
#
# Distributed under the terms of the MIT license.
#
diff --git a/scripts/editarticle.py b/scripts/editarticle.py
index 37f830a..4208e90 100755
--- a/scripts/editarticle.py
+++ b/scripts/editarticle.py
@@ -10,7 +10,7 @@
- ...
"""
#
-# (C) Gerrit Holl 2004
+# (C) Gerrit Holl, 2004
# (C) Pywikibot team, 2004-2014
#
# Distributed under the terms of the MIT license.
diff --git a/scripts/fixing_redirects.py b/scripts/fixing_redirects.py
index e257da8..0cc37d4 100644
--- a/scripts/fixing_redirects.py
+++ b/scripts/fixing_redirects.py
@@ -16,7 +16,7 @@
#
# This script based on disambredir.py and solve_disambiguation.py
#
-# (C) Pywikipedia team, 2004-2014
+# (C) Pywikibot team, 2004-2014
#
# Distributed under the terms of the MIT license.
#
diff --git a/scripts/illustrate_wikidata.py b/scripts/illustrate_wikidata.py
index a906943..01504de 100644
--- a/scripts/illustrate_wikidata.py
+++ b/scripts/illustrate_wikidata.py
@@ -12,7 +12,7 @@
¶ms;
"""
#
-# (C) Multichill 2014
+# (C) Multichill, 2014
# (C) Pywikibot team, 2013-2014
#
# Distributed under the terms of MIT License.
diff --git a/scripts/imagerecat.py b/scripts/imagerecat.py
index 748985e..9c0d886 100644
--- a/scripts/imagerecat.py
+++ b/scripts/imagerecat.py
@@ -25,8 +25,8 @@
"""
#
-# (C) Multichill 2008-2011
-# (C) Pywikibot team, 2008-2013
+# (C) Multichill, 2008-2011
+# (C) Pywikibot team, 2008-2014
#
# Distributed under the terms of the MIT license.
#
diff --git a/scripts/imageuncat.py b/scripts/imageuncat.py
index 74dc90d..0bcb3d9 100755
--- a/scripts/imageuncat.py
+++ b/scripts/imageuncat.py
@@ -6,7 +6,7 @@
"""
#
-# (C) Multichill 2008
+# (C) Multichill, 2008
# (C) Pywikibot team, 2009-2014
#
# Distributed under the terms of the MIT license.
diff --git a/scripts/maintenance/make_i18n_dict.py b/scripts/maintenance/make_i18n_dict.py
index 3292d11..d23e805 100644
--- a/scripts/maintenance/make_i18n_dict.py
+++ b/scripts/maintenance/make_i18n_dict.py
@@ -17,8 +17,8 @@
>>> bot = i18nBot('<scriptname>.<class instance>', '<msg dict1>', '<msg dict2>')
"""
#
-# (C) xqt 2013-2014
-# (C) Pywikipedia bot team, 2013
+# (C) xqt, 2013-2014
+# (C) Pywikibot team, 2013-2014
#
# Distributed under the terms of the MIT license.
#
diff --git a/scripts/makecat.py b/scripts/makecat.py
index d09a5bf..f005154 100644
--- a/scripts/makecat.py
+++ b/scripts/makecat.py
@@ -33,7 +33,7 @@
"""
# (C) Andre Engels, 2004
-# (C) Pywikibot team 2005-2014
+# (C) Pywikibot team, 2005-2014
#
# Distributed under the terms of the MIT license.
#
diff --git a/scripts/protect.py b/scripts/protect.py
index 2dd0417..d7a55b1 100644
--- a/scripts/protect.py
+++ b/scripts/protect.py
@@ -42,7 +42,7 @@
# Written by https://it.wikisource.org/wiki/Utente:Qualc1
# Created by modifying delete.py
#
-# (c) Pywikibot team, 2008-2014
+# (C) Pywikibot team, 2008-2014
#
# Distributed under the terms of the MIT license.
#
diff --git a/scripts/reflinks.py b/scripts/reflinks.py
index f1fb419..93617bf 100644
--- a/scripts/reflinks.py
+++ b/scripts/reflinks.py
@@ -34,7 +34,7 @@
-summary Use a custom edit summary. Otherwise it uses the default
one from i18n/reflinks.py
"""
-# (C) 2008 - Nicolas Dumazet ( en:User:NicDumZ )
+# (C) Nicolas Dumazet (NicDumZ), 2008
# (C) Pywikibot team, 2008-2014
#
# Distributed under the terms of the GPL
@@ -64,7 +64,7 @@
localized_msg = ('fr', 'it', 'pl') # localized message at MediaWiki
# localized message at specific wikipedia site
-# should be moved to MediaWiki pywikibot manual
+# should be moved to MediaWiki Pywikibot manual
stopPage = {
diff --git a/scripts/replace.py b/scripts/replace.py
index 3ddc0ec..4f1dc75 100755
--- a/scripts/replace.py
+++ b/scripts/replace.py
@@ -115,8 +115,8 @@
Please type "replace.py -help | more" if you can't read the top of the help.
"""
#
-# (C) Daniel Herding & the Pywikipedia team, 2004-2012
-# (C) Pywikibot team, 2009-2014
+# (C) Daniel Herding, 2004-2012
+# (C) Pywikibot team, 2004-2014
#
# Distributed under the terms of the MIT license.
#
diff --git a/scripts/replicate_wiki.py b/scripts/replicate_wiki.py
index 113ab8f..e22aa55 100644
--- a/scripts/replicate_wiki.py
+++ b/scripts/replicate_wiki.py
@@ -22,7 +22,7 @@
liwiki. Note that this does not take the origin wiki into account.
"""
#
-# (C) Kasper Souren 2012-2013
+# (C) Kasper Souren, 2012-2013
# (C) Pywikibot team, 2013-2014
#
# Distributed under the terms of the MIT license.
diff --git a/scripts/spamremove.py b/scripts/spamremove.py
index 60906f1..57c1b53 100755
--- a/scripts/spamremove.py
+++ b/scripts/spamremove.py
@@ -24,7 +24,7 @@
"""
#
-# (C) Pywikipedia bot team, 2007-2014
+# (C) Pywikibot team, 2007-2014
#
# Distributed under the terms of the MIT license.
#
diff --git a/scripts/template.py b/scripts/template.py
index c605d29..80df20b 100755
--- a/scripts/template.py
+++ b/scripts/template.py
@@ -69,12 +69,12 @@
python template.py test -subst -namespace:2 -namespace:3
-Note that -namespace: is a global pywikibot parameter
+Note that -namespace: is a global Pywikibot parameter
This next example substitutes the template lived with a supplied edit summary.
It only performs substitutions in main article namespace and doesn't prompt to
-start replacing. Note that -putthrottle: is a global pywikibot parameter.
+start replacing. Note that -putthrottle: is a global Pywikibot parameter.
python template.py -putthrottle:30 -namespace:0 lived -subst -always
-summary:"BOT: Substituting {{lived}}, see [[WP:SUBST]]."
diff --git a/scripts/templatecount.py b/scripts/templatecount.py
index a3dceb2..cd2aa01 100644
--- a/scripts/templatecount.py
+++ b/scripts/templatecount.py
@@ -30,8 +30,8 @@
"""
#
-# (c) Pywikibot team, 2006-2014
-# (c) xqt, 2009-2014
+# (C) Pywikibot team, 2006-2014
+# (C) xqt, 2009-2014
#
# Distributed under the terms of the MIT license.
#
diff --git a/scripts/transferbot.py b/scripts/transferbot.py
index dcc6144..a9c7965 100644
--- a/scripts/transferbot.py
+++ b/scripts/transferbot.py
@@ -33,7 +33,7 @@
#
# (C) Merlijn van Deen, 2014
-# (C) pywikibot team, 2014
+# (C) Pywikibot team, 2014
#
# Distributed under the terms of the MIT license.
#
diff --git a/scripts/version.py b/scripts/version.py
index 88b0f62..3dc2b2d 100755
--- a/scripts/version.py
+++ b/scripts/version.py
@@ -1,10 +1,10 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
-""" Script to determine the pywikibot version (tag, revision and date) """
+""" Script to determine the Pywikibot version (tag, revision and date) """
#
# (C) Merlijn 'valhallasw' van Deen, 2007-2008
# (C) xqt, 2010-2014
-# (C) Pywikibot team, 2007-2013
+# (C) Pywikibot team, 2007-2014
#
# Distributed under the terms of the MIT license.
#
diff --git a/scripts/welcome.py b/scripts/welcome.py
index 9ea90ea..92bfaf7 100644
--- a/scripts/welcome.py
+++ b/scripts/welcome.py
@@ -939,7 +939,7 @@
elif arg == '-quick':
globalvar.quick = True
- # Filename and pywikibot path
+ # Filename and Pywikibot path
# file where is stored the random signature index
filename = pywikibot.config.datafilepath('welcome-%s-%s.data'
% (pywikibot.Site().family.name,
diff --git a/tests/__init__.py b/tests/__init__.py
index 99fd1da..919064a 100644
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
-# (C) Pywikipedia bot team, 2007
+# (C) Pywikibot team, 2007-2014
#
# Distributed under the terms of the MIT license.
#
diff --git a/tests/api_tests.py b/tests/api_tests.py
index 5faec1f..ef6fedf 100644
--- a/tests/api_tests.py
+++ b/tests/api_tests.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
-# (C) Pywikipedia bot team, 2007
+# (C) Pywikibot team, 2007-2014
#
# Distributed under the terms of the MIT license.
#
diff --git a/tests/i18n_tests.py b/tests/i18n_tests.py
index b349bc7..2d16042 100644
--- a/tests/i18n_tests.py
+++ b/tests/i18n_tests.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
-# (C) Pywikipedia bot team, 2007
+# (C) Pywikibot team, 2007-2014
#
# Distributed under the terms of the MIT license.
#
diff --git a/tests/pwb_tests.py b/tests/pwb_tests.py
index 9f36a0c..c6aaf77 100644
--- a/tests/pwb_tests.py
+++ b/tests/pwb_tests.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
-# (C) Pywikipedia bot team, 2007
+# (C) Pywikibot team, 2007-2014
#
# Distributed under the terms of the MIT license.
#
diff --git a/tests/weblib_tests.py b/tests/weblib_tests.py
index 58a0392..61ccabe 100644
--- a/tests/weblib_tests.py
+++ b/tests/weblib_tests.py
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
-# (C) Pywikipedia bot team, 2014
+# (C) Pywikibot team, 2014
#
# Distributed under the terms of the MIT license.
#
diff --git a/tests/wikidataquery_tests.py b/tests/wikidataquery_tests.py
index 019887e..f1044b8 100644
--- a/tests/wikidataquery_tests.py
+++ b/tests/wikidataquery_tests.py
@@ -3,7 +3,7 @@
Test cases for the WikidataQuery query syntax and API
"""
#
-# (C) Pywikipedia bot team, 2013
+# (C) Pywikibot team, 2014
#
# Distributed under the terms of the MIT license.
#
--
To view, visit https://gerrit.wikimedia.org/r/146405
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I8822e3f978f5113df778d835030f372d3c98e68e
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: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: Pyfisch <pyfisch(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: Remove page.QueryPage
......................................................................
Remove page.QueryPage
QueryPage is not implemented in Wikibase yet, there are no uses of
a stub class in pywikibot, and there is no novel code in this stub
that warrants keeping while we wait for the functionality to exist
in the Wikibase software.
Change-Id: I9bcdb022c7e7e4db2d24327a29531e417c16ce76
---
M pywikibot/page.py
1 file changed, 0 insertions(+), 16 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page.py b/pywikibot/page.py
index d35de4f..5d5114a 100644
--- a/pywikibot/page.py
+++ b/pywikibot/page.py
@@ -3149,22 +3149,6 @@
return Claim(self.site, self.getID(), *args, **kwargs)
-class QueryPage(WikibasePage):
-
- """
- A Wikibase Query entity.
-
- For future usage, not implemented yet.
- """
-
- def __init__(self, site, title):
- """Constructor."""
- WikibasePage.__init__(self, site, title, ns=122)
- self.id = self.title(withNamespace=False).upper()
- if not self.id.startswith(u'U'):
- raise ValueError(u"'%s' is not a query page!" % self.title())
-
-
class Claim(Property):
"""
--
To view, visit https://gerrit.wikimedia.org/r/154014
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I9bcdb022c7e7e4db2d24327a29531e417c16ce76
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ladsgroup <ladsgroup(a)gmail.com>
Gerrit-Reviewer: Merlijn van Deen <valhallasw(a)arctus.nl>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: Ignore warnings due to family codenames with dots
......................................................................
Ignore warnings due to family codenames with dots
PyWikiBot works perfectly when family names have dots in them, however it still
shows a warning. This patch avoids that warning.
Change-Id: I18ab14a490186782c68bdddf6e7fb41bdaef4775
---
M pywikibot/site.py
1 file changed, 5 insertions(+), 1 deletion(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/site.py b/pywikibot/site.py
index 16415fb..24898eb 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -108,7 +108,11 @@
return _families[fam]
try:
- myfamily = imp.load_source(fam, config.family_files[fam])
+ # Ignore warnings due to dots in family names.
+ import warnings
+ with warnings.catch_warnings():
+ warnings.simplefilter("ignore", RuntimeWarning)
+ myfamily = imp.load_source(fam, config.family_files[fam])
except (ImportError, KeyError):
if fatal:
pywikibot.error(u"""\
--
To view, visit https://gerrit.wikimedia.org/r/153563
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I18ab14a490186782c68bdddf6e7fb41bdaef4775
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Gallaecio <adriyetichaves(a)gmail.com>
Gerrit-Reviewer: Gallaecio <adriyetichaves(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: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot <>
jenkins-bot has submitted this change and it was merged.
Change subject: Bug 68658-imagerecat fails to process pages
......................................................................
Bug 68658-imagerecat fails to process pages
Fix: replaced page.site() with page.site.
In addition to bug fixing, also changed:
- page.get() to page.text
- page.put() to page.save()
Change-Id: Ie2b579e640b8e116fd107d5727b07dac16e93280
---
M scripts/imagerecat.py
1 file changed, 5 insertions(+), 4 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/imagerecat.py b/scripts/imagerecat.py
index 748985e..a2a76e6 100644
--- a/scripts/imagerecat.py
+++ b/scripts/imagerecat.py
@@ -76,7 +76,7 @@
for page in generator:
if page.exists() and (page.namespace() == 6) and \
(not page.isRedirectPage()):
- imagepage = pywikibot.ImagePage(page.site(), page.title())
+ imagepage = pywikibot.ImagePage(page.site, page.title())
pywikibot.output(u'Working on ' + imagepage.title())
if onlyUncat and not(u'Uncategorized' in imagepage.templates()):
@@ -390,7 +390,7 @@
def saveImagePage(imagepage, newcats, usage, galleries, onlyFilter):
""" Remove the old categories and add the new categories to the image. """
- newtext = pywikibot.removeCategoryLinks(imagepage.get(), imagepage.site())
+ newtext = pywikibot.removeCategoryLinks(imagepage.text, imagepage.site)
if not onlyFilter:
newtext = removeTemplates(newtext)
newtext = newtext + getCheckCategoriesTemplate(usage, galleries,
@@ -402,8 +402,9 @@
comment = u'Filtering categories'
else:
comment = u'Image is categorized by a bot using data from [[Commons:Tools#CommonSense|CommonSense]]'
- pywikibot.showDiff(imagepage.get(), newtext)
- imagepage.put(newtext, comment)
+ pywikibot.showDiff(imagepage.text, newtext)
+ imagepage.text = newtext
+ imagepage.save(comment)
return
--
To view, visit https://gerrit.wikimedia.org/r/153720
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ie2b579e640b8e116fd107d5727b07dac16e93280
Gerrit-PatchSet: 3
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Mpaa <mpaa.wiki(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: Bug 69315 - cs timestamp not supported (II)
......................................................................
Bug 69315 - cs timestamp not supported (II)
New fix for bug in cs wiki.
If months are expressed as digits, regex expression for months
needs to used \d{1,2} and not the names as strings.
This ensure proper match of digits.
In such cases, it is assumed that date is expressed as dd. mm.
When only two occurrences of month (cnt=2), leave them to allow
to search for dd. mm. pattern.
Change-Id: Ic8549b2d5502fca86b3bb87e92001949f78720b0
---
M pywikibot/textlib.py
1 file changed, 20 insertions(+), 8 deletions(-)
Approvals:
John Vandenberg: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/textlib.py b/pywikibot/textlib.py
index 0b56f68..c6997a1 100644
--- a/pywikibot/textlib.py
+++ b/pywikibot/textlib.py
@@ -1191,10 +1191,21 @@
timeR = r'(?P<time>(?P<hour>[0-2]\d)[:\.h](?P<minute>[0-5]\d))'
timeznR = r'\((?P<tzinfo>[A-Z]+)\)'
yearR = r'(?P<year>(19|20)\d\d)'
- # if months name contain a dot, it needs to be escaped.
- escaped_months = [re.escape(_) for _ in self.origNames2monthNum]
- monthR = r'(?P<month>(%s))' % u'|'.join(escaped_months)
- dayR = r'(?P<day>(3[01]|[12]\d|0?[1-9]))\.?'
+
+ # if months have 'digits' as names, they need to be
+ # removed; will be handled as digits in regex, adding d+{1,2}\.?
+ escaped_months = [_ for _ in self.origNames2monthNum if
+ not _.strip('.').isdigit()]
+ escaped_months = [re.escape(_) for _ in escaped_months]
+
+ # work around for cs wiki: if month are in digits, we assume
+ # that format is dd. mm. (with dot and spaces optional)
+ if any(_.isdigit() for _ in self.origNames2monthNum):
+ monthR = r'(?P<month>(%s)|\d{1,2}\.?)' % u'|'.join(escaped_months)
+ dayR = r'(?P<day>(3[01]|[12]\d|0?[1-9]))\.?\s*[01]?\d\.?'
+ else:
+ monthR = r'(?P<month>(%s))' % u'|'.join(escaped_months)
+ dayR = r'(?P<day>(3[01]|[12]\d|0?[1-9]))\.?'
self.ptimeR = re.compile(timeR)
self.ptimeznR = re.compile(timeznR)
@@ -1230,11 +1241,11 @@
marker = self.findmarker(txt)
# month and day format might be identical (e.g. see bug 69315),
# avoid to wipe out day, after month is matched.
- # replace all matches but the one before last, which is the day candidate.
+ # replace all matches but the last two
+ # (i.e. allow to search for dd. mm.)
if pat == self.pmonthR:
- txt = pat.sub(marker, txt, cnt - 2)
- # matched month needs to be wiped out (last match of txt)
- txt = re.sub(r'(.*)%s' % m.group(), r'\1%s' % marker, txt)
+ if cnt > 2:
+ txt = pat.sub(marker, txt, cnt - 2)
else:
txt = pat.sub(marker, txt)
return (txt, m.groupdict())
@@ -1254,6 +1265,7 @@
line, matchDict = self.last_match_and_replace(line, pat)
if matchDict:
dateDict.update(matchDict)
+
# all fields matched -> date valid
if all(g in dateDict for g in self.groups):
# remove 'time' key, now splitted in hour/minute and not needed by datetime
--
To view, visit https://gerrit.wikimedia.org/r/153834
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ic8549b2d5502fca86b3bb87e92001949f78720b0
Gerrit-PatchSet: 3
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: Mpaa <mpaa.wiki(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: Mpaa <mpaa.wiki(a)gmail.com>
Gerrit-Reviewer: jenkins-bot <>