예제 #1
0
    def gatherNamespaces(self):
        '''This method must execute once..  Grab all schemas
        representing each targetNamespace.
        '''
        if self.usedNamespaces is not None:
            return

        self.logger.debug('gatherNamespaces')
        self.usedNamespaces = {}
            
        # Add all schemas defined in wsdl
        # to used namespace and to the Alias dict
        for schema in self._wsdl.types.values():
            tns = schema.getTargetNamespace()
            self.logger.debug('Register schema(%s) -- TNS(%s)'\
                %(_get_idstr(schema), tns),)
            if self.usedNamespaces.has_key(tns) is False:
                self.usedNamespaces[tns] = []
            self.usedNamespaces[tns].append(schema)
            NAD.add(tns)
            
        # Add all xsd:import schema instances
        # to used namespace and to the Alias dict
        for k,v in SchemaReader.namespaceToSchema.items():
            self.logger.debug('Register schema(%s) -- TNS(%s)'\
                %(_get_idstr(v), k),)
            if self.usedNamespaces.has_key(k) is False:
                self.usedNamespaces[k] = []
            self.usedNamespaces[k].append(v)
            NAD.add(k)
예제 #2
0
    def gatherNamespaces(self):
        '''This method must execute once..  Grab all schemas
        representing each targetNamespace.
        '''
        if self.usedNamespaces is not None:
            return

        self.logger.debug('gatherNamespaces')
        self.usedNamespaces = {}

        # Add all schemas defined in wsdl
        # to used namespace and to the Alias dict
        for schema in self._wsdl.types.values():
            tns = schema.getTargetNamespace()
            self.logger.debug('Register schema(%s) -- TNS(%s)'\
                %(_get_idstr(schema), tns),)
            if self.usedNamespaces.has_key(tns) is False:
                self.usedNamespaces[tns] = []
            self.usedNamespaces[tns].append(schema)
            NAD.add(tns)

        # Add all xsd:import schema instances
        # to used namespace and to the Alias dict
        for k, v in SchemaReader.namespaceToSchema.items():
            self.logger.debug('Register schema(%s) -- TNS(%s)'\
                %(_get_idstr(v), k),)
            if self.usedNamespaces.has_key(k) is False:
                self.usedNamespaces[k] = []
            self.usedNamespaces[k].append(v)
            NAD.add(k)
예제 #3
0
    def serialize(self, elt, sw, pyobj, name=None, **kw):
        objid = _get_idstr(pyobj)
        n = name or self.pname or ('E' + objid)

        # nillable
        el = elt.createAppendElement(self.nspname, n)
        if self.nillable is True and pyobj is None:
            self.serialize_as_nil(el)
            return None

        # other attributes
        self.set_attributes(el, pyobj)

        # soap href attribute
        unique = self.unique or kw.get('unique', False)
        if unique is False and sw.Known(orig or pyobj):
            self.set_attribute_href(el, objid)
            return None

        # xsi:type attribute
        if kw.get('typed', self.typed) is True:
            self.set_attribute_xsi_type(el, **kw)

        # soap id attribute
        if self.unique is False:
            self.set_attribute_id(el, objid)

        if self.aslist:
            for k, v in pyobj:
                self.tc.serialize(el, sw, {'key': k, 'value': v}, name='item')
        else:
            for k, v in pyobj.items():
                self.tc.serialize(el, sw, {'key': k, 'value': v}, name='item')
예제 #4
0
    def serialize(self, elt, sw, pyobj, name=None, **kw):
        objid = _get_idstr(pyobj)
        n = name or self.pname or ('E' + objid)

        # nillable
        el = elt.createAppendElement(self.nspname, n)
        if self.nillable is True and pyobj is None:
            self.serialize_as_nil(el)
            return None

        # other attributes
        self.set_attributes(el, pyobj)

        # soap href attribute
        unique = self.unique or kw.get('unique', False)
        if unique is False and sw.Known(orig or pyobj):
            self.set_attribute_href(el, objid)
            return None

        # xsi:type attribute 
        if kw.get('typed', self.typed) is True:
            self.set_attribute_xsi_type(el, **kw)

        # soap id attribute
        if self.unique is False:
            self.set_attribute_id(el, objid)

        if self.aslist:
            for k,v in pyobj:
                self.tc.serialize(el, sw, {'key': k, 'value': v}, name='item')
        else:
            for k,v in pyobj.items():
                self.tc.serialize(el, sw, {'key': k, 'value': v}, name='item')
