1
1
# This program is free software; you can redistribute it and/or modify
2
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
3
+ # published by the Free Software Foundation; either version 3 of the
4
4
# License, or (at your option) any later version.
5
5
#
6
6
# This program is distributed in the hope that it will be useful,
19
19
service proxy for Web Services.
20
20
"""
21
21
22
- import os
23
- import sys
22
+ from .compat import basestring , unicode
24
23
25
24
#
26
25
# Project properties
27
26
#
28
27
29
- __version__ = '0.4 '
30
- __build__ = "GA R699-20100913 "
28
+ __version__ = '1.4.4.1 '
29
+ __build__ = "IN 20210108 "
31
30
32
31
#
33
32
# Exceptions
34
33
#
35
34
35
+
36
36
class MethodNotFound (Exception ):
37
37
def __init__ (self , name ):
38
38
Exception .__init__ (self , "Method not found: '%s'" % name )
39
-
39
+
40
+
40
41
class PortNotFound (Exception ):
41
42
def __init__ (self , name ):
42
43
Exception .__init__ (self , "Port not found: '%s'" % name )
43
-
44
+
45
+
44
46
class ServiceNotFound (Exception ):
45
47
def __init__ (self , name ):
46
48
Exception .__init__ (self , "Service not found: '%s'" % name )
47
-
49
+
50
+
48
51
class TypeNotFound (Exception ):
49
52
def __init__ (self , name ):
50
53
Exception .__init__ (self , "Type not found: '%s'" % tostr (name ))
51
-
54
+
55
+
52
56
class BuildError (Exception ):
53
57
msg = \
54
58
"""
@@ -58,51 +62,84 @@ class BuildError(Exception):
58
62
Please open a ticket with a description of this error.
59
63
Reason: %s
60
64
"""
65
+
61
66
def __init__ (self , name , exception ):
62
67
Exception .__init__ (self , BuildError .msg % (name , exception ))
63
-
68
+
69
+
64
70
class SoapHeadersNotPermitted (Exception ):
65
71
msg = \
66
72
"""
67
73
Method (%s) was invoked with SOAP headers. The WSDL does not
68
74
define SOAP headers for this method. Retry without the soapheaders
69
75
keyword argument.
70
76
"""
77
+
71
78
def __init__ (self , name ):
72
79
Exception .__init__ (self , self .msg % name )
73
-
80
+
81
+
82
+ def smart_str (s , encoding = 'utf-8' , errors = 'strict' ):
83
+ """
84
+ Returns a bytestring version of 's', encoded as specified in 'encoding'.
85
+
86
+ If strings_only is True, don't convert (some) non-string-like objects.
87
+
88
+ from django
89
+ """
90
+ if not isinstance (s , basestring ):
91
+ try :
92
+ return str (s )
93
+ except UnicodeEncodeError :
94
+ if isinstance (s , Exception ):
95
+ # An Exception subclass containing non-ASCII data that doesn't
96
+ # know how to print itself properly. We shouldn't raise a
97
+ # further exception.
98
+ return ' ' .join (smart_str (arg , encoding , errors ) for arg in s )
99
+ return unicode (s ).encode (encoding , errors )
100
+ elif isinstance (s , unicode ):
101
+ return s .encode (encoding , errors )
102
+ elif s and encoding != 'utf-8' :
103
+ return s .decode ('utf-8' , errors ).encode (encoding , errors )
104
+ else :
105
+ return s
106
+
107
+
74
108
class WebFault (Exception ):
75
109
def __init__ (self , fault , document ):
76
110
if hasattr (fault , 'faultstring' ):
77
- Exception .__init__ (self , "Server raised fault: '%s'" % fault .faultstring )
111
+ Exception .__init__ (self , smart_str ( "Server raised fault: '%s'" % fault .faultstring ) )
78
112
self .fault = fault
79
113
self .document = document
80
114
81
115
#
82
116
# Logging
83
117
#
84
118
119
+
85
120
class Repr :
86
121
def __init__ (self , x ):
87
122
self .x = x
123
+
88
124
def __str__ (self ):
89
- return repr (self .x )
125
+ return repr (self .x )
90
126
91
127
#
92
128
# Utility
93
129
#
94
130
131
+
95
132
def tostr (object , encoding = None ):
96
133
""" get a unicode safe string representation of an object """
97
- if isinstance (object , str ):
134
+ if isinstance (object , basestring ):
98
135
if encoding is None :
99
136
return object
100
137
else :
101
138
return object .encode (encoding )
102
139
if isinstance (object , tuple ):
103
140
s = ['(' ]
104
141
for item in object :
105
- if isinstance (item , str ):
142
+ if isinstance (item , basestring ):
106
143
s .append (item )
107
144
else :
108
145
s .append (tostr (item ))
@@ -112,7 +149,7 @@ def tostr(object, encoding=None):
112
149
if isinstance (object , list ):
113
150
s = ['[' ]
114
151
for item in object :
115
- if isinstance (item , str ):
152
+ if isinstance (item , basestring ):
116
153
s .append (item )
117
154
else :
118
155
s .append (tostr (item ))
@@ -121,34 +158,40 @@ def tostr(object, encoding=None):
121
158
return '' .join (s )
122
159
if isinstance (object , dict ):
123
160
s = ['{' ]
124
- for item in list ( object .items () ):
125
- if isinstance (item [0 ], str ):
161
+ for item in object .items ():
162
+ if isinstance (item [0 ], basestring ):
126
163
s .append (item [0 ])
127
164
else :
128
165
s .append (tostr (item [0 ]))
129
166
s .append (' = ' )
130
- if isinstance (item [1 ], str ):
167
+ if isinstance (item [1 ], basestring ):
131
168
s .append (item [1 ])
132
169
else :
133
170
s .append (tostr (item [1 ]))
134
171
s .append (', ' )
135
172
s .append ('}' )
136
173
return '' .join (s )
137
174
try :
138
- return str (object )
175
+ return unicode (object )
139
176
except :
140
177
return str (object )
141
-
178
+
179
+
142
180
class null :
143
181
"""
144
182
The I{null} object.
145
183
Used to pass NULL for optional XML nodes.
146
184
"""
147
185
pass
148
-
186
+
187
+ class Object (object ):
188
+ """
189
+ The python 3 base Object
190
+ """
191
+ pass
192
+
149
193
def objid (obj ):
150
- return obj .__class__ .__name__ \
151
- + ':' + hex (id (obj ))
194
+ return obj .__class__ .__name__ + ':' + hex (id (obj ))
152
195
153
196
154
- from . import client
197
+ from .client import Client
0 commit comments