示例#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 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[:])
示例#3
0
 def start(self, content):
     """
     Processing on I{node} has started.  Build and return
     the proper object.
     @param content: The current content being unmarshalled.
     @type content: L{Content}
     @return: A subclass of Object.
     @rtype: L{Object}
     """
     content.data = Factory.object(content.node.name)
示例#4
0
 def cast(self, content):
     """
     Cast the I{untyped} list items found in content I{value}.
     Each items contained in the list is checked for XSD type information.
     Items (values) that are I{untyped}, are replaced with et_suds objects and
     type I{metadata} is added.
     @param content: The content holding the collection.
     @type content: L{Content}
     @return: self
     @rtype: L{Encoded}
     """
     aty = content.aty[1]
     resolved = content.type.resolve()
     array = Factory.object(resolved.name)
     array.item = []
     query = TypeQuery(aty)
     ref = query.execute(self.schema)
     if ref is None:
         raise TypeNotFound(qref)
     for x in content.value:
         if isinstance(x, (list, tuple)):
             array.item.append(x)
             continue
         if isinstance(x, Object):
             md = x.__metadata__
             md.sxtype = ref
             array.item.append(x)
             continue
         if isinstance(x, dict):
             x = Factory.object(ref.name, x)
             md = x.__metadata__
             md.sxtype = ref
             array.item.append(x)
             continue
         x = Factory.property(ref.name, x)
         md = x.__metadata__
         md.sxtype = ref
         array.item.append(x)
     content.value = array
     return self
示例#5
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
示例#6
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
示例#7
0
 def replycomposite(self, rtypes, nodes):
     """
     Construct a I{composite} reply.  This method is called when it has been
     detected that the reply has multiple root nodes.
     @param rtypes: A list of known return I{types}.
     @type rtypes: [L{et_suds.xsd.sxbase.SchemaObject},...]
     @param nodes: A collection of XML nodes.
     @type nodes: [L{Element},...]
     @return: The I{unmarshalled} composite object.
     @rtype: L{Object},...
     """
     dictionary = {}
     for rt in rtypes:
         dictionary[rt.name] = rt
     unmarshaller = self.unmarshaller()
     composite = Factory.object('reply')
     for node in nodes:
         tag = node.name
         rt = dictionary.get(tag, None)
         if rt is None:
             if node.get('id') is None:
                 raise Exception('<%s/> not mapped to message part' % tag)
             else:
                 continue
         resolved = rt.resolve(nobuiltin=True)
         sobject = unmarshaller.process(node, resolved)
         value = getattr(composite, tag, None)
         if value is None:
             if rt.unbounded():
                 value = []
                 setattr(composite, tag, value)
                 value.append(sobject)
             else:
                 setattr(composite, tag, sobject)
         else:
             if not isinstance(value, list):
                 value = [
                     value,
                 ]
                 setattr(composite, tag, value)
             value.append(sobject)
     return composite
示例#8
0
 def replycomposite(self, rtypes, nodes):
     """
     Construct a I{composite} reply.  This method is called when it has been
     detected that the reply has multiple root nodes.
     @param rtypes: A list of known return I{types}.
     @type rtypes: [L{et_suds.xsd.sxbase.SchemaObject},...]
     @param nodes: A collection of XML nodes.
     @type nodes: [L{Element},...]
     @return: The I{unmarshalled} composite object.
     @rtype: L{Object},...
     """
     dictionary = {}
     for rt in rtypes:
         dictionary[rt.name] = rt
     unmarshaller = self.unmarshaller()
     composite = Factory.object('reply')
     for node in nodes:
         tag = node.name
         rt = dictionary.get(tag, None)
         if rt is None:
             if node.get('id') is None:
                 raise Exception('<%s/> not mapped to message part' % tag)
             else:
                 continue
         resolved = rt.resolve(nobuiltin=True)
         sobject = unmarshaller.process(node, resolved)
         value = getattr(composite, tag, None)
         if value is None:
             if rt.unbounded():
                 value = []
                 setattr(composite, tag, value)
                 value.append(sobject)
             else:
                 setattr(composite, tag, sobject)
         else:
             if not isinstance(value, list):
                 value = [value,]
                 setattr(composite, tag, value)
             value.append(sobject)
     return composite
示例#9
0
 def start(self, content):
     #
     # Resolve to the schema type; build an object and setup metadata.
     #
     if content.type is None:
         found = self.resolver.find(content.node)
         if found is None:
             log.error(self.resolver.schema)
             raise TypeNotFound(content.node.qname())
         content.type = found
     else:
         known = self.resolver.known(content.node)
         frame = Frame(content.type, resolved=known)
         self.resolver.push(frame)
     real = self.resolver.top().resolved
     content.real = real
     cls_name = real.name
     if cls_name is None:
         cls_name = content.node.name
     content.data = Factory.object(cls_name)
     md = content.data.__metadata__
     md.sxtype = real
示例#10
0
 def start(self, content):
     #
     # Resolve to the schema type; build an object and setup metadata.
     #
     if content.type is None:
         found = self.resolver.find(content.node)
         if found is None:
             log.error(self.resolver.schema)
             raise TypeNotFound(content.node.qname())
         content.type = found
     else:
         known = self.resolver.known(content.node)
         frame = Frame(content.type, resolved=known)
         self.resolver.push(frame)
     real = self.resolver.top().resolved
     content.real = real
     cls_name = real.name
     if cls_name is None:
         cls_name = content.node.name
     content.data = Factory.object(cls_name)
     md = content.data.__metadata__
     md.sxtype = real
示例#11
0
 def translate(self, content):
     """
     Translate using the XSD type information.
     Python I{dict} is translated to a et_suds object.  Most
     importantly, primative values are translated from python
     types to XML types using the XSD type.
     @param content: The content to translate.
     @type content: L{Object}
     @return: self
     @rtype: L{Typed}
     """
     v = content.value
     if v is None:
         return
     if isinstance(v, dict):
         cls = content.real.name
         content.value = Factory.object(cls, v)
         md = content.value.__metadata__
         md.sxtype = content.type
         return
     v = content.real.translate(v, False)
     content.value = v
     return self
示例#12
0
 def translate(self, content):
     """
     Translate using the XSD type information.
     Python I{dict} is translated to a et_suds object.  Most
     importantly, primative values are translated from python
     types to XML types using the XSD type.
     @param content: The content to translate.
     @type content: L{Object}
     @return: self
     @rtype: L{Typed}
     """
     v = content.value
     if v is None:
         return
     if isinstance(v, dict):
         cls = content.real.name
         content.value = Factory.object(cls, v)
         md = content.value.__metadata__
         md.sxtype = content.type
         return
     v = content.real.translate(v, False)
     content.value = v
     return self
示例#13
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