Example #1
0
    def dumper(self, nsURI, obj_type, obj, tag, typed = 1, ns_map = {},
               rootattr = '', id = '',
               xml = '<%(tag)s%(type)s%(id)s%(attrs)s%(root)s>%(data)s</%(tag)s>\n'):
        if self.config.debug: print "In dumper."

        if nsURI == None:
            nsURI = self.config.typesNamespaceURI

        tag = tag or self.gentag()

        tag = toXMLname(tag) # convert from SOAP 1.2 XML name encoding

        a = n = t = ''
        if typed and obj_type:
            ns, n = self.genns(ns_map, nsURI)
            ins = self.genns(ns_map, self.config.schemaNamespaceURI)[0]
            t = ' %stype="%s%s"%s' % (ins, ns, obj_type, n)

        try: a = obj._marshalAttrs(ns_map, self)
        except: pass

        try: data = obj._marshalData()
        except:
            if (obj_type != "string"): # strings are already encoded
                data = cgi.escape(str(obj))
            else:
                data = obj



        return xml % {"tag": tag, "type": t, "data": data, "root": rootattr,
            "id": id, "attrs": a}
Example #2
0
    def dump_float(self, obj, tag, typed=1, ns_map={}):
        if self.config.debug:
            print "In dump_float."
        tag = tag or self.gentag()
        tag = toXMLname(tag)  # convert from SOAP 1.2 XML name encoding

        if self.config.strict_range:
            doubleType(obj)

        if PosInf == obj:
            obj = "INF"
        elif NegInf == obj:
            obj = "-INF"
        elif NaN == obj:
            obj = "NaN"
        else:
            obj = repr(obj)

        # Note: python 'float' is actually a SOAP 'double'.
        self.out.append(
            self.dumper(None, "double", obj, tag, typed, ns_map,
                        self.genroot(ns_map)))

        if self.config.debug:
            print "dump_float: self.out =", str(self.out)
Example #3
0
    def dump_dictionary(self, obj, tag, typed=1, ns_map={}):
        if self.config.debug:
            print "In dump_dictionary."
        tag = tag or self.gentag()
        tag = toXMLname(tag)  # convert from SOAP 1.2 XML name encoding

        id = self.checkref(obj, tag, ns_map)
        if id is None:
            return

        try:
            a = obj._marshalAttrs(ns_map, self)
        except Exception:
            a = ''

        self.out.append('<%s%s%s%s>\n' % (tag, id, a, self.genroot(ns_map)))

        if self.config.debug:
            print "dump_dictionary -- self.out 1 =", str(self.out)

        for (k, v) in obj.items():
            if k[0] != "_":
                self.dump(v, k, 1, ns_map)

        self.out.append('</%s>\n' % tag)

        if self.config.debug:
            print "dump_dictionary: self.out 2 =", str(self.out)
    def dumper(self, nsURI, obj_type, obj, tag, typed = 1, ns_map = {},
               rootattr = '', id = '',
               xml = '<%(tag)s%(type)s%(id)s%(attrs)s%(root)s>%(data)s</%(tag)s>\n'):
        if Config.debug: print "In dumper."

        if nsURI == None:
            nsURI = self.config.typesNamespaceURI

        tag = tag or self.gentag()

        tag = toXMLname(tag) # convert from SOAP 1.2 XML name encoding

        a = n = t = ''
        if typed and obj_type:
            ns, n = self.genns(ns_map, nsURI)
            ins = self.genns(ns_map, self.config.schemaNamespaceURI)[0]
            t = ' %stype="%s%s"%s' % (ins, ns, obj_type, n)

        try: a = obj._marshalAttrs(ns_map, self)
        except: pass

        try: data = obj._marshalData()
        except:
            if (obj_type != "string"): # strings are already encoded
                data = cgi.escape(str(obj))
            else:
                data = obj


        return xml % {"tag": tag, "type": t, "data": data, "root": rootattr,
            "id": id, "attrs": a}
