TTYUI: Fix python 2.6 compatibility

We were using super() on a class derived from logging.Formatter() which
worked fine in python 2.7. Apparently python 2.6 uses old-style classes
for this, so the TTYUI broke and crashed OfflineImap. This was
introduced in OLI 6.5.0, I think.

Fix it by calling logging.Formatter.... directly, rather than the
elegant super() (which I happen to like a lot more than is appropriate
in the python world).

Reported by Nik Reiman as github issue 23, should fix that issue.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
This commit is contained in:
Sebastian Spaeth 2012-01-18 00:39:04 +01:00
parent 73b2b01dfa
commit 344b2f0b7a
2 changed files with 6 additions and 2 deletions

View File

@ -20,3 +20,5 @@ Changes
Bug Fixes
---------
* Fix python2.6 compatibility with the TTYUI backend (crash)

View File

@ -24,12 +24,14 @@ from offlineimap.ui.UIBase import UIBase
class TTYFormatter(logging.Formatter):
"""Specific Formatter that adds thread information to the log output"""
def __init__(self, *args, **kwargs):
super(TTYFormatter, self).__init__(*args, **kwargs)
#super() doesn't work in py2.6 as 'logging' uses old-style class
logging.Formatter.__init__(self, *args, **kwargs)
self._last_log_thread = None
def format(self, record):
"""Override format to add thread information"""
log_str = super(TTYFormatter, self).format(record)
#super() doesn't work in py2.6 as 'logging' uses old-style class
log_str = logging.Formatter.format(self, record)
# If msg comes from a different thread than our last, prepend
# thread info. Most look like 'Account sync foo' or 'Folder
# sync foo'.