Пример #1
0
 def process(self, data, type, history):
     """ process the specified type then process its children """
     if type in history:
         return
     if type.enum():
         return
     history.append(type)
     resolved = type.resolve()
     value = None
     if type.unbounded():
         value = []
     else:
         if len(resolved) > 0:
             if resolved.mixed():
                 value = Factory.property(resolved.name)
                 md = value.__metadata__
                 md.sxtype = resolved
             else:
                 value = Factory.object(resolved.name)
                 md = value.__metadata__
                 md.sxtype = resolved
                 md.ordering = self.ordering(resolved)
     setattr(data, type.name, value)
     if value is not None:
         data = value
     if not isinstance(data, list):
         self.add_attributes(data, resolved)
         for child, ancestry in resolved.children():
             if self.skip_child(child, ancestry):
                 continue
             self.process(data, child, history[:])
Пример #2
0
 def build(self, name):
     """ build a an object for the specified typename as defined in the schema """
     if isinstance(name, basestring):
         type = self.resolver.find(name)
         if type is None:
             raise TypeNotFound(name)
     else:
         type = name
     cls = type.name
     if type.mixed():
         data = Factory.property(cls)
     else:
         data = Factory.object(cls)
     resolved = type.resolve()
     md = data.__metadata__
     md.sxtype = resolved
     md.ordering = self.ordering(resolved)
     history = []
     self.add_attributes(data, resolved)
     for child, ancestry in type.children():
         if self.skip_child(child, ancestry):
             continue
         self.process(data, child, history[:])
     return data
Пример #3
0
 def postprocess(self, content):
     """
     Perform final processing of the resulting data structure as follows:
       - Mixed values (children and text) will have a result of the I{content.node}.
       - Simi-simple values (attributes, no-children and text) will have a result of a
          property object.
       - Simple values (no-attributes, no-children with text nodes) will have a string 
          result equal to the value of the content.node.getText().
     @param content: The current content being unmarshalled.
     @type content: L{Content}
     @return: The post-processed result.
     @rtype: I{any}
     """
     node = content.node
     if len(node.children) and node.hasText():
         return node
     attributes = AttrList(node.attributes)
     if attributes.rlen() and \
         not len(node.children) and \
         node.hasText():
             p = Factory.property(node.name, node.getText())
             return merge(content.data, p)
     if len(content.data):
         return content.data
     lang = attributes.lang()
     if content.node.isnil():
         return None
     if not len(node.children) and content.text is None:
         if self.nillable(content):
             return None
         else:
             return Text('', lang=lang)
     if isinstance(content.text, basestring):
         return Text(content.text, lang=lang)
     else:
         return content.text