Example #5
0
    def dump_None(self, obj, tag, typed = 0, ns_map = {}):
        if self.config.debug: print "In dump_None."
        tag = tag or self.gentag()
        tag = toXMLname(tag) # convert from SOAP 1.2 XML name encoding
        ns = self.genns(ns_map, self.config.schemaNamespaceURI)[0]

        self.out.append('<%s %snull="1"%s/>\n' %
                        (tag, ns, self.genroot(ns_map)))
Example #6
0
    def dump_None(self, obj, tag, typed=0, ns_map={}):
        if Config.debug: print "In dump_None."
        tag = tag or self.gentag()
        tag = toXMLname(tag)  # convert from SOAP 1.2 XML name encoding
        ns = self.genns(ns_map, self.config.schemaNamespaceURI)[0]

        self.out.append('<%s %snull="1"%s/>\n' %
                        (tag, ns, self.genroot(ns_map)))
Example #7
0
    def dump_string(self, obj, tag, typed = 0, ns_map = {}):
        if self.config.debug: print "In dump_string."
        tag = tag or self.gentag()
        tag = toXMLname(tag) # convert from SOAP 1.2 XML name encoding

        id = self.checkref(obj, tag, ns_map)
        if id == None:
            return

        try: data = obj._marshalData()
        except: data = obj

        self.out.append(self.dumper(None, "string", cgi.escape(data), tag,
                                    typed, ns_map, self.genroot(ns_map), id))
    def dump_string(self, obj, tag, typed = 0, ns_map = {}):
        if Config.debug: print "In dump_string."
        tag = tag or self.gentag()
        tag = toXMLname(tag) # convert from SOAP 1.2 XML name encoding

        id = self.checkref(obj, tag, ns_map)
        if id == None:
            return

        try: data = obj._marshalData()
        except: data = obj

        self.out.append(self.dumper(None, "string", cgi.escape(data), tag,
                                    typed, ns_map, self.genroot(ns_map), id))
Example #9
0
    def dump_map(self, obj, tag, typed=1, ns_map={}):
        if self.config.debug:
            print "In dump_map.", "obj=", obj
        tag = tag or self.gentag()
        tag = toXMLname(tag)  # convert from SOAP 1.2 XML name encoding

        if type(obj) == InstanceType:
            data = obj.data
        else:
            data = obj

        if typed:
            id = self.checkref(obj, tag, ns_map)
            if id is None:
                return

        try:
            a = obj._marshalAttrs(ns_map, self)
        except Exception:
            a = ''

        ndecl = ''
        ens, edecl = self.genns(ns_map, 'http://xml.apache.org/xml-soap')
        ins, idecl = self.genns(ns_map, self.config.schemaNamespaceURI)

        if typed:
            self.out.append('<%s %stype="%sMap"%s%s%s%s%s%s>\n' %
                            (tag, ins, ens, ndecl, edecl, idecl,
                             self.genroot(ns_map), id, a))

            try:
                elemsname = obj._elemsname
            except Exception:
                elemsname = "item"
        else:
            elemsname = tag

        if isinstance(data, (list, tuple, arrayType)):
            should_drill = True
        else:
            should_drill = not same_type

        for i in data:
            self.dump(i, elemsname, should_drill, ns_map)

        if typed:
            self.out.append('</%s>\n' % tag)
        if self.config.debug:
            print "dump_map: self.out =", str(self.out)
Example #10
0
    def dump_dictionary(self, obj, tag, typed = 1, ns_map = {}):
        if Config.debug: print "In dump_dictionary."
        tag = tag or self.gentag()
        tag = toXMLname(tag) # convert from SOAP 1.2 XML name encoding
        id = self.checkref(obj, tag, ns_map)
        if id == None:
            return
        try: a = obj._marshalAttrs(ns_map, self)
        except: a = ''
        self.out.append('<%s%s%s%s>\n' % 
                        (tag, id, a, self.genroot(ns_map)))
        for (k, v) in obj.items():
            if k[0] != "_":
	        self.dump(v,k,1, ns_map)
		
        self.out.append('</%s>\n' % tag)
Example #11
0
    def dump_map(self, obj, tag, typed=1, ns_map={}):
        if self.config.debug: print "In dump_map.", "obj=", obj
        tag = tag or self.gentag()
        tag = toXMLname(tag)  # convert from SOAP 1.2 XML name encoding

        if type(obj) == InstanceType:
            data = obj.data
        else:
            data = obj

        if typed:
            id = self.checkref(obj, tag, ns_map)
            if id == None:
                return

        try:
            a = obj._marshalAttrs(ns_map, self)
        except:
            a = ''

        ndecl = ''
        ens, edecl = self.genns(ns_map, 'http://xml.apache.org/xml-soap')
        ins, idecl = self.genns(ns_map, self.config.schemaNamespaceURI)

        if typed:
            self.out.append('<%s %stype="%sMap"%s%s%s%s%s%s>\n' %
                            (tag, ins, ens, ndecl, edecl, idecl,
                             self.genroot(ns_map), id, a))

            try:
                elemsname = obj._elemsname
            except:
                elemsname = "item"
        else:
            elemsname = tag

        if isinstance(data, (list, tuple, arrayType)):
            should_drill = True
        else:
            should_drill = not same_type

        for i in data:
            self.dump(i, elemsname, should_drill, ns_map)

        if typed: self.out.append('</%s>\n' % tag)
Example #12
0
    def dump_float(self, obj, tag, typed = 1, ns_map = {}):
        if self.config.debug: print "In dump_float."
        tag = tag or self.gentag()

        tag = toXMLname(tag) # convert from SOAP 1.2 XML name encoding

        if self.config.strict_range:
            doubleType(obj)

        if PosInf == obj:
            obj = "INF"
        elif NegInf == obj:
            obj = "-INF"
        elif NaN == obj:
            obj = "NaN"
        else:
            obj = repr(obj)

        # Note: python 'float' is actually a SOAP 'double'.
        self.out.append(self.dumper(
            None, "double", obj, tag, typed, ns_map, self.genroot(ns_map)))
Example #13
0
    def dump_list(self, obj, tag, typed = 1, ns_map = {}):
        if self.config.debug: print "In dump_list.",  "obj=", obj
        tag = tag or self.gentag()
        tag = toXMLname(tag) # convert from SOAP 1.2 XML name encoding

        if type(obj) == InstanceType or isinstance(obj, anyType):
            data = obj.data
        else:
            data = obj

        if typed:
            id = self.checkref(obj, tag, ns_map)
            if id == None:
                return

        try:
            sample = data[0]
            empty = 0
        except:
            # preserve type if present
            if getattr(obj,"_typed",None) and getattr(obj,"_type",None):
                if getattr(obj, "_complexType", None):
                    sample = typedArrayType(typed=obj._type,
                                            complexType = obj._complexType)
                    sample._typename = obj._type
                    if not getattr(obj,"_ns",None): obj._ns = NS.URN
                else:
                    sample = typedArrayType(typed=obj._type)
            else:
                sample = structType()
            empty = 1

        # First scan list to see if all are the same type
        same_type = 1

        if not empty:
            for i in data[1:]:
                if type(sample) != type(i) or \
                    (type(sample) == InstanceType and \
                        sample.__class__ != i.__class__):
                    same_type = 0
                    break

        ndecl = ''
        if same_type:
            if (isinstance(sample, structType)) or \
                   type(sample) == DictType or \
                   (isinstance(sample, anyType) and \
                    (getattr(sample, "_complexType", None) and \
                     sample._complexType)): # force to urn struct
                try:
                    tns = obj._ns or NS.URN
                except:
                    tns = NS.URN

                ns, ndecl = self.genns(ns_map, tns)

                try:
                    typename = sample._typename
                except:
                    typename = "SOAPStruct"

                t = ns + typename
                                
            elif isinstance(sample, anyType):
                ns = sample._validNamespaceURI(self.config.typesNamespaceURI,
                                               self.config.strictNamespaces)
                if ns:
                    ns, ndecl = self.genns(ns_map, ns)
                    t = ns + str(sample._type)
                else:
                    t = 'ur-type'
            else:
                typename = type(sample).__name__

                # For Python 2.2+
                if type(sample) == StringType: typename = 'string'

                # HACK: unicode is a SOAP string
                if type(sample) == UnicodeType: typename = 'string'
                
                # HACK: python 'float' is actually a SOAP 'double'.
                if typename=="float": typename="double"  
                t = self.genns(
                ns_map, self.config.typesNamespaceURI)[0] + typename

        else:
            t = self.genns(ns_map, self.config.typesNamespaceURI)[0] + \
                "ur-type"

        try: a = obj._marshalAttrs(ns_map, self)
        except: a = ''

        ens, edecl = self.genns(ns_map, NS.ENC)
        ins, idecl = self.genns(ns_map, self.config.schemaNamespaceURI)

        if typed:
            self.out.append(
                '<%s %sarrayType="%s[%d]" %stype="%sArray"%s%s%s%s%s%s>\n' %
                (tag, ens, t, len(data), ins, ens, ndecl, edecl, idecl,
                 self.genroot(ns_map), id, a))

        if typed:
            try: elemsname = obj._elemsname
            except: elemsname = "item"
        else:
            elemsname = tag
            
        if isinstance(data, (list, tuple, arrayType)):
            should_drill = True
        else:
            should_drill = not same_type
        
        for i in data:
            self.dump(i, elemsname, should_drill, ns_map)

        if typed: self.out.append('</%s>\n' % tag)
