]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/samples/ide/activegrid/util/objutils.py
1 #----------------------------------------------------------------------------
3 # Purpose: Object Utilities
5 # Author: Alan Mullendore
9 # Copyright: (c) 2004-2005 ActiveGrid, Inc.
10 # License: wxWindows License
11 #----------------------------------------------------------------------------
20 def defaultLoad(fileObject
, knownTypes
=None):
21 xml
= fileObject
.read()
22 loadedObject
= xmlmarshaller
.unmarshal(xml
, knownTypes
=knownTypes
)
23 if hasattr(fileObject
, 'name'):
24 loadedObject
.fileName
= os
.path
.abspath(fileObject
.name
)
25 loadedObject
.initialize()
28 def defaultSave(fileObject
, objectToSave
, knownTypes
=None, withEncoding
=1, encoding
='utf-8'):
29 xml
= xmlmarshaller
.marshal(objectToSave
, prettyPrint
=True, knownTypes
=knownTypes
, withEncoding
=withEncoding
, encoding
=encoding
)
33 def clone(objectToClone
, knownTypes
=None, encoding
='utf-8'):
34 xml
= xmlmarshaller
.marshal(objectToClone
, prettyPrint
=True, knownTypes
=knownTypes
, encoding
=encoding
)
35 clonedObject
= xmlmarshaller
.unmarshal(xml
, knownTypes
=knownTypes
)
36 if hasattr(objectToClone
, 'fileName'):
37 clonedObject
.fileName
= objectToClone
.fileName
39 clonedObject
.initialize()
40 except AttributeError:
44 def classForName(className
):
45 pathList
= className
.split('.')
46 moduleName
= '.'.join(pathList
[:-1])
47 code
= __import__(moduleName
)
48 for name
in pathList
[1:]:
49 code
= code
.__dict
__[name
]
52 def hasattrignorecase(object, name
):
53 namelow
= name
.lower()
54 for attr
in dir(object):
55 if attr
.lower() == namelow
:
57 for attr
in dir(object):
58 if attr
.lower() == '_' + namelow
:
62 def setattrignorecase(object, name
, value
):
63 namelow
= name
.lower()
64 for attr
in object.__dict
__:
65 if attr
.lower() == namelow
:
66 object.__dict
__[attr
] = value
68 object.__dict
__[name
] = value
70 def getattrignorecase(object, name
):
71 namelow
= name
.lower()
72 for attr
in object.__dict
__:
73 if attr
.lower() == namelow
:
74 return object.__dict
__[attr
]
75 return object.__dict
__[name
]
77 def hasPropertyValue(obj
, attr
):
80 prop
= obj
.__class
__.__dict
__[attr
]
81 if (isinstance(prop
, property)):
82 hasProp
= hasattr(obj
, attr
)
84 # It's a property and it has a value but sometimes we don't want it.
85 # If there is a _hasattr method execute it and the
86 # result will tell us whether to include this value
88 hasProp
= obj
._hasattr
(attr
)