예제 #5
0
 def serialize(self, elt, sw, pyobj, inline=False, name=None, **kw):
     if inline or self.inline:
         self.cb(elt, sw, pyobj, name=name, **kw)
     else:
         objid = _get_idstr(pyobj)
         ns,n = self.get_name(name, objid)
         el = elt.createAppendElement(ns, n)
         el.setAttributeNS(None, 'href', "#%s" %objid)
         sw.AddCallback(self.cb, elt, sw, pyobj)
예제 #6
0
 def serialize(self, elt, sw, pyobj, inline=False, name=None, **kw):
     if inline or self.inline:
         self.cb(elt, sw, pyobj, name=name, **kw)
     else:
         objid = _get_idstr(pyobj)
         ns, n = self.get_name(name, objid)
         el = elt.createAppendElement(ns, n)
         el.setAttributeNS(None, 'href', "#%s" % objid)
         sw.AddCallback(self.cb, elt, sw, pyobj)
예제 #7
0
 def __repr__(self):
     return "<%s instance %s>" % (self.__class__.__name__, _get_idstr(self))
예제 #8
0
 def __str__(self):
     return '%s(%s) nodes( %s )' %(self.__class__, _get_idstr(self), str(self._nodes))
예제 #9
0
 def __str__(self):
     return '%s(%s) POST(%s)' %(self.__class__.__name__, _get_idstr(self), self.post)
예제 #10
0
    def serialize(self, elt, sw, pyobj, name=None, childnames=None, **kw):
        debug = self.logger.debugOn()
        if debug:
            self.logger.debug("serialize: %r" % pyobj)

        if self.mutable is False and sw.Known(pyobj): return
        objid = _get_idstr(pyobj)
        ns, n = self.get_name(name, objid)
        el = elt.createAppendElement(ns, n)

        # nillable
        if self.nillable is True and pyobj is None:
            self.serialize_as_nil(el)
            return None

        # other attributes
        self.set_attributes(el, pyobj)

        # soap href attribute
        unique = self.unique or kw.get('unique', False)
        if unique is False and sw.Known(pyobj):
            self.set_attribute_href(el, objid)
            return None

        # xsi:type attribute
        if kw.get('typed', self.typed) is True:
            self.set_attribute_xsi_type(el, **kw)

        # soap id attribute
        if self.unique is False:
            self.set_attribute_id(el, objid)

        offset = 0
        if self.sparse is False and self.nooffset is False:
            offset, end = 0, len(pyobj)
            while offset < end and pyobj[offset] == self.fill:
                offset += 1
            if offset:
                el.setAttributeNS(SOAP.ENC, 'offset', '[%d]' % offset)

        if self.undeclared is False:
            el.setAttributeNS(
                SOAP.ENC, 'arrayType',
                '%s:%s' % (el.getPrefix(self.atype[0]), self.atype[1]))

        if debug:
            self.logger.debug("ofwhat: %r" % self.ofwhat)

        d = {}
        kn = childnames or self.childnames
        if kn:
            d['name'] = kn
        elif not self.ofwhat.aname:
            d['name'] = 'element'

        if self.sparse is False:
            for e in pyobj[offset:]:
                self.ofwhat.serialize(el, sw, e, **d)
        else:
            position = 0
            for pos, v in pyobj:
                if pos != position:
                    el.setAttributeNS(SOAP.ENC, 'position', '[%d]' % pos)
                    position = pos

                self.ofwhat.serialize(el, sw, v, **d)
                position += 1