Example #14
0
    def dump_instance(self, obj, tag, typed = 1, ns_map = {}):
        if Config.debug: print "In dump_instance.", "obj=", obj, "tag=", tag
        if not tag:
            # If it has a name use it.
            if isinstance(obj, anyType) and obj._name:
                tag = obj._name
            else:
                tag = self.gentag()
        tag = toXMLname(tag) # convert from SOAP 1.2 XML name encoding

        if isinstance(obj, arrayType):      # Array
            self.dump_list(obj, tag, typed, ns_map)
            return

        if isinstance(obj, faultType):    # Fault
            cns, cdecl = self.genns(ns_map, NS.ENC)
            vns, vdecl = self.genns(ns_map, NS.ENV)
            self.out.append('''<%sFault %sroot="1"%s%s>
<faultcode>%s</faultcode>
<faultstring>%s</faultstring>
''' % (vns, cns, vdecl, cdecl, obj.faultcode, obj.faultstring))
            if hasattr(obj, "detail"):
                self.dump(obj.detail, "detail", typed, ns_map)
            self.out.append("</%sFault>\n" % vns)
            return

        r = self.genroot(ns_map)

        try: a = obj._marshalAttrs(ns_map, self)
        except: a = ''

        if isinstance(obj, voidType):     # void
            self.out.append("<%s%s%s></%s>\n" % (tag, a, r, tag))
            return

        id = self.checkref(obj, tag, ns_map)
        if id == None:
            return

        if isinstance(obj, structType):
            # Check for namespace
            ndecl = ''
            ns = obj._validNamespaceURI(self.config.typesNamespaceURI,
                self.config.strictNamespaces)
            if ns:
                ns, ndecl = self.genns(ns_map, ns)
                tag = ns + tag
            self.out.append("<%s%s%s%s%s>\n" % (tag, ndecl, id, a, r))

            keylist = obj.__dict__.keys()

            # first write out items with order information
            if hasattr(obj, '_keyord'):
                for i in range(len(obj._keyord)):
                    self.dump(obj._aslist(i), obj._keyord[i], 1, ns_map)
                    keylist.remove(obj._keyord[i])

            # now write out the rest
            for k in keylist:
                if (k[0] != "_"):
                    self.dump(getattr(obj,k), k, 1, ns_map)

            if isinstance(obj, bodyType):
                self.multis = 1

                for v, k in self.multirefs:
                    self.dump(v, k, typed = typed, ns_map = ns_map)

            self.out.append('</%s>\n' % tag)

        elif isinstance(obj, anyType):
            t = ''

            if typed:
                ns = obj._validNamespaceURI(self.config.typesNamespaceURI,
                    self.config.strictNamespaces)
                if ns:
                    ons, ondecl = self.genns(ns_map, ns)
                    ins, indecl = self.genns(ns_map,
                        self.config.schemaNamespaceURI)
                    t = ' %stype="%s%s"%s%s' % \
                        (ins, ons, obj._type, ondecl, indecl)

            self.out.append('<%s%s%s%s%s>%s</%s>\n' %
                            (tag, t, id, a, r, obj._marshalData(), tag))

        else:                           # Some Class
            self.out.append('<%s%s%s>\n' % (tag, id, r))

            for (k, v) in obj.__dict__.items():
                if k[0] != "_":
                    self.dump(v, k, 1, ns_map)

            self.out.append('</%s>\n' % tag)
