X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/1f780e48af479e7bf9a07eaaa1ab6b41f1ffb17b..92218ce60024b07e9ae5a5790a85582db083e55c:/wxPython/samples/ide/activegrid/util/aglogging.py diff --git a/wxPython/samples/ide/activegrid/util/aglogging.py b/wxPython/samples/ide/activegrid/util/aglogging.py index 880ff822f2..e4b5e7fd47 100644 --- a/wxPython/samples/ide/activegrid/util/aglogging.py +++ b/wxPython/samples/ide/activegrid/util/aglogging.py @@ -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: