source: trunk/suds/__init__.py @ 536

Revision 536, 4.2 KB checked in by jortel, 5 years ago (diff)

Modify marshaller to set xsi:type attribute on doc/lit services only for types derived by extension and not longer by restriction.

Line 
1# This program is free software; you can redistribute it and/or modify
2# it under the terms of the (LGPL) GNU Lesser General Public License as
3# published by the Free Software Foundation; either version 3 of the
4# License, or (at your option) any later version.
5#
6# This program is distributed in the hope that it will be useful,
7# but WITHOUT ANY WARRANTY; without even the implied warranty of
8# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9# GNU Library Lesser General Public License for more details at
10# ( http://www.gnu.org/licenses/lgpl.html ).
11#
12# You should have received a copy of the GNU Lesser General Public License
13# along with this program; if not, write to the Free Software
14# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15# written by: Jeff Ortel ( jortel@redhat.com )
16
17"""
18Suds is a lightweight SOAP python client that provides a service proxy
19for Web Services.
20@var properties: Library properties.
21@type properties: dict
22"""
23
24import os
25import sys
26import socket
27
28#
29# Project properties
30#
31
32__version__ = '0.3.7'
33
34properties = dict(version=__version__, build="(beta) R536-20090710")
35
36#
37# Exceptions
38#
39
40class MethodNotFound(Exception):
41    def __init__(self, name):
42        Exception.__init__(self, "Method not found: '%s'" % name)
43       
44class PortNotFound(Exception):
45    def __init__(self, name):
46        Exception.__init__(self, "Port not found: '%s'" % name)
47   
48class TypeNotFound(Exception):
49    def __init__(self, name):
50        Exception.__init__(self, "Type not found: '%s'" % tostr(name))
51   
52class BuildError(Exception):
53    msg = \
54        """
55        An error occured while building a instance of (%s).  As a result
56        the object you requested could not be constructed.  It is recommended
57        that you construct the type manually using a Suds object.
58        Please open a ticket with a description of this error.
59        Reason: %s
60        """
61    def __init__(self, name, exception):
62        Exception.__init__(self, BuildError.msg % (name, exception))
63       
64class SoapHeadersNotPermitted(Exception):
65    msg = \
66        """
67        Method (%s) was invoked with SOAP headers.  The WSDL does not
68        define SOAP headers for this method.  Retry without the soapheaders
69        keyword argument.
70        """
71    def __init__(self, name):
72        Exception.__init__(self, self.msg % name)
73   
74class WebFault(Exception):
75    def __init__(self, fault, document):
76        if hasattr(fault, 'faultstring'):
77            Exception.__init__(self, "Server raised fault: '%s'" % fault.faultstring)
78        self.fault = fault
79        self.document = document
80
81#
82# Logging
83#
84
85class Repr:
86    def __init__(self, x):
87        self.x = x
88    def __str__(self):
89        return repr(self.x) 
90
91#
92# Utility
93#
94
95def tostr(object, encoding=None):
96    """ get a unicode safe string representation of an object """
97    if isinstance(object, basestring):
98        if encoding is None:
99            return object
100        else:
101            return object.encode(encoding)
102    if isinstance(object, tuple):
103        s = ['(']
104        for item in object:
105            if isinstance(item, basestring):
106                s.append(item)
107            else:
108                s.append(tostr(item))
109            s.append(', ')
110        s.append(')')
111        return ''.join(s)
112    if isinstance(object, list):
113        s = ['[']
114        for item in object:
115            if isinstance(item, basestring):
116                s.append(item)
117            else:
118                s.append(tostr(item))
119            s.append(', ')
120        s.append(']')
121        return ''.join(s)
122    if isinstance(object, dict):
123        s = ['{']
124        for item in object.items():
125            if isinstance(item[0], basestring):
126                s.append(item[0])
127            else:
128                s.append(tostr(item[0]))
129            s.append(' = ')
130            if isinstance(item[1], basestring):
131                s.append(item[1])
132            else:
133                s.append(tostr(item[1]))
134            s.append(', ')
135        s.append('}')
136        return ''.join(s)
137    try:
138        return unicode(object)
139    except:
140        return str(object)
141   
142def objid(obj):
143    return obj.__class__.__name__\
144        +':'+hex(id(obj))
145
146
147import client
Note: See TracBrowser for help on using the repository browser.