From 7343af83bd192737e8e08366424d4f30345fb1dd Mon Sep 17 00:00:00 2001 From: gdetrez Date: Wed, 6 Dec 2006 00:07:57 +0100 Subject: [PATCH] Fonction copie des librairies de cherrypy pour formatter le traceback darcs-hash:20061205230757-f46e9-bd5ba336dd0b230ace414d61f1791d02c284b787.gz --- lib/utils/exceptions.py | 50 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100755 lib/utils/exceptions.py diff --git a/lib/utils/exceptions.py b/lib/utils/exceptions.py new file mode 100755 index 00000000..d00607b2 --- /dev/null +++ b/lib/utils/exceptions.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python +# -*- coding: iso-8859-15 -*- +# ############################################################# +# .. +# .... ............ ........ +# . ....... . .... .. +# . ... .. .. .. .. ..... . .. +# .. .. ....@@@. .. . ........ . +# .. . .. ..@.@@..@@. .@@@@@@@ @@@@@@. .... +# .@@@@. .@@@@. .@@@@..@@.@@..@@@..@@@..@@@@.... .... +# @@@@... .@@@.. @@ @@ .@..@@..@@...@@@. .@@@@@. .. +# .@@@.. . @@@. @@.@@..@@.@@..@@@ @@ .@@@@@@.. ..... +# ...@@@.... @@@ .@@.......... ........ ..... .. +# . ..@@@@.. . .@@@@. .. ....... . ............. +# . .. .... .. .. . ... .... +# . . .... ............. .. ... +# .. .. ... ........ ... ... +# ................................ +# +# ############################################################# +""" +exceptions.py + + Fonctions pour gérer les exceptions + +Copyright (c) 2006 by www.crans.org +Some code, from cherrypy lib +""" + +import sys, traceback + + +def formatExc(exc=None): + """formatExc(exc=None) -> exc (or sys.exc_info if None), formatted.""" + if exc is None: + exc = sys.exc_info() + + if exc == (None, None, None): + return "" + + page_handler_str = "" + args = list(getattr(exc[1], "args", [])) + if args: + if len(args) > 1: + page_handler = args.pop() + page_handler_str = 'Page handler: %s\n' % repr(page_handler) + exc[1].args = tuple(args) + return page_handler_str + "".join(traceback.format_exception(*exc)) + +