jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/462006 )
Change subject: [IMPR] Enable start timestamp for EventStreams
......................................................................
[IMPR] Enable start timestamp for EventStreams
Bug: T205121
Change-Id: Iec1a912ad44f3cf5e1732aee92629ef64a351709
---
M pywikibot/comms/eventstreams.py
1 file changed, 26 insertions(+), 5 deletions(-)
Approvals:
Framawiki: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/comms/eventstreams.py b/pywikibot/comms/eventstreams.py
index 7824e5b..39983f6 100644
--- a/pywikibot/comms/eventstreams.py
+++ b/pywikibot/comms/eventstreams.py
@@ -29,7 +29,7 @@
except ImportError as e:
EventSource = e
-from pywikibot import config, debug, Site, warning
+from pywikibot import config, debug, Timestamp, Site, warning
from pywikibot.tools import deprecated_args, StringTypes
# requests >= 2.9 is required for eventstreams (T184713)
@@ -81,6 +81,11 @@
@keyword site: a project site object. Used when no url is given
@type site: APISite
+ @keyword since: a timestamp for older events; there will likely be
+ between 7 and 31 days of history available but is not guaranteed.
+ It may be given as a pywikibot.Timestamp, an ISO 8601 string
+ or a mediawiki timestamp string.
+ @type since: pywikibot.Timestamp or str
@keyword streams: event stream types. Mandatory when no url is given.
Multiple streams may be given as a string with comma separated
stream types or an iterable of strings
@@ -91,7 +96,7 @@
data before giving up
@type timeout: int, float or a tuple of two values of int or float
@keyword url: an url retrieving events from. Will be set up to a
- default url using _site.family settings and stream types
+ default url using _site.family settings, stream types and timestamp
@type url: str
@param kwargs: keyword arguments passed to SSEClient and requests lib
@raises ImportError: sseclient is not installed
@@ -103,9 +108,20 @@
self.filter = {'all': [], 'any': [], 'none': []}
self._total = None
self._site = kwargs.pop('site', Site())
+
self._streams = kwargs.pop('streams', None)
if self._streams and not isinstance(self._streams, StringTypes):
self._streams = ','.join(self._streams)
+
+ self._since = kwargs.pop('since', None)
+ if self._since:
+ # assume this is a mw timestamp, convert it to a Timestamp object
+ if isinstance(self._streams, StringTypes) \
+ and '-' not in self._since:
+ self._since = Timestamp.fromtimestampformat(self._since)
+ if isinstance(self._streams, Timestamp):
+ self._since = self._since.isoformat
+
self._url = kwargs.get('url') or self.url
kwargs.setdefault('url', self._url)
kwargs.setdefault('timeout', config.socket_timeout)
@@ -119,6 +135,8 @@
if self._streams:
kwargs['streams'] = self._streams
kwargs.pop('url')
+ if self._since:
+ kwargs['since'] = self._since
if kwargs['timeout'] == config.socket_timeout:
kwargs.pop('timeout')
return '{0}({1})'.format(self.__class__.__name__, ', '.join(
@@ -135,9 +153,12 @@
raise NotImplementedError(
'No streams specified for class {0}'
.format(self.__class__.__name__))
- self._url = ('{0}{1}/{2}'.format(self._site.eventstreams_host(),
- self._site.eventstreams_path(),
- self._streams))
+ self._url = ('{host}{path}/{streams}{since}'
+ .format(host=self._site.eventstreams_host(),
+ path=self._site.eventstreams_path(),
+ streams=self._streams,
+ since=('?since=' + self._since)
+ if self._since else ''))
return self._url
def set_maximum_items(self, value):
--
To view, visit https://gerrit.wikimedia.org/r/462006
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Iec1a912ad44f3cf5e1732aee92629ef64a351709
Gerrit-Change-Number: 462006
Gerrit-PatchSet: 3
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Framawiki <framawiki(a)tools.wmflabs.org>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Ottomata <aotto(a)wikimedia.org>
Gerrit-Reviewer: jenkins-bot (75)
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/462205 )
Change subject: [cleanup] cleanup category.py
......................................................................
[cleanup] cleanup category.py
- remove preleading "u" from strings
- use single quotes for string constants
- keep lines beneath 80 chars
- use str.format() instead of modulo operator for changed lines
Change-Id: I75587eede55fc487ce5adc94c325e22504da3363
---
M scripts/category.py
1 file changed, 42 insertions(+), 44 deletions(-)
Approvals:
Framawiki: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/category.py b/scripts/category.py
index cc1cbc4..6443dca 100755
--- a/scripts/category.py
+++ b/scripts/category.py
@@ -159,17 +159,17 @@
'wikipedia': {
'cs': ['přesunout', 'přejmenovat', 'přejmenovat kategorii',
'přesunout kategorii', 'přejmenování kategorie'],
- 'en': [u'cfd', u'cfr', u'cfru', u'cfr-speedy', u'cfm', u'cfdu'],
- 'fi': [u'roskaa', u'poistettava', u'korjattava/nimi',
- u'yhdistettäväLuokka'],
+ 'en': ['cfd', 'cfr', 'cfru', 'cfr-speedy', 'cfm', 'cfdu'],
+ 'fi': ['roskaa', 'poistettava', 'korjattava/nimi',
+ 'yhdistettäväLuokka'],
'fr': ['renommage de catégorie demandé'],
- 'he': [u'הצבעת מחיקה', u'למחוק'],
- 'nl': [u'categorieweg', u'catweg', u'wegcat', u'weg2'],
+ 'he': ['הצבעת מחיקה', 'למחוק'],
+ 'nl': ['categorieweg', 'catweg', 'wegcat', 'weg2'],
# For testing purposes
- 'test': [u'delete']
+ 'test': ['delete']
},
'commons': {
- 'commons': [u'cfd', u'move']
+ 'commons': ['cfd', 'move']
}
}
@@ -379,8 +379,8 @@
elif not os.path.isabs(filename):
filename = config.datafilepath(filename)
if self.is_loaded and (self.catContentDB or self.superclassDB):
- pywikibot.output(u'Dumping to %s, please wait...'
- % config.shortpath(filename))
+ pywikibot.output('Dumping to {}, please wait...'
+ .format(config.shortpath(filename)))
databases = {
'catContentDB': self.catContentDB,
'superclassDB': self.superclassDB
@@ -397,8 +397,8 @@
except EnvironmentError:
pass
else:
- pywikibot.output(u'Database is empty. %s removed'
- % config.shortpath(filename))
+ pywikibot.output('Database is empty. {} removed'
+ .format(config.shortpath(filename)))
class CategoryAddBot(MultipleSitesBot, CategoryPreprocess):
@@ -462,13 +462,13 @@
old_text = text
cats = textlib.getCategoryLinks(
text, self.current_page.site, include=self.includeonly)
- pywikibot.output(u"Current categories:")
+ pywikibot.output('Current categories:')
for cat in cats:
- pywikibot.output(u"* %s" % cat.title())
+ pywikibot.output('* ' + cat.title())
catpl = pywikibot.Category(self.current_page.site, self.newcat)
if catpl in cats:
- pywikibot.output(u"%s is already in %s."
- % (self.current_page.title(), catpl.title()))
+ pywikibot.output('{} is already in {}.'
+ .format(self.current_page.title(), catpl.title()))
else:
if self.sort:
catpl = self.sorted_by_last_name(catpl, self.current_page)
@@ -509,9 +509,9 @@
self.userPut(self.current_page, old_text, text,
summary=comment)
except pywikibot.PageSaveRelatedError as error:
- pywikibot.output(u'Page %s not saved: %s'
- % (self.current_page.title(as_link=True),
- error))
+ pywikibot.output('Page {} not saved: {}'
+ .format(self.current_page.title(as_link=True),
+ error))
class CategoryMoveRobot(CategoryPreprocess):
@@ -755,15 +755,15 @@
"""Return if the old page can be safely moved to the new page."""
move_possible = True
if new_page and new_page.exists():
- pywikibot.warning(u"The {0} target '{1}' already "
- u"exists.".format(name, new_page.title()))
+ pywikibot.warning("The {0} target '{1}' already exists."
+ .format(name, new_page.title()))
move_possible = False
if not old_page.exists():
# only warn if not a talk page
log = (pywikibot.log if old_page.namespace() % 2 else
pywikibot.warning)
- log(u"Moving {0} '{1}' requested, but the page doesn't "
- u"exist.".format(name, old_page.title()))
+ log("Moving {0} '{1}' requested, but the page doesn't exist."
+ .format(name, old_page.title()))
move_possible = False
return move_possible
@@ -804,7 +804,7 @@
# 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)
+ 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()
@@ -851,8 +851,8 @@
history = self.oldcat.getVersionHistoryTable()
title = i18n.twtranslate(self.site, 'category-section-title',
{'oldcat': self.oldcat.title()})
- self.newtalk.text = "%s\n== %s ==\n%s" % (self.newtalk.text,
- title, history)
+ self.newtalk.text = '{}\n== {} ==\n{}'.format(self.newtalk.text,
+ title, history)
comment = i18n.twtranslate(self.site, 'category-version-history',
{'oldcat': self.oldcat.title()})
self.newtalk.save(comment)
@@ -936,18 +936,16 @@
if (not article.is_filepage() or
self.showImages) and not article.is_categorypage():
if self.talkPages and not article.isTalkPage():
- listString += "*[[%s]] -- [[%s|talk]]\n" \
- % (article.title(),
- article.toggleTalkPage().title())
+ listString += '* [[{0}]] -- [[{1}|talk]]\n'.format(
+ article.title(), article.toggleTalkPage().title())
else:
- listString += "*[[%s]]\n" % article.title()
+ listString += '* [[{0}]]\n'.format(article.title())
else:
if self.talkPages and not article.isTalkPage():
- listString += "*[[:%s]] -- [[%s|talk]]\n" \
- % (article.title(),
- article.toggleTalkPage().title())
+ listString += '* [[:{0}]] -- [[{1}|talk]]\n'.format(
+ article.title(), article.toggleTalkPage().title())
else:
- listString += "*[[:%s]]\n" % article.title()
+ listString += '* [[:{0}]]\n'.format(article.title())
if self.list.exists():
if self.append:
# append content by default at the bottom
@@ -1275,9 +1273,9 @@
* parent - the Category of the category we're coming from
"""
- result = u'#' * currentDepth
+ result = '#' * currentDepth
if currentDepth > 0:
- result += u' '
+ result += ' '
result += cat.title(as_link=True, textlink=True, with_ns=False)
result += ' (%d)' % cat.categoryinfo['pages']
if currentDepth < self.maxDepth // 2:
@@ -1319,7 +1317,7 @@
tree = self.treeview(cat)
pywikibot.output(u'')
if self.filename:
- pywikibot.output(u'Saving results in %s' % self.filename)
+ pywikibot.output('Saving results in ' + self.filename)
with codecs.open(self.filename, 'a', 'utf-8') as f:
f.write(tree)
else:
@@ -1445,7 +1443,7 @@
if action == 'add':
if not to_given:
new_cat_title = pywikibot.input(
- u'Category to add (do not give namespace):')
+ 'Category to add (do not give namespace):')
if not gen:
# default for backwards compatibility
gen_factory.handleArg('-links')
@@ -1475,10 +1473,10 @@
elif action == 'move':
if not from_given:
old_cat_title = pywikibot.input(
- u'Please enter the old name of the category:')
+ 'Please enter the old name of the category:')
if not to_given:
new_cat_title = pywikibot.input(
- u'Please enter the new name of the category:')
+ 'Please enter the new name of the category:')
if use_deletion_summary:
deletion_comment = CategoryMoveRobot.DELETION_COMMENT_SAME_AS_EDIT_COMMENT
else:
@@ -1503,7 +1501,7 @@
summary)
elif action == 'tree':
catTitle = pywikibot.input(
- u'For which category do you want to create a tree view?')
+ 'For which category do you want to create a tree view?')
filename = pywikibot.input(
'Please enter the name of the file where the tree should be saved,'
'\nor press enter to simply show the tree:')
@@ -1511,10 +1509,10 @@
elif action == 'listify':
if not from_given:
old_cat_title = pywikibot.input(
- u'Please enter the name of the category to listify:')
+ 'Please enter the name of the category to listify:')
if not to_given:
new_cat_title = pywikibot.input(
- u'Please enter the name of the list to create:')
+ 'Please enter the name of the list to create:')
bot = CategoryListifyRobot(old_cat_title, new_cat_title, summary,
append, overwrite, showimages, subCats=True,
talkPages=talkpages, recurse=recurse)
@@ -1525,7 +1523,7 @@
try:
bot.run()
except pywikibot.Error:
- pywikibot.error("Fatal error:", exc_info=True)
+ pywikibot.error('Fatal error:', exc_info=True)
finally:
if cat_db:
cat_db.dump()
@@ -1535,7 +1533,7 @@
return False
-if __name__ == "__main__":
+if __name__ == '__main__':
main()
wrapper = ModuleDeprecationWrapper(__name__)
--
To view, visit https://gerrit.wikimedia.org/r/462205
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I75587eede55fc487ce5adc94c325e22504da3363
Gerrit-Change-Number: 462205
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Framawiki <framawiki(a)tools.wmflabs.org>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: Xqt <info(a)gno.de>
Gerrit-Reviewer: jenkins-bot (75)
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/462128 )
Change subject: [bugfix] re-enable notifications
......................................................................
[bugfix] re-enable notifications
- "text" value for notformat parameter is no longer available and there is
not hint when this was dropped. Use 'special' instead.
- "format" keyword may also be None which does not return the content values.
- "prop" parameter is "list" by default.
Bug: T205184
Change-Id: Id05ee852b6f8ce0ad5aeb842f9d5a1f8e033b7e3
---
M pywikibot/site.py
1 file changed, 12 insertions(+), 5 deletions(-)
Approvals:
Framawiki: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/site.py b/pywikibot/site.py
index c4a97e5..dea582c 100644
--- a/pywikibot/site.py
+++ b/pywikibot/site.py
@@ -2321,16 +2321,23 @@
@need_extension('Echo')
def notifications(self, **kwargs):
- """Yield Notification objects from the Echo extension."""
+ """Yield Notification objects from the Echo extension.
+
+ keyword format: If specified, notifications will be returned formatted
+ this way. Its value is either 'model', 'special' or None. Default
+ is 'special'.
+ type format: str or None
+
+ Refer API reference for other keywords.
+ """
params = {
'action': 'query',
'meta': 'notifications',
- 'notprop': 'list',
- 'notformat': 'text',
+ 'notformat': 'special',
}
- for key in kwargs:
- params['not' + key] = kwargs[key]
+ for key, value in kwargs.items():
+ params['not' + key] = value
data = self._simple_request(**params).submit()
notifications = data['query']['notifications']['list']
--
To view, visit https://gerrit.wikimedia.org/r/462128
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Id05ee852b6f8ce0ad5aeb842f9d5a1f8e033b7e3
Gerrit-Change-Number: 462128
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Framawiki <framawiki(a)tools.wmflabs.org>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: jenkins-bot (75)
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/462142 )
Change subject: [cleanup] Always show deprecation warning for -dry option in basic.py
......................................................................
[cleanup] Always show deprecation warning for -dry option in basic.py
- DeprecationWarning is hidden by default.
Show FutureWarning instead which is intended for end users
https://docs.python.org/3/library/exceptions.html#FutureWarning
Bug: T205190
Change-Id: I426d3caef2837f9cb3de1006d1da5b33e9f34e50
---
M scripts/basic.py
1 file changed, 1 insertion(+), 0 deletions(-)
Approvals:
Framawiki: Looks good to me, approved
jenkins-bot: Verified
diff --git a/scripts/basic.py b/scripts/basic.py
index 71d14fe..e5cd63d 100755
--- a/scripts/basic.py
+++ b/scripts/basic.py
@@ -114,6 +114,7 @@
if 'dry' in kwargs:
issue_deprecation_warning('dry argument',
'pywikibot.config.simulate', 1,
+ warning_class=FutureWarning,
since='20160124')
# use simulate variable instead
pywikibot.config.simulate = True
--
To view, visit https://gerrit.wikimedia.org/r/462142
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I426d3caef2837f9cb3de1006d1da5b33e9f34e50
Gerrit-Change-Number: 462142
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Framawiki <framawiki(a)tools.wmflabs.org>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: jenkins-bot (75)
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/462138 )
Change subject: Use FutureWarning for warnings intended for end users
......................................................................
Use FutureWarning for warnings intended for end users
- this could replace some important deprecation warnings
which aren't shown by default
- show FutureWarnings only once
- as first FutureWarning use dropping warning fpr Python 2.7.2/3
Bug: T191192
Change-Id: I79a375e9bc8754a79cd68b04c48353f74cd3f90d
---
M pywikibot/__init__.py
M pywikibot/bot.py
2 files changed, 2 insertions(+), 1 deletion(-)
Approvals:
Framawiki: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/__init__.py b/pywikibot/__init__.py
index 76fa14c..c9230c0 100644
--- a/pywikibot/__init__.py
+++ b/pywikibot/__init__.py
@@ -137,7 +137,7 @@
warn(
'Pywikibot will soon drop support for Python 2.7.2 and 2.7.3, '
'please update your Python.',
- DeprecationWarning,
+ FutureWarning,
)
diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index 9721ded..4c4d95b 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -312,6 +312,7 @@
warnings.filterwarnings("always")
elif config.verbose_output:
warnings.filterwarnings("module")
+ warnings.filterwarnings('once', category=FutureWarning)
root_logger.handlers = [] # remove any old handlers
--
To view, visit https://gerrit.wikimedia.org/r/462138
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I79a375e9bc8754a79cd68b04c48353f74cd3f90d
Gerrit-Change-Number: 462138
Gerrit-PatchSet: 2
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Framawiki <framawiki(a)tools.wmflabs.org>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: jenkins-bot (75)
jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/462162 )
Change subject: [cleanup] Remove maxint error message
......................................................................
[cleanup] Remove maxint error message
BaseBot._treat_counter does never exceed maxint limit because
Python 2 yield plain integers unless the value is too large to
be represented as a plain integer, in which case it yield a
long integer. Therefore remove that error message.
Change-Id: Ic974854c9d31201c58668f9a454f500aa32cffb9
---
M pywikibot/bot.py
1 file changed, 1 insertion(+), 10 deletions(-)
Approvals:
Framawiki: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/bot.py b/pywikibot/bot.py
index 9721ded..68fdd5d 100644
--- a/pywikibot/bot.py
+++ b/pywikibot/bot.py
@@ -1466,13 +1466,11 @@
raise NotImplementedError('Variable %s.generator not set.'
% self.__class__.__name__)
- maxint = 0
if PY2:
- maxint = sys.maxint
-
# Python 2 does not clear previous exceptions and method `exit`
# relies on sys.exc_info returning exceptions occurring in `run`.
sys.exc_clear()
+
self.setup()
try:
for item in self.generator:
@@ -1504,14 +1502,7 @@
# Process the page
self.treat(page)
-
self._treat_counter += 1
- if maxint and self._treat_counter == maxint:
- # Warn the user that the bot may not function correctly
- pywikibot.error(
- '\n%s: page count reached Python 2 sys.maxint (%d).\n'
- 'Python 3 should be used to process very large batches'
- % (self.__class__.__name__, sys.maxint))
else:
self._generator_completed = True
except GeneratorExit:
--
To view, visit https://gerrit.wikimedia.org/r/462162
To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Ic974854c9d31201c58668f9a454f500aa32cffb9
Gerrit-Change-Number: 462162
Gerrit-PatchSet: 1
Gerrit-Owner: Xqt <info(a)gno.de>
Gerrit-Reviewer: Framawiki <framawiki(a)tools.wmflabs.org>
Gerrit-Reviewer: John Vandenberg <jayvdb(a)gmail.com>
Gerrit-Reviewer: jenkins-bot (75)