Example #1
0
 def bodypart_types(method, schema, input=True):
     """
     This returns the types of a soap body.
     This is basically copied from the suds source code (suds.bindings.binding)
     """
     result = []
     if input:
         parts = method.soap.input.body.parts
     else:
         parts = method.soap.output.body.parts
     for p in parts:
         if p.element is not None:
             query = ElementQuery(p.element)
         else:
             query = TypeQuery(p.type)
         pt = query.execute(schema)
         if pt is None:
             raise TypeNotFound(query.ref)
         if p.type is not None:
             pt = TypeNotFound(p.name, pt)
         if input:
             if pt.name is None:
                 result.append((p.name, pt))
             else:
                 result.append((pt.name, pt))
         else:
             result.append(pt)
     return result
Example #2
0
 def create(self, name):
     """
     create a WSDL type by name
     @param name: The name of a type defined in the WSDL.
     @type name: str
     @return: The requested object.
     @rtype: L{Object}
     """
     timer = metrics.Timer()
     timer.start()
     type = self.resolver.find(name)
     if type is None:
         raise TypeNotFound(name)
     if type.enum():
         result = InstFactory.object(name)
         for e, a in type.children():
             setattr(result, e.name, e.name)
     else:
         try:
             result = self.builder.build(type)
         except Exception as e:
             log.error("create '%s' failed", name, exc_info=True)
             raise BuildError(name, e)
     timer.stop()
     metrics.log.debug('%s created: %s', name, timer)
     return result
Example #3
0
 def bodypart_types(self, method, input=True):
     """
     Get a list of I{parameter definitions} (pdef) defined for the specified
     method.
     Each I{pdef} is a tuple (I{name}, L{xsd.sxbase.SchemaObject})
     @param method: A service method.
     @type method: I{service.Method}
     @param input: Defines input/output message.
     @type input: boolean
     @return:  A list of parameter definitions
     @rtype: [I{pdef},]
     """
     result = []
     if input:
         parts = method.soap.input.body.parts
     else:
         parts = method.soap.output.body.parts
     for p in parts:
         if p.element is not None:
             query = ElementQuery(p.element)
         else:
             query = TypeQuery(p.type)
         pt = query.execute(self.schema())
         if pt is None:
             raise TypeNotFound(query.ref)
         if p.type is not None:
             pt = PartElement(p.name, pt)
         if input:
             if pt.name is None:
                 result.append((p.name, pt))
             else:
                 result.append((pt.name, pt))
         else:
             result.append(pt)
     return result
Example #4
0
 def resolve(self, nobuiltin=False):
     qref = self.qref()
     if qref is None:
         return self
     key = 'resolved:nb=%s' % nobuiltin
     cached = self.cache.get(key)
     if cached is not None:
         return cached
     result = self
     query = TypeQuery(qref)
     query.history = [self]
     log.debug('%s, resolving: %s\n using:%s', self.id, qref, query)
     resolved = query.execute(self.schema)
     if resolved is None:
         log.debug(self.schema)
         raise TypeNotFound(qref)
     self.cache[key] = resolved
     if resolved.builtin():
         if nobuiltin:
             result = self
         else:
             result = resolved
     else:
         result = resolved.resolve(nobuiltin)
     return result
Example #5
0
    def marshal_exception(self, exc, method):

        raise NotImplementedError("cannot yet handle exceptions")

        # The following code is very much unfinished and there is no
        # guaranty that it is correct or even makes sense
        # Currently it finds the fault return types (there should only
        # be one AFAICT). How to get from there and to to a fault body
        # is still open.

        from suds import TypeNotFound
        from suds.bindings.binding import PartElement
        from suds.xsd.query import TypeQuery, ElementQuery

        rtypes = []

        for f in method.unwrapped_.soap.faults:
            for p in f.parts:
                if p.element is not None:
                    query = ElementQuery(p.element)
                else:
                    query = TypeQuery(p.type)
                pt = query.execute(method.binding.output.schema())
                if pt is None:
                    raise TypeNotFound(query.ref)
                if p.type is not None:
                    pt = PartElement(p.name, pt)
                rtypes.append(pt)

        return rtypes
Example #6
0
 def dependencies(self):
     deps = []
     midx = None
     if self.ref is not None:
         query = AttrQuery(self.ref)
         a = query.execute(self.schema)
         if a is None:
             log.debug(self.schema)
             raise TypeNotFound(self.ref)
         deps.append(a)
         midx = 0
     return (midx, deps)
Example #7
0
 def dependencies(self):
     deps = []
     midx = None
     if self.ref is not None:
         query = TypeQuery(self.ref)
         super = query.execute(self.schema)
         if super is None:
             log.debug(self.schema)
             raise TypeNotFound(self.ref)
         if not super.builtin():
             deps.append(super)
             midx = 0
     return (midx, deps)
Example #8
0
 def set_wrapped(self):
     """ set (wrapped|bare) flag on messages """
     for b in self.bindings.values():
         for op in b.operations.values():
             for body in (op.soap.input.body, op.soap.output.body):
                 body.wrapped = False
                 if len(body.parts) != 1:
                     continue
                 for p in body.parts:
                     if p.element is None:
                         continue
                     query = ElementQuery(p.element)
                     pt = query.execute(self.schema)
                     if pt is None:
                         raise TypeNotFound(query.ref)
                     resolved = pt.resolve()
                     if resolved.builtin():
                         continue
                     body.wrapped = True
Example #9
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 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(ref)
     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
Example #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
Example #11
0
 def build(self, name):
     "build 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
Example #12
0
 def start(self, content):
     #
     # Start marshalling the 'content' by ensuring that both the
     # 'content' _and_ the resolver are primed with the XSD type
     # information.  The 'content' value is both translated and
     # sorted based on the XSD type.  Only values that are objects
     # have their attributes sorted.
     #
     log.debug('starting content:\n%s', content)
     if content.type is None:
         name = content.tag
         if name.startswith('_'):
             name = '@' + name[1:]
         content.type = self.resolver.find(name, content.value)
         if content.type is None:
             raise TypeNotFound(content.tag)
     else:
         known = None
         if isinstance(content.value, Object):
             known = self.resolver.known(content.value)
             if known is None:
                 log.debug('object has no type information', content.value)
                 known = content.type
         frame = Frame(content.type, resolved=known)
         self.resolver.push(frame)
     frame = self.resolver.top()
     content.real = frame.resolved
     content.ancestry = frame.ancestry
     self.translate(content)
     self.sort(content)
     if self.skip(content):
         log.debug('skipping (optional) content:\n%s', content)
         self.resolver.pop()
         return False
     else:
         return True