source: trunk/suds/__init__.py @ 508

Revision 508, 4.1 KB checked in by jortel, 5 years ago (diff)

bump beta release

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
32properties = dict(version='0.3.6', build="(beta) R507-20090513")
33
34#
35# Exceptions
36#
37
38class MethodNotFound(Exception):
39    def __init__(self, name):
40        Exception.__init__(self, "Method not found: '%s'" % name)
41       
42class PortNotFound(Exception):
43    def __init__(self, name):
44        Exception.__init__(self, "Port not found: '%s'" % name)
45   
46class TypeNotFound(Exception):
47    def __init__(self, name):
48        Exception.__init__(self, "Type not found: '%s'" % tostr(name))
49   
50class BuildError(Exception):
51    msg = \
52        """
53        An error occured while building a instance of (%s).  As a result
54        the object you requested could not be constructed.  It is recommended
55        that you construct the type manually using a Suds object.
56        Please open a ticket with a description of this error.
57        Reason: %s
58        """
59    def __init__(self, name, exception):
60        Exception.__init__(self, BuildError.msg % (name, exception))
61       
62class SoapHeadersNotPermitted(Exception):
63    msg = \
64        """
65        Method (%s) was invoked with SOAP headers.  The WSDL does not
66        define SOAP headers for this method.  Retry without the soapheaders
67        keyword argument.
68        """
69    def __init__(self, name):
70        Exception.__init__(self, self.msg % name)
71   
72class WebFault(Exception):
73    def __init__(self, fault, document):
74        if hasattr(fault, 'faultstring'):
75            Exception.__init__(self, "Server raised fault: '%s'" % fault.faultstring)
76        self.fault = fault
77        self.document = document
78
79#
80# Logging
81#
82
83class Repr:
84    def __init__(self, x):
85        self.x = x
86    def __str__(self):
87        return repr(self.x) 
88
89#
90# Utility
91#
92
93def tostr(object, encoding=None):
94    """ get a unicode safe string representation of an object """
95    if isinstance(object, basestring):
96        if encoding is None:
97            return object
98        else:
99            return object.encode(encoding)
100    if isinstance(object, tuple):
101        s = ['(']
102        for item in object:
103            if isinstance(item, basestring):
104                s.append(item)
105            else:
106                s.append(tostr(item))
107            s.append(', ')
108        s.append(')')
109        return ''.join(s)
110    if isinstance(object, list):
111        s = ['[']
112        for item in object:
113            if isinstance(item, basestring):
114                s.append(item)
115            else:
116                s.append(tostr(item))
117            s.append(', ')
118        s.append(']')
119        return ''.join(s)
120    if isinstance(object, dict):
121        s = ['{']
122        for item in object.items():
123            if isinstance(item[0], basestring):
124                s.append(item[0])
125            else:
126                s.append(tostr(item[0]))
127            s.append(' = ')
128            if isinstance(item[1], basestring):
129                s.append(item[1])
130            else:
131                s.append(tostr(item[1]))
132            s.append(', ')
133        s.append('}')
134        return ''.join(s)
135    try:
136        return unicode(object)
137    except:
138        return str(object)
139   
140def objid(obj):
141    return obj.__class__.__name__\
142        +':'+hex(id(obj))
Note: See TracBrowser for help on using the repository browser.