http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10763
Revision: 10763 Author: drtrigon Date: 2012-12-02 19:54:40 +0000 (Sun, 02 Dec 2012) Log Message: ----------- follow-up; to r10761 in order to unlink the code from DrTrigonBot framework (dtbext)
Modified Paths: -------------- trunk/pywikipedia/pywikibot/exceptions.py trunk/pywikipedia/subster.py
Modified: trunk/pywikipedia/pywikibot/exceptions.py =================================================================== --- trunk/pywikipedia/pywikibot/exceptions.py 2012-12-02 19:23:51 UTC (rev 10762) +++ trunk/pywikipedia/pywikibot/exceptions.py 2012-12-02 19:54:40 UTC (rev 10763) @@ -10,6 +10,10 @@ __version__ = '$Id$'
+# Standard library imports +import traceback, StringIO + +# Application specific imports import config
# TODO: not certain that all of them will be needed. @@ -120,3 +124,17 @@ """ class UserActionRefuse(Error): pass + + +# @remarks need for Bot Error Handling; get the error tracebacks without +# raising the error +def gettraceback(exc_info): + output = StringIO.StringIO() + traceback.print_exception(exc_info[0], exc_info[1], exc_info[2], file=output) + + exception_only = traceback.format_exception_only(exc_info[0], exc_info[1]) + + result = output.getvalue() + output.close() + + return (exception_only, result)
Modified: trunk/pywikipedia/subster.py =================================================================== --- trunk/pywikipedia/subster.py 2012-12-02 19:23:51 UTC (rev 10762) +++ trunk/pywikipedia/subster.py 2012-12-02 19:54:40 UTC (rev 10763) @@ -55,7 +55,6 @@ import ast
import pagegenerators, basic -import dtbext # Splitting the bot into library parts import wikipedia as pywikibot from pywikibot import i18n @@ -240,7 +239,7 @@ substed_tags += tags except: exc_info = sys.exc_info() - (exception_only, result) = dtbext.pywikibot.gettraceback(exc_info) + (exception_only, result) = pywikibot.gettraceback(exc_info) substed_content += ast.literal_eval(self._param_default['error']) %\ {'error': bot_config['ErrorTemplate'] %\ ( pywikibot.Timestamp.now().isoformat(' '), @@ -257,7 +256,7 @@ substed_tags += tags except: exc_info = sys.exc_info() - (exception_only, result) = dtbext.pywikibot.gettraceback(exc_info) + (exception_only, result) = pywikibot.gettraceback(exc_info) substed_content += ast.literal_eval(item['error']) %\ {'error': bot_config['ErrorTemplate'] %\ ( item['value'], @@ -336,9 +335,9 @@ return (content, substed_tags) if param['wiki']: if ast.literal_eval(param['expandtemplates']): # DRTRIGON-93 (only with 'wiki') - external_buffer = dtbext.pywikibot.Page(self.site, param['url']).get(expandtemplates=True) + external_buffer = pywikibot.Page(self.site, param['url']).get(expandtemplates=True) else: - external_buffer = self.load( dtbext.pywikibot.Page(self.site, param['url']) ) + external_buffer = self.load( pywikibot.Page(self.site, param['url']) ) elif (param['url'][:7] == u'mail://'): # DRTRIGON-101 param['url'] = param['url'].replace(u'{{@}}', u'@') # e.g. nlwiki mbox = SubsterMailbox(pywikibot.config.datafilepath(bot_config['data_path'], bot_config['mbox_file'], ''))