def loadURI(uri, knownTypes=None, knownNamespaces=None, xmlSource=None, createGenerics=False): loadedObject = None timeStart = time.time() xml = "" try: xml = urllib.urlopen(uri).read() loadedObject = unmarshal(xml, knownTypes=knownTypes, knownNamespaces=knownNamespaces, xmlSource=xmlSource, createGenerics=createGenerics) loadedObject.fileName = uri if hasattr(loadedObject, 'initialize'): loadedObject.initialize() finally: if xmlLogger.isEnabledFor(aglogging.LEVEL_INFO): timeDone = time.time() aglogging.info(xmlLogger, ( 'Load statistics for URI %s (%d bytes): elapsed time = %f secs' % (uri, len(xml), timeDone - timeStart))) return loadedObject
def load(fileName, knownTypes=None, knownNamespaces=None, createGenerics=False): loadedObject = None fileObject = file(fileName) timeStart = time.time() xml = "" try: xml = fileObject.read() loadedObject = unmarshal(xml, knownTypes=knownTypes, knownNamespaces=knownNamespaces, xmlSource=fileName, createGenerics=createGenerics) loadedObject.fileName = os.path.abspath(fileName) if hasattr(loadedObject, 'initialize'): loadedObject.initialize() finally: fileObject.close() if xmlLogger.isEnabledFor(aglogging.LEVEL_INFO): timeDone = time.time() aglogging.info(xmlLogger, ( 'Load statistics for file %s (%d bytes): elapsed time = %f secs' % (fileName, len(xml), timeDone - timeStart))) return loadedObject
def loadURI(uri, knownTypes=None, knownNamespaces=None, xmlSource=None, createGenerics=False): loadedObject = None timeStart = time.time() xml = "" try: xml = urllib.urlopen(uri).read() loadedObject = unmarshal(xml, knownTypes=knownTypes, knownNamespaces=knownNamespaces, xmlSource=xmlSource, createGenerics=createGenerics) loadedObject.fileName = uri if hasattr(loadedObject, 'initialize'): loadedObject.initialize() finally: if xmlLogger.isEnabledFor(aglogging.LEVEL_INFO): timeDone = time.time() aglogging.info(xmlLogger, ('Load statistics for URI %s (%d bytes): elapsed time = %f secs' % (uri, len(xml), timeDone-timeStart))) return loadedObject
def load(fileName, knownTypes=None, knownNamespaces=None, createGenerics=False): loadedObject = None fileObject = file(fileName) timeStart = time.time() xml = "" try: xml = fileObject.read() loadedObject = unmarshal(xml, knownTypes=knownTypes, knownNamespaces=knownNamespaces, xmlSource=fileName, createGenerics=createGenerics) loadedObject.fileName = os.path.abspath(fileName) if hasattr(loadedObject, 'initialize'): loadedObject.initialize() finally: fileObject.close() if xmlLogger.isEnabledFor(aglogging.LEVEL_INFO): timeDone = time.time() aglogging.info(xmlLogger, ('Load statistics for file %s (%d bytes): elapsed time = %f secs' % (fileName, len(xml), timeDone-timeStart))) return loadedObject
def save(fileName, objectToSave, prettyPrint=True, marshalType=True, knownTypes=None, knownNamespaces=None, encoding='utf-8'): if hasattr(objectToSave, '_xmlReadOnly') and objectToSave._xmlReadOnly == True: raise xmlmarshaller.MarshallerException('Error marshalling object to file "%s": object is marked "readOnly" and cannot be written' % (fileName)) timeStart = time.time() xml = marshal(objectToSave, prettyPrint=prettyPrint, marshalType=marshalType, knownTypes=knownTypes, knownNamespaces=knownNamespaces, encoding=encoding) fileObject = file(fileName, 'w') try: fileObject.write(xml) fileObject.flush() except Exception, errorData: fileObject.close() raise xmlmarshaller.MarshallerException('Error marshalling object to file "%s": %s' % (fileName, str(errorData))) fileObject.close() timeDone = time.time() aglogging.info(xmlLogger, ('Save statistics for file %s: elapsed time = %f secs' % (fileName, timeDone-timeStart))) def marshal(objectToSave, prettyPrint=True, marshalType=True, knownTypes=None, knownNamespaces=None, encoding='utf-8'): if (knownTypes == None): knownTypes, knownNamespaces = getAgKnownTypes() return xmlmarshaller.marshal(objectToSave, prettyPrint=prettyPrint, marshalType=marshalType, knownTypes=knownTypes, knownNamespaces=knownNamespaces, encoding=encoding) def addNSAttribute(xmlDoc, shortNamespace, longNamespace): if not hasattr(xmlDoc, "__xmlnamespaces__"): xmlDoc.__xmlnamespaces__ = {shortNamespace:longNamespace} elif shortNamespace not in xmlDoc.__xmlnamespaces__: if (hasattr(xmlDoc.__class__, "__xmlnamespaces__") and (xmlDoc.__xmlnamespaces__ is xmlDoc.__class__.__xmlnamespaces__)): xmlDoc.__xmlnamespaces__ = dict(xmlDoc.__xmlnamespaces__) xmlDoc.__xmlnamespaces__[shortNamespace] = longNamespace
knownTypes=knownTypes, knownNamespaces=knownNamespaces, encoding=encoding) fileObject = file(fileName, 'w') try: fileObject.write(xml) fileObject.flush() except Exception, errorData: fileObject.close() raise xmlmarshaller.MarshallerException( 'Error marshalling object to file "%s": %s' % (fileName, str(errorData))) fileObject.close() timeDone = time.time() aglogging.info(xmlLogger, ('Save statistics for file %s: elapsed time = %f secs' % (fileName, timeDone - timeStart))) def marshal(objectToSave, prettyPrint=True, marshalType=True, knownTypes=None, knownNamespaces=None, encoding='utf-8'): if (knownTypes == None): knownTypes, knownNamespaces = getAgKnownTypes() return xmlmarshaller.marshal(objectToSave, prettyPrint=prettyPrint, marshalType=marshalType, knownTypes=knownTypes,