new getBacktrace() function
This commit is contained in:
parent
cdfc6882f9
commit
c77acdbef4
1 changed files with 22 additions and 0 deletions
|
|
@ -18,8 +18,14 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|||
|
||||
"""
|
||||
|
||||
import sys
|
||||
import traceback
|
||||
from dateutil import tz
|
||||
|
||||
|
||||
__all__ = ['toUnicode', 'local2utc', 'html2text', 'getBacktrace']
|
||||
|
||||
|
||||
def toUnicode(text):
|
||||
r"""
|
||||
>>> toUnicode('ascii')
|
||||
|
|
@ -52,3 +58,19 @@ try:
|
|||
except ImportError:
|
||||
def html2text(s):
|
||||
return s
|
||||
|
||||
def getBacktrace(empty="Empty backtrace."):
|
||||
"""
|
||||
Try to get backtrace as string.
|
||||
Returns "Error while trying to get backtrace" on failure.
|
||||
"""
|
||||
try:
|
||||
info = sys.exc_info()
|
||||
trace = traceback.format_exception(*info)
|
||||
sys.exc_clear()
|
||||
if trace[0] != "None\n":
|
||||
return "".join(trace)
|
||||
except:
|
||||
# No i18n here (imagine if i18n function calls error...)
|
||||
return "Error while trying to get backtrace"
|
||||
return empty
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue