[tuxdroid-svn] r4927 - software_suite_v3/smart-core/smart-server/trunk/util/xml
Status: Beta
Brought to you by:
ks156
|
From: remi <c2m...@c2...> - 2009-06-29 09:05:03
|
Author: remi
Date: 2009-06-29 11:04:56 +0200 (Mon, 29 Jun 2009)
New Revision: 4927
Modified:
software_suite_v3/smart-core/smart-server/trunk/util/xml/XmlSerializer.py
Log:
* added a traceback storage on xml reads error
Modified: software_suite_v3/smart-core/smart-server/trunk/util/xml/XmlSerializer.py
===================================================================
--- software_suite_v3/smart-core/smart-server/trunk/util/xml/XmlSerializer.py 2009-06-29 08:15:41 UTC (rev 4926)
+++ software_suite_v3/smart-core/smart-server/trunk/util/xml/XmlSerializer.py 2009-06-29 09:04:56 UTC (rev 4927)
@@ -7,12 +7,15 @@
import os
import sys
+import traceback
import cStringIO
from xml.sax.handler import ContentHandler
from xml.sax.saxutils import XMLGenerator
from xml.sax.xmlreader import XMLReader
from xml.sax import make_parser
+LAST_TRACE_BACK = "No error"
+
# ------------------------------------------------------------------------------
# Xml parser handler to make a dictionary from a xml content.
# ------------------------------------------------------------------------------
@@ -171,6 +174,16 @@
"""
# --------------------------------------------------------------------------
+ # Get the last traceback.
+ # --------------------------------------------------------------------------
+ def getLastTraceback():
+ """Get the last traceback.
+ @return: A string.
+ """
+ global LAST_TRACE_BACK
+ return LAST_TRACE_BACK
+
+ # --------------------------------------------------------------------------
# Deserialize a xml file to a dictionary.
# --------------------------------------------------------------------------
def deserialize(xmlFileName):
@@ -178,6 +191,17 @@
@param xmlFileName: Input xml file.
@return: The resulting dictionary.
"""
+ def setLastTraceback():
+ global LAST_TRACE_BACK
+ fList = traceback.format_exception(sys.exc_info()[0],
+ sys.exc_info()[1],
+ sys.exc_info()[2])
+ LAST_TRACE_BACK = ""
+ for line in fList:
+ LAST_TRACE_BACK += line
+ def reinitLastTraceback():
+ global LAST_TRACE_BACK
+ LAST_TRACE_BACK = "No error"
# Get the xml encoding
encoding = "utf-8"
try:
@@ -191,15 +215,19 @@
encoding = line[line.find("encoding"):].split('"')[1]
finally:
f.close()
+ reinitLastTraceback()
except:
+ setLastTraceback()
return None
try:
parser = make_parser()
dictionaryHandler = DictionaryHandler(encoding)
parser.setContentHandler(dictionaryHandler)
parser.parse(open(xmlFileName))
+ reinitLastTraceback()
return dictionaryHandler.getDictionary()
except:
+ setLastTraceback()
return None
# --------------------------------------------------------------------------
@@ -261,3 +289,4 @@
deserialize = staticmethod(deserialize)
deserializeEx = staticmethod(deserializeEx)
serialize = staticmethod(serialize)
+ getLastTraceback = staticmethod(getLastTraceback)
|