Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Static Public Attributes
Marshall.handlers.atxml.ATXMLMarshaller Class Reference
Inheritance diagram for Marshall.handlers.atxml.ATXMLMarshaller:
Inheritance graph
[legend]
Collaboration diagram for Marshall.handlers.atxml.ATXMLMarshaller:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def getFieldNamespace
def getNamespaceURIMap
def getNamespacePrefixMap
def getNamespaces
def demarshall
def marshall
def parseContext
def parseXml
def processContext

Public Attributes

 root_tag
 namespace

Static Public Attributes

list namespaces = []
 use_validation = False

Detailed Description

Definition at line 291 of file atxml.py.


Constructor & Destructor Documentation

def Marshall.handlers.atxml.ATXMLMarshaller.__init__ (   self,
  demarshall_hook = None,
  marshall_hook = None,
  root_tag = 'metadata',
  namespace = _marker 
)

Definition at line 301 of file atxml.py.

00301 
00302                  root_tag='metadata', namespace=_marker):
00303         Marshaller.__init__(self, demarshall_hook, marshall_hook)
00304         self.root_tag = root_tag
00305         self.namespace = namespace
00306         if namespace is _marker:
00307             self.namespace = config.AT_NS


Member Function Documentation

def Marshall.handlers.atxml.ATXMLMarshaller.demarshall (   self,
  instance,
  data,
  kwargs 
)

Definition at line 340 of file atxml.py.

00340 
00341     def demarshall(self, instance, data, **kwargs):
00342         context = self.parseContext( instance, data)
00343         self.processContext( instance, context, kwargs )

Here is the call graph for this function:

Definition at line 308 of file atxml.py.

00308 
00309     def getFieldNamespace(self, field):
00310         namespaces = self.getNamespaceURIMap()
00311         # Flatten ns into (ns, attr) tuples
00312         flat_ns = []
00313         [flat_ns.extend(zip((n,)*len(n.attrs), n.attrs)) for n in namespaces]        
00314         # Dict mapping an AT fieldname to a (prefix, element name) tuple
00315         field_map = dict([(a.field, (n.prefix, a.name)) for n, a in flat_ns])
00316         return field_map
    

Here is the call graph for this function:

Mapping of prefix -> xmlns URI

Definition at line 323 of file atxml.py.

00323 
00324     def getNamespacePrefixMap(self):
00325         """ Mapping of prefix -> xmlns URI
00326         """
00327         prefix_map = dict([(ns.prefix, ns.xmlns) for ns in namespaces])

Here is the call graph for this function:

def Marshall.handlers.atxml.ATXMLMarshaller.getNamespaces (   self,
  namespaces = None 
)

Definition at line 328 of file atxml.py.

00328 
00329     def getNamespaces(self, namespaces=None):
00330         if namespaces is None:
00331             for ns in getRegisteredNamespaces():
00332                 yield ns
00333             raise StopIteration
00334 
00335         ns = getRegisteredNamespaces()
00336         for n in ns:
00337             if n.prefix in namespaces or \
00338                n.xmlns in namespaces:
00339                 yield n

Here is the caller graph for this function:

Mapping of xmlns URI to ns object

Definition at line 317 of file atxml.py.

00317 
00318     def getNamespaceURIMap(self):
00319         """ Mapping of xmlns URI to ns object
00320         """
00321         ns_map = dict([(ns.xmlns, ns) for ns in self.namespaces])
00322         return ns_map

Here is the call graph for this function:

Here is the caller graph for this function:

def Marshall.handlers.atxml.ATXMLMarshaller.marshall (   self,
  instance,
  use_namespaces = None,
  kwargs 
)

Definition at line 344 of file atxml.py.

00344 
00345     def marshall(self, instance, use_namespaces=None, **kwargs):
00346         doc = minidom.Document()
00347         node = doc.createElementNS( self.namespace, self.root_tag)         
00348         doc.appendChild( node )
00349 
00350         # setup default namespace
00351         attr = doc.createAttribute('xmlns')
00352         attr.value = self.namespace
00353         node.setAttributeNode(attr)
00354     
00355         for ns in self.getNamespaces( use_namespaces ):
00356             ns.serialize( doc, node, instance, kwargs )
00357             if not ns.prefix:
00358                 continue
00359             attrname = 'xmlns:%s' % ns.prefix
00360             attr = doc.createAttribute(attrname)
00361             attr.value = ns.xmlns
00362             node.setAttributeNode(attr)                
00363 
00364         content_type = 'text/xml'
00365         data = doc.toprettyxml()#.encode('utf-8')
00366         length = len(data)
00367         return (content_type, length, data)

Here is the call graph for this function:

def Marshall.handlers.atxml.ATXMLMarshaller.parseContext (   self,
  instance,
  data 
)

Definition at line 368 of file atxml.py.

00368 
00369     def parseContext(self, instance, data):  
00370         #parser = XmlParser( instance, data, use_validation=self.use_validation)
00371         root = ElementTree.fromstring(data)
00372         ns_map = self.getNamespaceURIMap()
00373         context = ParseContext(instance, root, ns_map)
00374         context.xmlsource = data
00375         self.parseXml( root, context, ns_map )
00376 
00377 
00378         if self.use_validation: # and not reader.IsValid():
00379             errors = error_callback.get(clear=True)
00380             log(errors)
00381             raise MarshallingException, ("Input failed to validate against "
00382                                          "the ATXML RelaxNG schema.\n"
00383                                          "%s" % errors)
00384 
00385         return context
00386 

Here is the call graph for this function:

Here is the caller graph for this function:

def Marshall.handlers.atxml.ATXMLMarshaller.parseXml (   self,
  root,
  context,
  ns_map 
)
input read and dispatch loop

Definition at line 387 of file atxml.py.

00387 
00388     def parseXml(self, root, context, ns_map):
00389         """
00390         input read and dispatch loop
00391         """
00392         read_result = 1
00393         for node in root:
00394             tag, namespace = utils.fixtag(node.tag, context.ns_map)
00395                 
00396             if namespace.processXml(context, node):
00397                 context.node=node
00398                 context.node.attribute.processXmlValue(context, node.text)
00399             else:
00400                 ## XXX: raise a warning that the attribute isnt defined in the schema
00401                 pass
00402 
00403         return read_result

Here is the caller graph for this function:

def Marshall.handlers.atxml.ATXMLMarshaller.processContext (   self,
  instance,
  context,
  options 
)
instantiate instance with data from context

Definition at line 404 of file atxml.py.

00404 
00405     def processContext(self, instance, context, options):
00406         """ instantiate instance with data from context
00407         """
00408         for ns in getRegisteredNamespaces():
00409             ns_data = context.getDataFor( ns.xmlns )
00410             ns.deserialize( instance, ns_data, options )
00411 

Here is the caller graph for this function:


Member Data Documentation

Definition at line 304 of file atxml.py.

Definition at line 294 of file atxml.py.

Definition at line 303 of file atxml.py.

Definition at line 297 of file atxml.py.


The documentation for this class was generated from the following file: