Docview and IDE patch from Morag Hua with fix for bug #1217890
"Closing view crashes Python" plus some new features: New feature added to the IDE is 'Extensions'. Under Tools|Options|Extensions, you can add calls to external programs. For example you can add a "Notepad" extension (under windows) that will exec Notepad on the currently open file. A new "Notepad" menu item will appear under the Tools menu. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@34638 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -14,8 +14,10 @@ import traceback
|
||||
import sys
|
||||
import os
|
||||
|
||||
def _registerMainModuleDir():
|
||||
global mainModuleDir
|
||||
def isWindows():
|
||||
return os.name == 'nt'
|
||||
|
||||
def _generateMainModuleDir():
|
||||
if sys.executable.find('python') != -1:
|
||||
utilModuleDir = os.path.dirname(__file__)
|
||||
if not os.path.isabs(utilModuleDir):
|
||||
@@ -25,5 +27,22 @@ def _registerMainModuleDir():
|
||||
mainModuleDir = os.path.dirname(mainModuleDir) # Get rid of library.zip
|
||||
else:
|
||||
mainModuleDir = os.path.dirname(sys.executable)
|
||||
return mainModuleDir
|
||||
|
||||
mainModuleDir = _generateMainModuleDir()
|
||||
|
||||
|
||||
def _generatePythonExecPath():
|
||||
if sys.executable.find('python') != -1:
|
||||
pythonExecPath = sys.executable
|
||||
else:
|
||||
pythonExecPath = os.path.join(os.path.dirname(sys.executable), '3rdparty\python2.3\python')
|
||||
return pythonExecPath
|
||||
|
||||
pythonExecPath = _generatePythonExecPath()
|
||||
|
||||
def getCommandNameForExecPath(execPath):
|
||||
if isWindows():
|
||||
return '"%s"' % execPath
|
||||
return execPath
|
||||
|
||||
_registerMainModuleDir()
|
||||
|
103
wxPython/samples/ide/activegrid/util/aglogging.py
Normal file
103
wxPython/samples/ide/activegrid/util/aglogging.py
Normal file
@@ -0,0 +1,103 @@
|
||||
#----------------------------------------------------------------------------
|
||||
# Name: aglogging.py
|
||||
# Purpose: Utilities to help with logging
|
||||
#
|
||||
# Author: Jeff Norton
|
||||
#
|
||||
# Created: 01/04/05
|
||||
# CVS-ID: $Id$
|
||||
# Copyright: (c) 2005 ActiveGrid, Inc.
|
||||
# License: wxWindows License
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
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 = TEST_MODE_NONE
|
||||
|
||||
def setTestMode(mode):
|
||||
global agTestMode
|
||||
agTestMode = mode
|
||||
|
||||
def getTestMode():
|
||||
global agTestMode
|
||||
return agTestMode
|
||||
|
||||
def testMode(normalObj, testObj=None):
|
||||
if getTestMode() > TEST_MODE_NONE:
|
||||
return testObj
|
||||
return normalObj
|
||||
|
||||
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 = 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).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"
|
||||
for s in traceback.format_tb(tb):
|
||||
tbs += s
|
||||
return tbs
|
||||
|
||||
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:
|
||||
exstr = str(val)
|
||||
if (out == None):
|
||||
print "Got Exception = %s: %s" % (extype, exstr)
|
||||
else:
|
||||
print >> out, "Got Exception = %s: %s" % (extype, exstr)
|
||||
if (stacktrace):
|
||||
fmt = traceback.format_exception(extype, val, t)
|
||||
for s in fmt:
|
||||
if (diffable):
|
||||
s = removeFileRefs(s)
|
||||
if (out == None):
|
||||
print s
|
||||
else:
|
||||
print >> out, s
|
||||
|
67
wxPython/samples/ide/activegrid/util/lang.py
Normal file
67
wxPython/samples/ide/activegrid/util/lang.py
Normal file
@@ -0,0 +1,67 @@
|
||||
#----------------------------------------------------------------------------
|
||||
# Name: lang.py
|
||||
# Purpose: Active grid language specific utilities -- provides portability
|
||||
# for common idiom's that have language specific implementations
|
||||
#
|
||||
# Author: Jeff Norton
|
||||
#
|
||||
# Created: 04/27/05
|
||||
# CVS-ID: $Id$
|
||||
# Copyright: (c) 2004-2005 ActiveGrid, Inc.
|
||||
# License: wxWindows License
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
def isMain(caller):
|
||||
return caller == '__main__'
|
||||
|
||||
def ag_className(obj):
|
||||
return obj.__class__.__name__
|
||||
|
||||
def asDict(src):
|
||||
return src
|
||||
|
||||
def asList(src):
|
||||
return src
|
||||
|
||||
def asTuple(src):
|
||||
return src
|
||||
|
||||
def asString(src):
|
||||
return src
|
||||
|
||||
def asInt(src):
|
||||
return src
|
||||
|
||||
def asBool(src):
|
||||
return src
|
||||
|
||||
def asObject(src):
|
||||
return src
|
||||
|
||||
def cast(src, type):
|
||||
return src
|
||||
|
||||
def asRef(src):
|
||||
return src
|
||||
|
||||
def asClass(src):
|
||||
return src
|
||||
|
||||
def localize(text):
|
||||
return text
|
||||
|
||||
# Pass in Python code as a string. The cross-compiler will convert to PHP
|
||||
# and in-line the result.
|
||||
def pyToPHP(expr):
|
||||
pass
|
||||
|
||||
# Pass in PHP code as a string. The cross-compiler will drop it in-line verbatim.
|
||||
def PHP(expr):
|
||||
pass
|
||||
|
||||
# Bracket Python only code. The Cross-compiler will ignore the bracketed code.
|
||||
def ifDefPy(comment=False):
|
||||
pass
|
||||
|
||||
def endIfDef():
|
||||
pass
|
@@ -14,98 +14,7 @@ import logging
|
||||
import traceback
|
||||
import sys
|
||||
import os
|
||||
import xmlmarshaller
|
||||
|
||||
AG_TYPE_MAPPING = { "ag:append" : "activegrid.model.processmodel.AppendOperation",
|
||||
"ag:body" : "activegrid.model.processmodel.Body",
|
||||
"ag:copy" : "activegrid.model.processmodel.CopyOperation",
|
||||
"ag:cssRule" : "activegrid.model.processmodel.CssRule",
|
||||
"ag:datasource" : "activegrid.data.dataservice.DataSource",
|
||||
"ag:debug" : "activegrid.model.processmodel.DebugOperation",
|
||||
"ag:deployment" : "activegrid.server.deployment.Deployment",
|
||||
"ag:glue" : "activegrid.model.processmodel.Glue",
|
||||
"ag:hr" : "activegrid.model.processmodel.HorizontalRow",
|
||||
"ag:image" : "activegrid.model.processmodel.Image",
|
||||
"ag:inputs" : "activegrid.model.processmodel.Inputs",
|
||||
"ag:label" : "activegrid.model.processmodel.Label",
|
||||
"ag:processmodel": "activegrid.model.processmodel.ProcessModel",
|
||||
"ag:processmodelref" : "activegrid.server.deployment.ProcessModelRef",
|
||||
"ag:query" : "activegrid.model.processmodel.Query",
|
||||
"ag:schemaOptions" : "activegrid.model.schema.SchemaOptions",
|
||||
"ag:schemaref" : "activegrid.server.deployment.SchemaRef",
|
||||
"ag:set" : "activegrid.model.processmodel.SetOperation",
|
||||
"ag:text" : "activegrid.model.processmodel.Text",
|
||||
"ag:title" : "activegrid.model.processmodel.Title",
|
||||
"ag:view" : "activegrid.model.processmodel.View",
|
||||
"bpws:case" : "activegrid.model.processmodel.BPELCase",
|
||||
"bpws:catch" : "activegrid.model.processmodel.BPELCatch",
|
||||
"bpws:faultHandlers" : "activegrid.model.processmodel.BPELFaultHandlers",
|
||||
"bpws:invoke" : "activegrid.model.processmodel.BPELInvoke",
|
||||
"bpws:onMessage" : "activegrid.model.processmodel.BPELOnMessage",
|
||||
"bpws:otherwise" : "activegrid.model.processmodel.BPELOtherwise",
|
||||
"bpws:pick" : "activegrid.model.processmodel.BPELPick",
|
||||
"bpws:process" : "activegrid.model.processmodel.BPELProcess",
|
||||
"bpws:receive" : "activegrid.model.processmodel.BPELReceive",
|
||||
"bpws:reply" : "activegrid.model.processmodel.BPELReply",
|
||||
"bpws:scope" : "activegrid.model.processmodel.BPELScope",
|
||||
"bpws:sequence" : "activegrid.model.processmodel.BPELSequence",
|
||||
"bpws:switch" : "activegrid.model.processmodel.BPELSwitch",
|
||||
"bpws:terminate" : "activegrid.model.processmodel.BPELTerminate",
|
||||
"bpws:variable" : "activegrid.model.processmodel.BPELVariable",
|
||||
"bpws:variables" : "activegrid.model.processmodel.BPELVariables",
|
||||
"bpws:while" : "activegrid.model.processmodel.BPELWhile",
|
||||
"wsdl:message" : "activegrid.model.processmodel.WSDLMessage",
|
||||
"wsdl:part" : "activegrid.model.processmodel.WSDLPart",
|
||||
"xforms:group" : "activegrid.model.processmodel.XFormsGroup",
|
||||
"xforms:input" : "activegrid.model.processmodel.XFormsInput",
|
||||
"xforms:label" : "activegrid.model.processmodel.XFormsLabel",
|
||||
"xforms:output" : "activegrid.model.processmodel.XFormsOutput",
|
||||
"xforms:secret" : "activegrid.model.processmodel.XFormsSecret",
|
||||
"xforms:submit" : "activegrid.model.processmodel.XFormsSubmit",
|
||||
"xs:all" : "activegrid.model.schema.XsdSequence",
|
||||
"xs:complexType" : "activegrid.model.schema.XsdComplexType",
|
||||
"xs:element" : "activegrid.model.schema.XsdElement",
|
||||
"xs:field" : "activegrid.model.schema.XsdKeyField",
|
||||
"xs:key" : "activegrid.model.schema.XsdKey",
|
||||
"xs:keyref" : "activegrid.model.schema.XsdKeyRef",
|
||||
"xs:schema" : "activegrid.model.schema.Schema",
|
||||
"xs:selector" : "activegrid.model.schema.XsdKeySelector",
|
||||
"xs:sequence" : "activegrid.model.schema.XsdSequence",
|
||||
"projectmodel" : "activegrid.tool.ProjectEditor.ProjectModel",
|
||||
}
|
||||
|
||||
def defaultLoad(fileObject, knownTypes=None):
|
||||
xml = fileObject.read()
|
||||
loadedObject = defaultUnmarshal(xml, knownTypes=knownTypes)
|
||||
if hasattr(fileObject, 'name'):
|
||||
loadedObject.fileName = os.path.abspath(fileObject.name)
|
||||
loadedObject.initialize()
|
||||
return loadedObject
|
||||
|
||||
def defaultUnmarshal(xml, knownTypes=None):
|
||||
if not knownTypes: knownTypes = AG_TYPE_MAPPING
|
||||
return xmlmarshaller.unmarshal(xml, knownTypes=knownTypes)
|
||||
|
||||
def defaultSave(fileObject, objectToSave, prettyPrint=True, knownTypes=None, withEncoding=1, encoding='utf-8'):
|
||||
xml = defaultMarshal(objectToSave, prettyPrint=prettyPrint, knownTypes=knownTypes, withEncoding=withEncoding, encoding=encoding)
|
||||
fileObject.write(xml)
|
||||
fileObject.flush()
|
||||
|
||||
def defaultMarshal(objectToSave, prettyPrint=True, knownTypes=None, withEncoding=1, encoding='utf-8'):
|
||||
if not knownTypes: knownTypes = AG_TYPE_MAPPING
|
||||
return xmlmarshaller.marshal(objectToSave, prettyPrint=prettyPrint, knownTypes=knownTypes, withEncoding=withEncoding, encoding=encoding)
|
||||
|
||||
def clone(objectToClone, knownTypes=None, encoding='utf-8'):
|
||||
if not knownTypes: knownTypes = AG_TYPE_MAPPING
|
||||
xml = xmlmarshaller.marshal(objectToClone, prettyPrint=True, knownTypes=knownTypes, encoding=encoding)
|
||||
clonedObject = xmlmarshaller.unmarshal(xml, knownTypes=knownTypes)
|
||||
if hasattr(objectToClone, 'fileName'):
|
||||
clonedObject.fileName = objectToClone.fileName
|
||||
try:
|
||||
clonedObject.initialize()
|
||||
except AttributeError:
|
||||
pass
|
||||
return clonedObject
|
||||
from types import *
|
||||
|
||||
def classForName(className):
|
||||
pathList = className.split('.')
|
||||
@@ -115,31 +24,6 @@ def classForName(className):
|
||||
code = code.__dict__[name]
|
||||
return code
|
||||
|
||||
def hasattrignorecase(object, name):
|
||||
namelow = name.lower()
|
||||
for attr in dir(object):
|
||||
if attr.lower() == namelow:
|
||||
return True
|
||||
for attr in dir(object):
|
||||
if attr.lower() == '_' + namelow:
|
||||
return True
|
||||
return False
|
||||
|
||||
def setattrignorecase(object, name, value):
|
||||
namelow = name.lower()
|
||||
for attr in object.__dict__:
|
||||
if attr.lower() == namelow:
|
||||
object.__dict__[attr] = value
|
||||
return
|
||||
object.__dict__[name] = value
|
||||
|
||||
def getattrignorecase(object, name):
|
||||
namelow = name.lower()
|
||||
for attr in object.__dict__:
|
||||
if attr.lower() == namelow:
|
||||
return object.__dict__[attr]
|
||||
return object.__dict__[name]
|
||||
|
||||
def hasPropertyValue(obj, attr):
|
||||
hasProp = False
|
||||
try:
|
||||
@@ -159,7 +43,7 @@ def hasPropertyValue(obj, attr):
|
||||
return hasProp
|
||||
|
||||
def toDiffableString(value):
|
||||
s = repr(value)
|
||||
s = str(value)
|
||||
ds = ""
|
||||
i = s.find(" at 0x")
|
||||
start = 0
|
||||
@@ -171,19 +55,51 @@ def toDiffableString(value):
|
||||
start = j
|
||||
i = s.find(" at 0x", start)
|
||||
return ds + s[start:]
|
||||
|
||||
|
||||
def toString(value, options=0):
|
||||
if ((options & PRINT_OBJ_DIFFABLE) > 0):
|
||||
return toDiffableString(value)
|
||||
return value
|
||||
|
||||
def toTypeString(obj):
|
||||
if (isinstance(obj, BooleanType)):
|
||||
return "bool"
|
||||
elif (isinstance(obj, UnicodeType)):
|
||||
return "unicode"
|
||||
elif (isinstance(obj, basestring)):
|
||||
return "string"
|
||||
elif (isinstance(obj, IntType)):
|
||||
return "int"
|
||||
elif (isinstance(obj, FloatType)):
|
||||
return "float"
|
||||
elif (type(obj) == ListType):
|
||||
return "list"
|
||||
elif (isinstance(obj, DictType)):
|
||||
return "dict"
|
||||
elif (isinstance(obj, TupleType)):
|
||||
return "tuple"
|
||||
elif (isinstance(obj, InstanceType)):
|
||||
return type(obj)
|
||||
else:
|
||||
return type(obj)
|
||||
|
||||
PRINT_OBJ_GETATTR = 1
|
||||
PRINT_OBJ_HIDE_INTERNAL = 2
|
||||
PRINT_OBJ_COMPACT = 4
|
||||
PRINT_OBJ_NONONE = 8
|
||||
PRINT_OBJ_DIFFABLE = 16
|
||||
PRINT_OBJ_INTERNAL = 512
|
||||
|
||||
def printObject(out, object, name="", indent=0, flags=0, exclude=None, maxIndent=30):
|
||||
if ((maxIndent != None) and (indent > maxIndent)):
|
||||
print >> out, " "*indent, name, str(object)
|
||||
print >> out, " "*indent, "%s: %s" % (name, toString(str(object), flags)),
|
||||
if ((flags & PRINT_OBJ_INTERNAL) == 0):
|
||||
print >> out
|
||||
return True
|
||||
finalNewLine = False
|
||||
printed = True
|
||||
## if (exclude == None):
|
||||
## exclude = []
|
||||
if ((flags & PRINT_OBJ_COMPACT) > 0):
|
||||
if (exclude and object in exclude):
|
||||
return
|
||||
@@ -191,7 +107,7 @@ def printObject(out, object, name="", indent=0, flags=0, exclude=None, maxIndent
|
||||
if ((flags & PRINT_OBJ_INTERNAL) == 0):
|
||||
finalNewLine = True
|
||||
flags |= PRINT_OBJ_INTERNAL
|
||||
if (object == None):
|
||||
if (object is None):
|
||||
if (flags & PRINT_OBJ_NONONE) == 0:
|
||||
print >> out, " "*indent, name, " = None",
|
||||
else:
|
||||
@@ -201,21 +117,21 @@ def printObject(out, object, name="", indent=0, flags=0, exclude=None, maxIndent
|
||||
finalNewLine = False
|
||||
printed = False
|
||||
elif (isinstance(object, (list, tuple))):
|
||||
if (exclude and object in exclude):
|
||||
print >> out, " "*indent, name, " : ", type(object), " of length = ", len(object), " (already printed)",
|
||||
elif (exclude and name in exclude):
|
||||
print >> out, " "*indent, name, " : ", type(object), " of length = ", len(object), " (excluded)",
|
||||
if ((exclude != None) and object in exclude):
|
||||
print >> out, " "*indent, name, " : ", toTypeString(object), " of length = ", len(object), " (already printed)",
|
||||
elif ((exclude != None) and name in exclude):
|
||||
print >> out, " "*indent, name, " : ", toTypeString(object), " of length = ", len(object), " (excluded)",
|
||||
else:
|
||||
if (exclude != None): exclude.append(object)
|
||||
print >> out, " "*indent, name, " : ", type(object), " of length = %i" % len(object),
|
||||
if ((exclude != None) and (len(object) > 0)): exclude.append(object)
|
||||
print >> out, " "*indent, name, " : ", toTypeString(object), " of length = %d" % len(object),
|
||||
for i, o in enumerate(object):
|
||||
print >> out
|
||||
printObject(out, o, name="[%i]" % i, indent=indent+2, flags=flags, exclude=exclude, maxIndent=maxIndent)
|
||||
printObject(out, o, name="[%d]" % i, indent=indent+2, flags=flags, exclude=exclude, maxIndent=maxIndent)
|
||||
elif (isinstance(object, dict)):
|
||||
if (exclude and object in exclude):
|
||||
print >> out, " "*indent, name, " : ", type(object), " (already printed)",
|
||||
if ((exclude != None) and object in exclude):
|
||||
print >> out, " "*indent, name, " : ", toTypeString(object), " (already printed)",
|
||||
else:
|
||||
if (exclude != None): exclude.append(object)
|
||||
if ((exclude != None) and (len(object) > 0)): exclude.append(object)
|
||||
if (len(name) > 0):
|
||||
print >> out, " "*indent, name,
|
||||
if ((flags & PRINT_OBJ_COMPACT) == 0):
|
||||
@@ -226,25 +142,29 @@ def printObject(out, object, name="", indent=0, flags=0, exclude=None, maxIndent
|
||||
print >> out
|
||||
keys = object.keys()
|
||||
keys.sort()
|
||||
for n in keys:
|
||||
if ((n != None) and (not n.startswith("_") or ((flags & PRINT_OBJ_HIDE_INTERNAL) == 0))):
|
||||
if printObject(out, object[n], name=n, indent=indent+2, flags=flags, exclude=exclude, maxIndent=maxIndent):
|
||||
if ((flags & PRINT_OBJ_COMPACT) == 0):
|
||||
print >> out
|
||||
else:
|
||||
print >> out, ",",
|
||||
for key in keys:
|
||||
if (key != None):
|
||||
n = key
|
||||
if (not (isinstance(n, basestring))):
|
||||
n = str(n)
|
||||
if ((not n.startswith("_") or ((flags & PRINT_OBJ_HIDE_INTERNAL) == 0))):
|
||||
if printObject(out, object[key], name=n, indent=indent+2, flags=(flags | PRINT_OBJ_INTERNAL), exclude=exclude, maxIndent=maxIndent):
|
||||
if ((flags & PRINT_OBJ_COMPACT) == 0):
|
||||
print >> out
|
||||
else:
|
||||
print >> out, ",",
|
||||
print >> out, " "*indent, "}",
|
||||
elif (hasattr(object, "__dict__")):
|
||||
if (exclude and object in exclude):
|
||||
print >> out, " "*indent, name, " : ", type(object), " (already printed) = ", toDiffableString(object),
|
||||
if ((exclude != None) and object in exclude):
|
||||
print >> out, " "*indent, name, " : ", toTypeString(object), " (already printed) = ", toDiffableString(object),
|
||||
else:
|
||||
if (exclude != None): exclude.append(object)
|
||||
if (name.startswith("_")):
|
||||
print >> out, " "*indent, name, " : ", type(object),
|
||||
elif (exclude and object.__dict__ in exclude):
|
||||
print >> out, " "*indent, name, " : ", type(object), " (already printed)",
|
||||
if (name.startswith("_")): ## and ((flags & PRINT_OBJ_HIDE_INTERNAL) > 0)):
|
||||
print >> out, " "*indent, name, " : ", toTypeString(object),
|
||||
elif ((exclude != None) and object.__dict__ in exclude):
|
||||
print >> out, " "*indent, name, " : ", toTypeString(object), " (already printed)",
|
||||
else:
|
||||
print >> out, " "*indent, name, " : ", type(object),
|
||||
print >> out, " "*indent, name, " : ", toTypeString(object),
|
||||
if ((flags & PRINT_OBJ_GETATTR) == 0):
|
||||
if ((flags & PRINT_OBJ_COMPACT) == 0):
|
||||
print >> out
|
||||
@@ -259,14 +179,19 @@ def printObject(out, object, name="", indent=0, flags=0, exclude=None, maxIndent
|
||||
elif (indent < 0):
|
||||
print >> out, object,
|
||||
elif isinstance(object, basestring):
|
||||
if (exclude and name in exclude):
|
||||
print >> out, " "*indent, name, " : ", type(object), " of length = ", len(object), " (excluded)",
|
||||
if ((exclude != None) and name in exclude):
|
||||
print >> out, " "*indent, name, " : ", toTypeString(object), " of length = ", len(object), " (excluded)",
|
||||
elif (len(object) > 100):
|
||||
print >> out, " "*indent, name, ":", type(object), "[%i] = %s...%s" % (len(object), object[:50], object[-50:]),
|
||||
print >> out, " "*indent, name, ":", toTypeString(object), "[%d] = %s...%s" % (len(object), object[:50], object[-50:]),
|
||||
else:
|
||||
print >> out, " "*indent, name, ":", type(object), "=", str(object),
|
||||
print >> out, " "*indent, name, ":", toTypeString(object), "=", str(object),
|
||||
## elif (isinstance(object, float)):
|
||||
## val = str(object)
|
||||
## if (len(val) > 17):
|
||||
## val = val[:17]
|
||||
## print >> out, " "*indent, name, ":", type(object), "=", val,
|
||||
else:
|
||||
print >> out, " "*indent, name, ":", type(object), "=", str(object),
|
||||
print >> out, " "*indent, name, ":", toTypeString(object), "=", str(object),
|
||||
if (finalNewLine):
|
||||
print >> out
|
||||
return printed
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -10,8 +10,7 @@
|
||||
# License: wxWindows License
|
||||
#----------------------------------------------------------------------------
|
||||
import xml.sax
|
||||
import xml.sax.handler
|
||||
|
||||
from activegrid.util.lang import *
|
||||
|
||||
class XMLPrettyPrinter(xml.sax.ContentHandler):
|
||||
def __init__(self, indentationChar=' ', newlineChar='\n'):
|
||||
@@ -24,7 +23,7 @@ class XMLPrettyPrinter(xml.sax.ContentHandler):
|
||||
|
||||
## ContentHandler methods
|
||||
def startElement(self, name, attrs):
|
||||
indentation = self.newlineChar + (self.indentationLevel * self.indentationChar)
|
||||
indentation = self.newlineChar + (self.indentationChar * self.indentationLevel)
|
||||
# build attribute string
|
||||
attrstring = ''
|
||||
for attr in attrs.getNames():
|
||||
@@ -36,6 +35,7 @@ class XMLPrettyPrinter(xml.sax.ContentHandler):
|
||||
self.hitCharData = False
|
||||
|
||||
def characters(self, content):
|
||||
## print "--> characters(%s)" % content
|
||||
self.xmlOutput += content
|
||||
self.hitCharData = True
|
||||
|
||||
@@ -43,11 +43,12 @@ class XMLPrettyPrinter(xml.sax.ContentHandler):
|
||||
self.indentationLevel -= 1
|
||||
indentation = ''
|
||||
if not self.hitCharData:
|
||||
## indentation += self.newlineChar + (self.indentationLevel * self.indentationChar)
|
||||
indentation += self.indentationLevel * self.indentationChar
|
||||
indentation += self.newlineChar + (self.indentationChar * self.indentationLevel)
|
||||
## indentation += self.indentationChar * self.indentationLevel
|
||||
else:
|
||||
self.hitCharData = False
|
||||
self.xmlOutput += '%s</%s>%s' % (indentation, self.elementStack.pop(), self.newlineChar)
|
||||
## self.xmlOutput += '%s</%s>%s' % (indentation, self.elementStack.pop(), self.newlineChar)
|
||||
self.xmlOutput += '%s</%s>' % (indentation, self.elementStack.pop())
|
||||
|
||||
def getXMLString(self):
|
||||
return self.xmlOutput[1:]
|
||||
@@ -57,7 +58,7 @@ def xmlprettyprint(xmlstr, spaces=4):
|
||||
xml.sax.parseString(xmlstr, xpp)
|
||||
return xpp.getXMLString()
|
||||
|
||||
if __name__ == '__main__':
|
||||
if isMain(__name__):
|
||||
simpleTestString = """<one>some text<two anattr="booga">two's data</two></one>"""
|
||||
print prettyprint(simpleTestString)
|
||||
print xmlprettyprint(simpleTestString)
|
||||
|
||||
|
128
wxPython/samples/ide/activegrid/util/xmlutils.py
Normal file
128
wxPython/samples/ide/activegrid/util/xmlutils.py
Normal file
@@ -0,0 +1,128 @@
|
||||
#----------------------------------------------------------------------------
|
||||
# Name: xmlutils.py
|
||||
# Purpose: XML and Marshaller Utilities
|
||||
#
|
||||
# Author: Jeff Norton
|
||||
#
|
||||
# Created: 6/2/05
|
||||
# CVS-ID: $Id$
|
||||
# Copyright: (c) 2004-2005 ActiveGrid, Inc.
|
||||
# License: wxWindows License
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
import os
|
||||
import activegrid.util.objutils as objutils
|
||||
import activegrid.util.xmlmarshaller as xmlmarshaller
|
||||
|
||||
agKnownTypes = None
|
||||
|
||||
def defaultLoad(fileObject, knownTypes=None):
|
||||
xml = fileObject.read()
|
||||
loadedObject = unmarshal(xml, knownTypes=knownTypes)
|
||||
if hasattr(fileObject, 'name'):
|
||||
loadedObject.fileName = os.path.abspath(fileObject.name)
|
||||
loadedObject.initialize()
|
||||
return loadedObject
|
||||
|
||||
def unmarshal(xml, knownTypes=None):
|
||||
if not knownTypes: knownTypes = getAgKnownTypes()
|
||||
return xmlmarshaller.unmarshal(xml, knownTypes=knownTypes)
|
||||
|
||||
def defaultSave(fileObject, objectToSave, prettyPrint=True, knownTypes=None, encoding='utf-8'):
|
||||
xml = marshal(objectToSave, prettyPrint=prettyPrint, knownTypes=knownTypes, encoding=encoding)
|
||||
fileObject.write(xml)
|
||||
fileObject.flush()
|
||||
|
||||
def marshal(objectToSave, prettyPrint=True, knownTypes=None, encoding='utf-8'):
|
||||
if not knownTypes: knownTypes = getAgKnownTypes()
|
||||
return xmlmarshaller.marshal(objectToSave, prettyPrint=prettyPrint, knownTypes=knownTypes, encoding=encoding)
|
||||
|
||||
def cloneObject(objectToClone, knownTypes=None, encoding='utf-8'):
|
||||
if not knownTypes: knownTypes = getAgKnownTypes()
|
||||
xml = xmlmarshaller.marshal(objectToClone, prettyPrint=True, knownTypes=knownTypes, encoding=encoding)
|
||||
clonedObject = xmlmarshaller.unmarshal(xml, knownTypes=knownTypes)
|
||||
if hasattr(objectToClone, 'fileName'):
|
||||
clonedObject.fileName = objectToClone.fileName
|
||||
try:
|
||||
clonedObject.initialize()
|
||||
except AttributeError:
|
||||
pass
|
||||
return clonedObject
|
||||
|
||||
def getAgKnownTypes():
|
||||
import activegrid.model.processmodel
|
||||
import activegrid.model.schema
|
||||
import activegrid.data.dataservice
|
||||
import activegrid.server.deployment
|
||||
global agKnownTypes
|
||||
if agKnownTypes == None:
|
||||
tmpAgKnownTypes = {}
|
||||
AG_TYPE_MAPPING = {
|
||||
"ag:append" : "activegrid.model.processmodel.AppendOperation",
|
||||
"ag:body" : "activegrid.model.processmodel.Body",
|
||||
"ag:cssRule" : "activegrid.model.processmodel.CssRule",
|
||||
"ag:datasource" : "activegrid.data.dataservice.DataSource",
|
||||
"ag:debug" : "activegrid.model.processmodel.DebugOperation",
|
||||
"ag:deployment" : "activegrid.server.deployment.Deployment",
|
||||
"ag:glue" : "activegrid.model.processmodel.Glue",
|
||||
"ag:hr" : "activegrid.model.processmodel.HorizontalRow",
|
||||
"ag:image" : "activegrid.model.processmodel.Image",
|
||||
"ag:inputs" : "activegrid.model.processmodel.Inputs",
|
||||
"ag:label" : "activegrid.model.processmodel.Label",
|
||||
"ag:processmodel" : "activegrid.model.processmodel.ProcessModel",
|
||||
"ag:processmodelref" : "activegrid.server.deployment.ProcessModelRef",
|
||||
"ag:query" : "activegrid.model.processmodel.Query",
|
||||
"ag:restParameter" : "activegrid.server.deployment.RestParameter",
|
||||
"ag:restService" : "activegrid.server.deployment.RestService",
|
||||
"ag:schemaOptions" : "activegrid.model.schema.SchemaOptions",
|
||||
"ag:schemaref" : "activegrid.server.deployment.SchemaRef",
|
||||
"ag:serviceref" : "activegrid.server.deployment.ServiceRef",
|
||||
"ag:set" : "activegrid.model.processmodel.SetOperation",
|
||||
"ag:text" : "activegrid.model.processmodel.Text",
|
||||
"ag:title" : "activegrid.model.processmodel.Title",
|
||||
"ag:view" : "activegrid.model.processmodel.View",
|
||||
"bpws:case" : "activegrid.model.processmodel.BPELCase",
|
||||
"bpws:catch" : "activegrid.model.processmodel.BPELCatch",
|
||||
"bpws:faultHandlers" : "activegrid.model.processmodel.BPELFaultHandlers",
|
||||
"bpws:invoke" : "activegrid.model.processmodel.BPELInvoke",
|
||||
"bpws:onMessage" : "activegrid.model.processmodel.BPELOnMessage",
|
||||
"bpws:otherwise" : "activegrid.model.processmodel.BPELOtherwise",
|
||||
"bpws:pick" : "activegrid.model.processmodel.BPELPick",
|
||||
"bpws:process" : "activegrid.model.processmodel.BPELProcess",
|
||||
"bpws:receive" : "activegrid.model.processmodel.BPELReceive",
|
||||
"bpws:reply" : "activegrid.model.processmodel.BPELReply",
|
||||
"bpws:scope" : "activegrid.model.processmodel.BPELScope",
|
||||
"bpws:sequence" : "activegrid.model.processmodel.BPELSequence",
|
||||
"bpws:switch" : "activegrid.model.processmodel.BPELSwitch",
|
||||
"bpws:terminate" : "activegrid.model.processmodel.BPELTerminate",
|
||||
"bpws:variable" : "activegrid.model.processmodel.BPELVariable",
|
||||
"bpws:variables" : "activegrid.model.processmodel.BPELVariables",
|
||||
"bpws:while" : "activegrid.model.processmodel.BPELWhile",
|
||||
"wsdl:message" : "activegrid.model.processmodel.WSDLMessage",
|
||||
"wsdl:part" : "activegrid.model.processmodel.WSDLPart",
|
||||
"xforms:group" : "activegrid.model.processmodel.XFormsGroup",
|
||||
"xforms:input" : "activegrid.model.processmodel.XFormsInput",
|
||||
"xforms:label" : "activegrid.model.processmodel.XFormsLabel",
|
||||
"xforms:output" : "activegrid.model.processmodel.XFormsOutput",
|
||||
"xforms:secret" : "activegrid.model.processmodel.XFormsSecret",
|
||||
"xforms:submit" : "activegrid.model.processmodel.XFormsSubmit",
|
||||
"xs:all" : "activegrid.model.schema.XsdSequence",
|
||||
"xs:complexType" : "activegrid.model.schema.XsdComplexType",
|
||||
"xs:element" : "activegrid.model.schema.XsdElement",
|
||||
"xs:field" : "activegrid.model.schema.XsdKeyField",
|
||||
"xs:key" : "activegrid.model.schema.XsdKey",
|
||||
"xs:keyref" : "activegrid.model.schema.XsdKeyRef",
|
||||
"xs:schema" : "activegrid.model.schema.Schema",
|
||||
"xs:selector" : "activegrid.model.schema.XsdKeySelector",
|
||||
"xs:sequence" : "activegrid.model.schema.XsdSequence",
|
||||
}
|
||||
|
||||
for keyName, className in AG_TYPE_MAPPING.iteritems():
|
||||
try:
|
||||
tmpAgKnownTypes[keyName] = objutils.classForName(className)
|
||||
except KeyError:
|
||||
print "Error mapping knownType", className
|
||||
pass
|
||||
if len(tmpAgKnownTypes) > 0:
|
||||
agKnownTypes = tmpAgKnownTypes
|
||||
return agKnownTypes
|
Reference in New Issue
Block a user