예제 #11
0
    def cb(self, elt, sw, pyobj, name=None, **kw):
        debug = self.logger.debugOn()
        if debug:
            self.logger.debug("cb: %s" % str(self.ofwhat))

        objid = _get_idstr(pyobj)
        ns, n = self.get_name(name, objid)
        if pyobj is None:
            if self.nillable is True:
                elem = elt.createAppendElement(ns, n)
                self.serialize_as_nil(elem)
                return
            raise EvaluateException, 'element(%s,%s) is not nillable(%s)' % (
                self.nspname, self.pname, self.nillable)

        if self.mutable is False and sw.Known(pyobj):
            return

        if debug:
            self.logger.debug("element: (%s, %s)", str(ns), n)

        if n is not None:
            elem = elt.createAppendElement(ns, n)
            self.set_attributes(elem, pyobj)
            if kw.get('typed', self.typed) is True:
                self.set_attribute_xsi_type(elem)

            #MIXED For now just stick it in front.
            if self.mixed is True and self.mixed_aname is not None:
                if hasattr(pyobj, self.mixed_aname):
                    textContent = getattr(pyobj, self.mixed_aname)
                    if hasattr(textContent, 'typecode'):
                        textContent.typecode.serialize_text_node(
                            elem, sw, textContent)
                    elif type(textContent) in _stringtypes:
                        if debug:
                            self.logger.debug("mixed text content:\n\t%s",
                                              textContent)
                        elem.createAppendTextNode(textContent)
                    else:
                        raise EvaluateException(
                            'mixed test content in element (%s,%s) must be a string type'
                            % (self.nspname, self.pname), sw.Backtrace(elt))
                else:
                    if debug:
                        self.logger.debug("mixed NO text content in %s",
                                          self.mixed_aname)
        else:
            #For information items w/o tagNames
            #  ie. model groups,SOAP-ENC:Header
            elem = elt

        if self.inline:
            pass
        elif not self.inline and self.unique:
            raise EvaluateException(
                'Not inline, but unique makes no sense. No href/id.',
                sw.Backtrace(elt))
        elif n is not None:
            self.set_attribute_id(elem, objid)

        if self.pyclass and type(self.pyclass) is type:
            f = lambda attr: getattr(pyobj, attr, None)
        elif self.pyclass:
            d = pyobj.__dict__
            f = lambda attr: d.get(attr)
        else:
            d = pyobj
            f = lambda attr: pyobj.get(attr)
            if TypeCode.typechecks and type(d) != types.DictType:
                raise TypeError("Classless complexType didn't get dictionary")

        indx, lenofwhat = 0, len(self.ofwhat)
        if debug:
            self.logger.debug('element declaration (%s,%s)', self.nspname,
                              self.pname)
            if self.type:
                self.logger.debug('xsi:type definition (%s,%s)', self.type[0],
                                  self.type[1])
            else:
                self.logger.warning('NO xsi:type')

        while indx < lenofwhat:
            occurs = 0
            what = self.ofwhat[indx]

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

            if debug:
                self.logger.debug('serialize what -- %s',
                                  what.__class__.__name__)

            # No way to order <any> instances, so just grab any unmatched
            # anames and serialize them.  Only support one <any> in all content.
            # Must be self-describing instances

            # Regular handling of declared elements
            aname = what.aname
            v = f(aname)
            indx += 1
            if what.minOccurs == 0 and v is None:
                continue

            # Default to typecode, if self-describing instance, and check
            # to make sure it is derived from what.
            whatTC = what
            if whatTC.maxOccurs > 1 and v is not None:
                if type(v) not in _seqtypes:
                    raise EvaluateException(
                        'pyobj (%s,%s), aname "%s": maxOccurs %s, expecting a %s'
                        % (self.nspname, self.pname, what.aname,
                           whatTC.maxOccurs, _seqtypes), sw.Backtrace(elt))

                for v2 in v:
                    occurs += 1
                    if occurs > whatTC.maxOccurs:
                        raise EvaluateException(
                            'occurances (%d) exceeded maxOccurs(%d) for <%s>' %
                            (occurs, whatTC.maxOccurs, what.pname),
                            sw.Backtrace(elt))

                    what = _get_type_or_substitute(whatTC, v2, sw, elt)
                    if debug and what is not whatTC:
                        self.logger.debug('substitute derived type: %s' %
                                          what.__class__)

                    what.serialize(elem, sw, v2, **kw)


#                    try:
#                        what.serialize(elem, sw, v2, **kw)
#                    except Exception, e:
#                        raise EvaluateException('Serializing %s.%s, %s %s' %
#                            (n, whatTC.aname or '?', e.__class__.__name__, str(e)))

                if occurs < whatTC.minOccurs:
                    raise EvaluateException(\
                        'occurances(%d) less than minOccurs(%d) for <%s>' %
                        (occurs, whatTC.minOccurs, what.pname), sw.Backtrace(elt))

                continue

            if v is not None or what.nillable is True:
                what = _get_type_or_substitute(whatTC, v, sw, elt)
                if debug and what is not whatTC:
                    self.logger.debug('substitute derived type: %s' %
                                      what.__class__)
                what.serialize(elem, sw, v, **kw)
                #                try:
                #                    what.serialize(elem, sw, v, **kw)
                #                except (ParseException, EvaluateException), e:
                #                    raise
                #                except Exception, e:
                #                    raise EvaluateException('Serializing %s.%s, %s %s' %
                #                        (n, whatTC.aname or '?', e.__class__.__name__, str(e)),
                #                        sw.Backtrace(elt))
                continue

            raise EvaluateException(
                'Got None for nillable(%s), minOccurs(%d) element (%s,%s), %s'
                % (what.nillable, what.minOccurs, what.nspname, what.pname,
                   elem), sw.Backtrace(elt))
