Exemplo n.º 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
Exemplo n.º 2
0
    def getSubstituteType(self, elt, ps):
        '''if xsi:type does not match the instance type attr,
        check to see if it is a derived type substitution.
        
        DONT Return the element's type.
        
        Parameters:
            elt -- the DOM element being parsed
            ps -- the ParsedSoap object.
        '''
        pyclass = SchemaInstanceType.getTypeDefinition(*self.type)
        if pyclass is None:
            raise EvaluateException(
                    'No Type registed for xsi:type=(%s, %s)' %
                    (self.type[0], self.type[1]), ps.Backtrace(elt))
            
        typeName = _find_type(elt)
        prefix,typeName = SplitQName(typeName)
        uri = ps.GetElementNSdict(elt).get(prefix)
        subclass = SchemaInstanceType.getTypeDefinition(uri, typeName)
        if subclass is None:
            raise EvaluateException(
                    'No registered xsi:type=(%s, %s), substitute for xsi:type=(%s, %s)' %
                    (uri, typeName, self.type[0], self.type[1]), ps.Backtrace(elt))
                    
        if not issubclass(subclass, pyclass) and subclass(None) and not issubclass(subclass, pyclass):
            raise TypeError(
                    'Substitute Type (%s, %s) is not derived from %s' %
                    (self.type[0], self.type[1], pyclass), ps.Backtrace(elt))

        return subclass((self.nspname, self.pname))
Exemplo n.º 3
0
 def get_typeclass(self, msg_type, targetNamespace):
     prefix, name = SplitQName(msg_type)
     if targetNamespace in SCHEMA.XSD_LIST:
         return self._get_xsd_typecode(name)
     elif targetNamespace in [SOAP.ENC]:
         return self._get_soapenc_typecode(name)
     return None
Exemplo n.º 4
0
    def _getType(self, tp, name, literal, local, namespaceURI):
        """Returns a typecode instance representing the passed in type and name.
           tp -- XMLSchema.TypeDefinition instance
           name -- element name
           literal -- literal encoding?
           local -- is locally defined?
           namespaceURI -- namespace
        """
        ofwhat = []
        if not (tp.isDefinition() and tp.isComplex()):
            raise EvaluateException('only supporting complexType definition')
        elif tp.content.isComplex():
            if hasattr(tp.content,
                       'derivation') and tp.content.derivation.isRestriction():
                derived = tp.content.derivation
                typeClass = self._getTypeClass(*derived.getAttribute('base'))
                if typeClass == TC.Array:
                    attrs = derived.attr_content[0].attributes[WSDL.BASE]
                    prefix, localName = SplitQName(attrs['arrayType'])
                    nsuri = derived.attr_content[0].getXMLNS(prefix=prefix)
                    localName = localName.split('[')[0]
                    simpleTypeClass = self._getTypeClass(namespaceURI=nsuri,
                                                         localName=localName)
                    if simpleTypeClass:
                        ofwhat = simpleTypeClass()
                    else:
                        tp = self._wsdl.types[nsuri].types[localName]
                        ofwhat = self._getType(tp=tp,
                                               name=None,
                                               literal=literal,
                                               local=True,
                                               namespaceURI=nsuri)
                else:
                    raise EvaluateException(
                        'only support soapenc:Array restrictions')
                return typeClass(atype=name,
                                 ofwhat=ofwhat,
                                 pname=name,
                                 childNames='item')
            else:
                raise EvaluateException(
                    'complexContent only supported for soapenc:Array derivations'
                )
        elif tp.content.isModelGroup():
            modelGroup = tp.content
            for item in modelGroup.content:
                ofwhat.append(
                    self._getElement(item, literal=literal, local=True))

            tc = TC.Struct(pyclass=None, ofwhat=ofwhat, pname=name)
            if not local:
                self._globalElement(tc,
                                    namespaceURI=namespaceURI,
                                    literal=literal)
            return tc

        raise EvaluateException(
            'only supporting complexType w/ model group, or soapenc:Array restriction'
        )
Exemplo n.º 5
0
def GetModuleBaseNameFromWSDL(wsdl):
    """By default try to construct a reasonable base name for all
    generated modules.  Otherwise return None.
    """
    base_name = wsdl.name or wsdl.services[0].name
    base_name = SplitQName(base_name)[1]
    if base_name is None:
        return None
    return NCName_to_ModuleName(base_name)
Exemplo n.º 6
0
 def get_typeclass(self, msg_type, targetNamespace):
     prefix, name = SplitQName(msg_type)
     if targetNamespace in SCHEMA.XSD_LIST:
         return self._get_xsd_typecode(name)
     elif targetNamespace in [SOAP.ENC]:
         return self._get_soapenc_typecode(name)
     elif targetNamespace in [ZSI.TCapache.Apache.NS]:
         #maybe we have an AXIS attachment
         if name == ZSI.TCapache.AttachmentRef.type[1]:
             #we have an AXIS attachment
             return ZSI.TCapache.AttachmentRef
         else:
             #AXIS Map type
             return TC.AnyType
     return None