Example #15
0
    def dump_instance(self, obj, tag, typed=1, ns_map={}):
        if Config.debug: print "In dump_instance.", "obj=", obj, "tag=", tag
        if not tag:
            # If it has a name use it.
            if isinstance(obj, anyType) and obj._name:
                tag = obj._name
            else:
                tag = self.gentag()
        tag = toXMLname(tag)  # convert from SOAP 1.2 XML name encoding

        if isinstance(obj, arrayType):  # Array
            self.dump_list(obj, tag, typed, ns_map)
            return

        if isinstance(obj, faultType):  # Fault
            cns, cdecl = self.genns(ns_map, NS.ENC)
            vns, vdecl = self.genns(ns_map, NS.ENV)
            self.out.append('''<%sFault %sroot="1"%s%s>
<faultcode>%s</faultcode>
<faultstring>%s</faultstring>
''' % (vns, cns, vdecl, cdecl, obj.faultcode, obj.faultstring))
            if hasattr(obj, "detail"):
                self.dump(obj.detail, "detail", typed, ns_map)
            self.out.append("</%sFault>\n" % vns)
            return

        r = self.genroot(ns_map)

        try:
            a = obj._marshalAttrs(ns_map, self)
        except:
            a = ''

        if isinstance(obj, voidType):  # void
            self.out.append("<%s%s%s></%s>\n" % (tag, a, r, tag))
            return

        id = self.checkref(obj, tag, ns_map)
        if id == None:
            return

        if isinstance(obj, structType):
            # Check for namespace
            ndecl = ''
            ns = obj._validNamespaceURI(self.config.typesNamespaceURI,
                                        self.config.strictNamespaces)
            if ns:
                ns, ndecl = self.genns(ns_map, ns)
                tag = ns + tag
            self.out.append("<%s%s%s%s%s>\n" % (tag, ndecl, id, a, r))

            keylist = obj.__dict__.keys()

            # first write out items with order information
            if hasattr(obj, '_keyord'):
                for i in range(len(obj._keyord)):
                    self.dump(obj._aslist(i), obj._keyord[i], 1, ns_map)
                    keylist.remove(obj._keyord[i])

            # now write out the rest
            for k in keylist:
                if (k[0] != "_"):
                    self.dump(getattr(obj, k), k, 1, ns_map)

            if isinstance(obj, bodyType):
                self.multis = 1

                for v, k in self.multirefs:
                    self.dump(v, k, typed=typed, ns_map=ns_map)

            self.out.append('</%s>\n' % tag)

        elif isinstance(obj, anyType):
            t = ''

            if typed:
                ns = obj._validNamespaceURI(self.config.typesNamespaceURI,
                                            self.config.strictNamespaces)
                if ns:
                    ons, ondecl = self.genns(ns_map, ns)
                    ins, indecl = self.genns(ns_map,
                                             self.config.schemaNamespaceURI)
                    t = ' %stype="%s%s"%s%s' % \
                        (ins, ons, obj._type, ondecl, indecl)

            self.out.append('<%s%s%s%s%s>%s</%s>\n' %
                            (tag, t, id, a, r, obj._marshalData(), tag))

        else:  # Some Class
            self.out.append('<%s%s%s>\n' % (tag, id, r))

            for (k, v) in obj.__dict__.items():
                if k[0] != "_":
                    self.dump(v, k, 1, ns_map)

            self.out.append('</%s>\n' % tag)
