Esempio n. 1
0
 def parse(self, elt, ps):
     self.checkname(elt, ps)
     if self.nilled(elt, ps): return None
     p = self.tc.parse
     if self.aslist:
         v = []
         for c in _child_elements(elt):
             d = p(c, ps)
             v.append((d['key'], d['value']))
     else:
         v = {}
         for c in _child_elements(elt):
             d = p(c, ps)
             v[d['key']] = d['value']
     return v
Esempio n. 2
0
 def parse(self, elt, ps):
     href = _find_href(elt)
     if href:
         if _children(elt):
             raise EvaluateException('Array has content and HREF',
                     ps.Backtrace(elt))
         elt = ps.FindLocalHREF(href, elt)
     if self.nilled(elt, ps): return Nilled
     if not _find_arraytype(elt) and self.undeclared is False:
         raise EvaluateException('Array expected', ps.Backtrace(elt))
     t = _find_type(elt)
     if t:
         pass # XXX should check the type, but parsing that is hairy.
     offset = self.parse_offset(elt, ps)
     v, vlen = [], 0
     if offset and not self.sparse:
         while vlen < offset:
             vlen += 1
             v.append(self.fill)
     for c in _child_elements(elt):
         item = self.ofwhat.parse(c, ps)
         position = self.parse_position(c, ps) or offset
         if self.sparse:
             v.append((position, item))
         else:
             while offset < position:
                 offset += 1
                 v.append(self.fill)
             v.append(item)
         offset += 1
     return v
Esempio n. 3
0
    def Receive(self, replytype, **kw):
        '''Parse message, create Python object.

        KeyWord data:
            faults   -- list of WSDL operation.fault typecodes
            wsaction -- If using WS-Address, must specify Action value we expect to
                receive.
        '''
        self.ReceiveSOAP(**kw)
        ps = self.ps
        tp = _find_type(ps.body_root)
        isarray = ((type(tp) in (tuple,list) and tp[1] == 'Array') or _find_arraytype(ps.body_root))
        if self.typesmodule is None or isarray:
            return _Binding.Receive(self, replytype, **kw)

        if ps.IsAFault():
            msg = FaultFromFaultMessage(ps)
            raise FaultException(msg)

        tc = replytype
        if hasattr(replytype, 'typecode'):
            tc = replytype.typecode

        #Ignore response wrapper
        reply = {}
        for elt in _child_elements(ps.body_root):
            name = str(elt.localName)
            reply[name] = self.__parse_child(elt)

        if self.address is not None:
            self.address.checkResponse(ps, kw.get('wsaction'))

        return reply
Esempio n. 4
0
    def parse(self, elt, ps):
        debug = self.logger.debugOn()
        debug and self.logger.debug('parse')

        xtype = self.checkname(elt, ps)
        if self.type and xtype not in [ self.type, (None,None) ]:
            if not isinstance(self, TypeDefinition):
                raise EvaluateException(\
                    'ComplexType for %s has wrong type(%s), looking for %s' %
                        (self.pname, self.checktype(elt,ps), self.type),
                                        ps.Backtrace(elt))
            else:
                #TODO: mabye change MRO to handle this
                debug and self.logger.debug('delegate to substitute type')
                what = TypeDefinition.getSubstituteType(self, elt, ps)
                return what.parse(elt, ps)

        href = _find_href(elt)
        if href:
            if _children(elt):
                raise EvaluateException('Struct has content and HREF',
                        ps.Backtrace(elt))
            elt = ps.FindLocalHREF(href, elt)
        c = _child_elements(elt)
        count = len(c)
        if self.nilled(elt, ps): return Nilled

        # Create the object.
        v = {}

        # parse all attributes contained in attribute_typecode_dict (user-defined attributes),
        # the values (if not None) will be keyed in self.attributes dictionary.
        attributes = self.parse_attributes(elt, ps)
        if attributes:
            v[self.attrs_aname] = attributes

        #MIXED
        if self.mixed is True:
            v[self.mixed_aname] = self.simple_value(elt,ps, mixed=True)

        # Clone list of kids (we null it out as we process)
        c, crange = c[:], range(len(c))
        # Loop over all items we're expecting

        if debug:
            self.logger.debug("ofwhat: %s",str(self.ofwhat))

        any = None
        for i,what in [ (i, self.ofwhat[i]) for i in range(len(self.ofwhat)) ]:

            # retrieve typecode if it is hidden
            if callable(what): what = what()

            # Loop over all available kids
            if debug:
                self.logger.debug("what: (%s,%s)", what.nspname, what.pname)

            for j,c_elt in [ (j, c[j]) for j in crange if c[j] ]:
                if debug:
                    self.logger.debug("child node: (%s,%s)", c_elt.namespaceURI,
                                      c_elt.tagName)
                if what.name_match(c_elt):
                    # Parse value, and mark this one done.
                    try:
                        value = what.parse(c_elt, ps)
                    except EvaluateException, e:
                        #what = _get_substitute_element(c_elt, what)
                        #value = what.parse(c_elt, ps)
                        raise
                    if what.maxOccurs > 1:
                        if v.has_key(what.aname):
                            v[what.aname].append(value)
                        else:
                            v[what.aname] = [value]
                        c[j] = None
                        continue
                    else:
                        v[what.aname] = value
                    c[j] = None
                    break
                else:
                    if debug:
                        self.logger.debug("no element (%s,%s)",
                                          what.nspname, what.pname)

                # No match; if it was supposed to be here, that's an error.
                if self.inorder is True and i == j:
                    raise EvaluateException('Out of order complexType',
                            ps.Backtrace(c_elt))
            else:
                # only supporting 1 <any> declaration in content.
                if isinstance(what,AnyElement):
                    any = what
                elif hasattr(what, 'default'):
                    v[what.aname] = what.default
                elif what.minOccurs > 0 and not v.has_key(what.aname):
                    raise EvaluateException('Element "' + what.aname + \
                        '" missing from complexType', ps.Backtrace(elt))