]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/samples/ide/activegrid/util/aglogging.py
Fix "warning: operation on 'y' may be undefined".
[wxWidgets.git] / wxPython / samples / ide / activegrid / util / aglogging.py
index 880ff822f231f7d09bcd4a3c087c2a636a48ab82..e4b5e7fd4771ca0841919ce37de9db65942e7ada 100644 (file)
@@ -14,47 +14,60 @@ import sys
 import os
 import re
 import traceback
+import logging
+from activegrid.util.lang import *
+
+LEVEL_FATAL = logging.FATAL
+LEVEL_ERROR = logging.ERROR
+LEVEL_WARN = logging.WARN
+LEVEL_INFO = logging.INFO
+LEVEL_DEBUG = logging.DEBUG
+
+TEST_MODE_NONE = 0
+TEST_MODE_DETERMINISTIC = 1
+TEST_MODE_NON_DETERMINISTIC = 2
 
 global agTestMode
-agTestMode = False
+agTestMode = TEST_MODE_NONE
 
 def setTestMode(mode):
     global agTestMode
-    if (mode):
-        agTestMode = True
-    else:
-        agTestMode = False
+    agTestMode = mode
         
 def getTestMode():
     global agTestMode
     return agTestMode
     
 def testMode(normalObj, testObj=None):
-    if getTestMode():
+    if getTestMode() > TEST_MODE_NONE:
         return testObj
     return normalObj
 
-def toDiffableString(value):
-    s = repr(value)
-    ds = ""
-    i = s.find(" at 0x") 
-    start = 0
-    while (i >= 0):
-        j = s.find(">", i)
-        if (j < i):
-            break
-        ds += s[start:i]
-        start = j
-        i = s.find(" at 0x", start) 
-    return ds + s[start:]
-    
+pythonFileRefPattern = asString(r'(?<=File ")[^"]*(#[^#]*")(, line )[0-9]*')
+phpFileRefPattern = asString(r'( in ).*#([^#]*#[^ ]*)(?= on line )')
+pathSepPattern = os.sep
+if (pathSepPattern == "\\"):
+    pathSepPattern = "\\\\"
+pythonFileRefPattern = pythonFileRefPattern.replace("#", pathSepPattern)
+pythonFileRefPattern = re.compile(pythonFileRefPattern)
+phpFileRefPattern = phpFileRefPattern.replace("#", pathSepPattern)
+phpFileRefPattern = re.compile(phpFileRefPattern)
+
 def removeFileRefs(str):
-    str = re.sub(r'(?<=File ")[^"]*(\\[^\\]*")(, line )[0-9]*', _fileNameReplacement, str)
+    str = pythonFileRefPattern.sub(_fileNameReplacement, str)
+    str = phpFileRefPattern.sub(_fileNameReplacementPHP, str)
+    return str
+    
+def removePHPFileRefs(str):
+    str = phpFileRefPattern.sub(_fileNameReplacementPHP, str)
     return str
     
 def _fileNameReplacement(match):
-    return "...%s" % match.group(1)
-
+    return "...%s" % match.group(1).replace(os.sep, "/")
+    
+def _fileNameReplacementPHP(match):
+    return "%s...%s" % (match.group(1), match.group(2).replace(os.sep, "/"))
+    
 def getTraceback():
     extype, val, tb = sys.exc_info()
     tbs = "\n"
@@ -62,8 +75,14 @@ def getTraceback():
         tbs += s
     return tbs
 
-def reportException(out=None, stacktrace=False, diffable=False):
-    extype, val, t = sys.exc_info()
+def reportException(out=None, stacktrace=False, diffable=False, exception=None):
+    if (True): # exception == None):
+        extype, val, t = sys.exc_info()
+    else:
+        extype = type(exception)
+        val = exception
+        if (stacktrace):
+            e,v,t = sys.exc_info()
     if (diffable):
         exstr = removeFileRefs(str(val))
     else: