Пример #1
0
    def ParseHeaderElements(self, ofwhat):
        '''Returns a dictionary of pyobjs.
        ofhow -- list of typecodes w/matching nspname/pname to the header_elements.
        '''
        d = {}
        lenofwhat = len(ofwhat)
        c, crange = self.header_elements[:], range(len(self.header_elements))
        for i, what in [(i, ofwhat[i]) for i in range(lenofwhat)]:
            if isinstance(what, AnyElement):
                raise EvaluateException, 'not supporting <any> as child of SOAP-ENC:Header'

            v = []
            occurs = 0
            namespaceURI, tagName = what.nspname, what.pname
            for j, c_elt in [(j, c[j]) for j in crange if c[j]]:
                prefix, name = SplitQName(c_elt.tagName)
                nsuri = _resolve_prefix(c_elt, prefix)
                if tagName == name and namespaceURI == nsuri:
                    pyobj = what.parse(c_elt, self)
                else:
                    continue
                v.append(pyobj)
                c[j] = None
            if what.minOccurs > len(v) > what.maxOccurs:
                raise EvaluateException, 'number of occurances(%d) doesnt fit constraints (%d,%s)'\
                    %(len(v),what.minOccurs,what.maxOccurs)
            if what.maxOccurs == 1:
                if len(v) == 0: v = None
                else: v = v[0]
            d[(what.nspname, what.pname)] = v
        return d
Пример #2
0
    def ParseHeaderElements(self, ofwhat):
        """Returns a dictionary of pyobjs.
        ofhow -- list of typecodes w/matching nspname/pname to the header_elements.
        """
        d = {}
        lenofwhat = len(ofwhat)
        c, crange = self.header_elements[:], list(range(len(self.header_elements)))
        for i, what in [(i, ofwhat[i]) for i in range(lenofwhat)]:
            if isinstance(what, AnyElement):
                raise EvaluateException("not supporting <any> as child of SOAP-ENC:Header")

            v = []
            occurs = 0
            namespaceURI, tagName = what.nspname, what.pname
            for j, c_elt in [(j, c[j]) for j in crange if c[j]]:
                prefix, name = SplitQName(c_elt.tagName)
                nsuri = _resolve_prefix(c_elt, prefix)
                if tagName == name and namespaceURI == nsuri:
                    pyobj = what.parse(c_elt, self)
                else:
                    continue
                v.append(pyobj)
                c[j] = None
            if what.minOccurs > len(v) > what.maxOccurs:
                raise EvaluateException(
                    "number of occurances(%d) doesnt fit constraints (%d,%s)" % (len(v), what.minOccurs, what.maxOccurs)
                )
            if what.maxOccurs == 1:
                if len(v) == 0:
                    v = None
                else:
                    v = v[0]
            d[(what.nspname, what.pname)] = v
        return d