http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10918
Revision: 10918 Author: saper Date: 2013-01-14 10:53:12 +0000 (Mon, 14 Jan 2013) Log Message: ----------- Logging changes broke pywikipedia on 2.5
Fancy logging made pywikipedia to stop working on Python 2.5.
Workarounds applied using exceptions.
Modified Paths: -------------- trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/wikipedia.py =================================================================== --- trunk/pywikipedia/wikipedia.py 2013-01-14 10:43:29 UTC (rev 10917) +++ trunk/pywikipedia/wikipedia.py 2013-01-14 10:53:12 UTC (rev 10918) @@ -8713,18 +8713,30 @@ backupCount=config.logfilecount, encoding='utf-8') else: - fh = logging.handlers.TimedRotatingFileHandler(logfn, + try: + fh = logging.handlers.TimedRotatingFileHandler(logfn, when='midnight', utc=False, #encoding='bz2-codec') encoding='utf-8') + except TypeError: + # For Python 2.5 + fh = logging.handlers.TimedRotatingFileHandler(logfn, + when='midnight', + #encoding='bz2-codec') + encoding='utf-8') # patch for "Issue 8117: TimedRotatingFileHandler doesn't rotate log # file at startup." # applies to python2.6 only, solution filched from python2.7 source: # http://hg.python.org/cpython-fullhistory/diff/a566e53f106d/Lib/logging/handl... if os.path.exists(logfn): t = os.stat(logfn).st_mtime - fh.rolloverAt = fh.computeRollover(t) + try: + fh.rolloverAt = fh.computeRollover(t) + except AttributeError: + # Python 2.5 does not have it + pass + fh.setLevel(logging.DEBUG if debug else logging.INFO) # create console handler with a higher log level ch = logging.StreamHandler()
pywikipedia-svn@lists.wikimedia.org