Example #16
0
    def dump_list(self, obj, tag, typed=1, ns_map={}):
        if Config.debug: print "In dump_list.", "obj=", obj
        tag = tag or self.gentag()
        tag = toXMLname(tag)  # convert from SOAP 1.2 XML name encoding

        if type(obj) == InstanceType:
            data = obj.data
        else:
            data = obj

        if typed:
            id = self.checkref(obj, tag, ns_map)
            if id == None:
                return

        try:
            sample = data[0]
            empty = 0
        except:
            # preserve type if present
            if getattr(obj, "_typed", None) and getattr(obj, "_type", None):
                if getattr(obj, "_complexType", None):
                    sample = typedArrayType(typed=obj._type,
                                            complexType=obj._complexType)
                    sample._typename = obj._type
                    if not getattr(obj, "_ns", None): obj._ns = NS.URN
                else:
                    sample = typedArrayType(typed=obj._type)
            else:
                sample = structType()
            empty = 1

        # First scan list to see if all are the same type
        same_type = 1

        if not empty:
            for i in data[1:]:
                if type(sample) != type(i) or \
                    (type(sample) == InstanceType and \
                        sample.__class__ != i.__class__):
                    same_type = 0
                    break

        ndecl = ''
        if same_type:
            if (isinstance(sample, structType)) or \
                   type(sample) == DictType or \
                   (isinstance(sample, anyType) and \
                    (getattr(sample, "_complexType", None) and \
                     sample._complexType)): # force to urn struct
                try:
                    tns = obj._ns or NS.URN
                except:
                    tns = NS.URN

                ns, ndecl = self.genns(ns_map, tns)

                try:
                    typename = sample._typename
                except:
                    typename = "SOAPStruct"

                t = ns + typename

            elif isinstance(sample, anyType):
                ns = sample._validNamespaceURI(self.config.typesNamespaceURI,
                                               self.config.strictNamespaces)
                if ns:
                    ns, ndecl = self.genns(ns_map, ns)
                    t = ns + str(sample._type)
                else:
                    t = 'ur-type'
            else:
                typename = type(sample).__name__

                # For Python 2.2+
                if type(sample) == StringType: typename = 'string'

                # HACK: unicode is a SOAP string
                if type(sample) == UnicodeType: typename = 'string'

                # HACK: python 'float' is actually a SOAP 'double'.
                if typename == "float": typename = "double"
                t = self.genns(ns_map, self.config.typesNamespaceURI)[0] + \
      typename

        else:
            t = self.genns(ns_map, self.config.typesNamespaceURI)[0] + \
                "ur-type"

        try:
            a = obj._marshalAttrs(ns_map, self)
        except:
            a = ''

        ens, edecl = self.genns(ns_map, NS.ENC)
        ins, idecl = self.genns(ns_map, self.config.schemaNamespaceURI)

        if typed:
            self.out.append(
                '<%s %sarrayType="%s[%d]" %stype="%sArray"%s%s%s%s%s%s>\n' %
                (tag, ens, t, len(data), ins, ens, ndecl, edecl, idecl,
                 self.genroot(ns_map), id, a))

        if typed:
            try:
                elemsname = obj._elemsname
            except:
                elemsname = "item"
        else:
            elemsname = tag

        for i in data:
            self.dump(i, elemsname, not same_type, ns_map)

        if typed: self.out.append('</%s>\n' % tag)