diff options
author | Simo Sorce <simo@redhat.com> | 2015-10-01 21:35:28 -0400 |
---|---|---|
committer | Simo Sorce <simo@redhat.com> | 2015-10-19 12:16:59 -0400 |
commit | a008bef50939383c33fa81d7e939908729b27876 (patch) | |
tree | 5a3a97633f30179364c9ca3bb635d832fc2622dd | |
parent | 5fceed2d9be1001fc486d801e0a0f923d8dd3159 (diff) | |
download | custodia-a008bef50939383c33fa81d7e939908729b27876.tar.gz custodia-a008bef50939383c33fa81d7e939908729b27876.tar.xz custodia-a008bef50939383c33fa81d7e939908729b27876.zip |
Fix traceback support in python 3.4
Signed-off-by: Simo Sorce <simo@redhat.com>
Reviewed-by: Christian Heimes <cheimes@redhat.com>
-rw-r--r-- | custodia/log.py | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/custodia/log.py b/custodia/log.py index a04288d..ff71137 100644 --- a/custodia/log.py +++ b/custodia/log.py @@ -1,20 +1,27 @@ # Copyright (C) 2015 Custodia Project Contributors - see LICENSE file -import io import sys import time import traceback +try: + from StringIO import StringIO +except ImportError: + from io import StringIO DEBUG = False def stacktrace(): - with io.BytesIO() as f: - _, _, tb = sys.exc_info() + _, _, tb = sys.exc_info() + if tb is None: + return None + try: + f = StringIO() traceback.print_tb(tb, None, file=f) - del tb return f.getvalue() + finally: + del tb def get_time(): @@ -32,7 +39,9 @@ def error(msg, head=None): def debug(msg): if DEBUG: error(msg, 'DEBUG') - sys.stderr.write(stacktrace()) + trace = stacktrace() + if trace is not None: + sys.stderr.write(trace + '\n') AUDIT_NONE = 0 |