예제 #12
0
    def serialize(self, elt, sw, pyobj, name=None, childnames=None, **kw):
        debug = self.logger.debugOn()
        if debug:
            self.logger.debug("serialize: %r" %pyobj)
        
        if self.mutable is False and sw.Known(pyobj): return
        objid = _get_idstr(pyobj)
        ns,n = self.get_name(name, objid)
        el = elt.createAppendElement(ns, n)

        # nillable
        if self.nillable is True and pyobj is None:
            self.serialize_as_nil(el)
            return None

        # other attributes
        self.set_attributes(el, pyobj)

        # soap href attribute
        unique = self.unique or kw.get('unique', False)
        if unique is False and sw.Known(pyobj):
            self.set_attribute_href(el, objid)
            return None

        # xsi:type attribute 
        if kw.get('typed', self.typed) is True:
            self.set_attribute_xsi_type(el, **kw)

        # soap id attribute
        if self.unique is False:
            self.set_attribute_id(el, objid)

        offset = 0
        if self.sparse is False and self.nooffset is False:
            offset, end = 0, len(pyobj)
            while offset < end and pyobj[offset] == self.fill:
                offset += 1
            if offset: 
                el.setAttributeNS(SOAP.ENC, 'offset', '[%d]' %offset)

        if self.undeclared is False:
            el.setAttributeNS(SOAP.ENC, 'arrayType', 
                '%s:%s' %(el.getPrefix(self.atype[0]), self.atype[1])
            )

        if debug:
            self.logger.debug("ofwhat: %r" %self.ofwhat)

        d = {}
        kn = childnames or self.childnames
        if kn:
            d['name'] = kn
        elif not self.ofwhat.aname:
            d['name'] = 'element'
            
        if self.sparse is False:
            for e in pyobj[offset:]: self.ofwhat.serialize(el, sw, e, **d)
        else:
            position = 0
            for pos, v in pyobj:
                if pos != position:
                    el.setAttributeNS(SOAP.ENC, 'position', '[%d]' %pos)
                    position = pos

                self.ofwhat.serialize(el, sw, v, **d)
                position += 1
예제 #13
0
 def __init__(self, module=__name__):
     self.logger = logging.getLogger('%s-%s(%s)' %(module, self.__class__, _get_idstr(self)))
예제 #14
0
 def __repr__(self):
     return "<%s.Fault at %s>" % (__name__, _get_idstr(self))
예제 #15
0
    def cb(self, elt, sw, pyobj, name=None, **kw):
        debug = self.logger.debugOn()
        if debug:
            self.logger.debug("cb: %s" %str(self.ofwhat))

        objid = _get_idstr(pyobj)
        ns,n = self.get_name(name, objid)
        if pyobj is None:
            if self.nillable is True:
                elem = elt.createAppendElement(ns, n)
                self.serialize_as_nil(elem)
                return
            raise EvaluateException, 'element(%s,%s) is not nillable(%s)' %(
                self.nspname,self.pname,self.nillable)

        if self.mutable is False and sw.Known(pyobj): 
            return
        
        if debug:
            self.logger.debug("element: (%s, %s)", str(ns), n)
            
        if n is not None:
            elem = elt.createAppendElement(ns, n)
            self.set_attributes(elem, pyobj)
            if kw.get('typed', self.typed) is True:
                self.set_attribute_xsi_type(elem)

            #MIXED For now just stick it in front.
            if self.mixed is True and self.mixed_aname is not None:
               if hasattr(pyobj, self.mixed_aname):
                   textContent = getattr(pyobj, self.mixed_aname)
                   if hasattr(textContent, 'typecode'):
                       textContent.typecode.serialize_text_node(elem, sw, textContent)
                   elif type(textContent) in _stringtypes:
                       if debug:
                           self.logger.debug("mixed text content:\n\t%s", 
                                             textContent)
                       elem.createAppendTextNode(textContent)
                   else:
                       raise EvaluateException('mixed test content in element (%s,%s) must be a string type' %(
                           self.nspname,self.pname), sw.Backtrace(elt))
               else:
                   if debug:
                       self.logger.debug("mixed NO text content in %s", 
                                         self.mixed_aname)
        else:
            #For information items w/o tagNames 
            #  ie. model groups,SOAP-ENC:Header
            elem = elt

        if self.inline:
            pass
        elif not self.inline and self.unique:
            raise EvaluateException('Not inline, but unique makes no sense. No href/id.',
                sw.Backtrace(elt))
        elif n is not None:
            self.set_attribute_id(elem, objid)

        if self.pyclass and type(self.pyclass) is type:
            f = lambda attr: getattr(pyobj, attr, None)
        elif self.pyclass:
            d = pyobj.__dict__
            f = lambda attr: d.get(attr)
        else:
            d = pyobj
            f = lambda attr: pyobj.get(attr)
            if TypeCode.typechecks and type(d) != types.DictType:
                raise TypeError("Classless complexType didn't get dictionary")

        indx, lenofwhat = 0, len(self.ofwhat)
        if debug:
            self.logger.debug('element declaration (%s,%s)', self.nspname, 
                              self.pname)
            if self.type:
                self.logger.debug('xsi:type definition (%s,%s)', self.type[0], 
                                  self.type[1])
            else:
                self.logger.warning('NO xsi:type')

        while indx < lenofwhat:
            occurs = 0
            what = self.ofwhat[indx]
            
            # retrieve typecode if hidden
            if callable(what): what = what()
            
            if debug:
                self.logger.debug('serialize what -- %s', 
                                  what.__class__.__name__)

            # No way to order <any> instances, so just grab any unmatched
            # anames and serialize them.  Only support one <any> in all content.
            # Must be self-describing instances

            # Regular handling of declared elements
            aname = what.aname
            v = f(aname)
            indx += 1
            if what.minOccurs == 0 and v is None: 
                continue

            # Default to typecode, if self-describing instance, and check 
            # to make sure it is derived from what.
            whatTC = what
            if whatTC.maxOccurs > 1 and v is not None:
                if type(v) not in _seqtypes:
                    raise EvaluateException('pyobj (%s,%s), aname "%s": maxOccurs %s, expecting a %s' %(
                         self.nspname,self.pname,what.aname,whatTC.maxOccurs,_seqtypes), 
                         sw.Backtrace(elt))

                for v2 in v: 
                    occurs += 1
                    if occurs > whatTC.maxOccurs:
                        raise EvaluateException('occurances (%d) exceeded maxOccurs(%d) for <%s>' %(
                                occurs, whatTC.maxOccurs, what.pname), 
                                sw.Backtrace(elt))
                        
                    what = _get_type_or_substitute(whatTC, v2, sw, elt)
                    if debug and what is not whatTC:
                        self.logger.debug('substitute derived type: %s' %
                                          what.__class__)
                        
                    what.serialize(elem, sw, v2, **kw)
#                    try:
#                        what.serialize(elem, sw, v2, **kw)
#                    except Exception, e:
#                        raise EvaluateException('Serializing %s.%s, %s %s' %
#                            (n, whatTC.aname or '?', e.__class__.__name__, str(e)))

                if occurs < whatTC.minOccurs:
                    raise EvaluateException(\
                        'occurances(%d) less than minOccurs(%d) for <%s>' %
                        (occurs, whatTC.minOccurs, what.pname), sw.Backtrace(elt))
                    
                continue

            if v is not None or what.nillable is True:
                what = _get_type_or_substitute(whatTC, v, sw, elt)
                if debug and what is not whatTC:
                    self.logger.debug('substitute derived type: %s' %
                                      what.__class__)
                what.serialize(elem, sw, v, **kw)
#                try:
#                    what.serialize(elem, sw, v, **kw)
#                except (ParseException, EvaluateException), e:
#                    raise
#                except Exception, e:
#                    raise EvaluateException('Serializing %s.%s, %s %s' %
#                        (n, whatTC.aname or '?', e.__class__.__name__, str(e)),
#                        sw.Backtrace(elt))
                continue

            raise EvaluateException('Got None for nillable(%s), minOccurs(%d) element (%s,%s), %s' %
                    (what.nillable, what.minOccurs, what.nspname, what.pname, elem),
                    sw.Backtrace(elt))
예제 #16
0
 def __repr__(self):
     return "<%s.ZSIFaultDetail %s>" % (__name__, _get_idstr(self))
예제 #17
0
 def __repr__(self):
     return "<%s.Fault at %s>" % (__name__, _get_idstr(self))
예제 #18
0
 def __str__(self):
     return '%s(%s) nodes( %s )' % (self.__class__, _get_idstr(self),
                                    str(self._nodes))
예제 #19
0
 def __str__(self):
     return '%s(%s) POST(%s)' % (self.__class__.__name__, _get_idstr(self),
                                 self.post)
예제 #20
0
 def __repr__(self):
     return "<%s.ZSIFaultDetail %s>" % (__name__, _get_idstr(self))