1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 """
18 The I{sxbuiltin} module provides classes that represent
19 XSD I{builtin} schema objects.
20 """
21
22 from logging import getLogger
23 from suds import *
24 from suds.xsd import *
25 from suds.sax.date import *
26 from suds.xsd.sxbase import XBuiltin
27 import datetime as dt
28
29
30 log = getLogger(__name__)
34 """
35 Represents an (xsd) <xs:string/> node
36 """
37 pass
38
39
40 -class XAny(XBuiltin):
41 """
42 Represents an (xsd) <any/> node
43 """
44
48
50 child = XAny(self.schema, name)
51 return (child, [])
52
55
58 """
59 Represents an (xsd) boolean builtin type.
60 """
61
62 translation = (
63 { '1':True,'true':True,'0':False,'false':False },
64 { True:'true',1:'true',False:'false',0:'false' },
65 )
66
68 if topython:
69 if isinstance(value, basestring):
70 return XBoolean.translation[0].get(value)
71 else:
72 return None
73 else:
74 if isinstance(value, (bool,int)):
75 return XBoolean.translation[1].get(value)
76 else:
77 return value
78
81 """
82 Represents an (xsd) xs:int builtin type.
83 """
84
86 if topython:
87 if isinstance(value, basestring) and len(value):
88 return int(value)
89 else:
90 return None
91 else:
92 if isinstance(value, int):
93 return str(value)
94 else:
95 return value
96
98 """
99 Represents an (xsd) xs:long builtin type.
100 """
101
103 if topython:
104 if isinstance(value, basestring) and len(value):
105 return long(value)
106 else:
107 return None
108 else:
109 if isinstance(value, (int,long)):
110 return str(value)
111 else:
112 return value
113
116 """
117 Represents an (xsd) xs:float builtin type.
118 """
119
121 if topython:
122 if isinstance(value, basestring) and len(value):
123 return float(value)
124 else:
125 return None
126 else:
127 if isinstance(value, float):
128 return str(value)
129 else:
130 return value
131
132
133 -class XDate(XBuiltin):
134 """
135 Represents an (xsd) xs:date builtin type.
136 """
137
139 if topython:
140 if isinstance(value, basestring) and len(value):
141 return Date(value).date
142 else:
143 return None
144 else:
145 if isinstance(value, dt.date):
146 return str(Date(value))
147 else:
148 return value
149
150
151 -class XTime(XBuiltin):
152 """
153 Represents an (xsd) xs:time builtin type.
154 """
155
157 if topython:
158 if isinstance(value, basestring) and len(value):
159 return Time(value).time
160 else:
161 return None
162 else:
163 if isinstance(value, dt.date):
164 return str(Time(value))
165 else:
166 return value
167
170 """
171 Represents an (xsd) xs:datetime builtin type.
172 """
173
175 if topython:
176 if isinstance(value, basestring) and len(value):
177 return DateTime(value).datetime
178 else:
179 return None
180 else:
181 if isinstance(value, dt.date):
182 return str(DateTime(value))
183 else:
184 return value
185
188
189 tags =\
190 {
191
192 'anyType' : XAny,
193
194 'string' : XString,
195 'normalizedString' : XString,
196 'ID' : XString,
197 'Name' : XString,
198 'QName' : XString,
199 'NCName' : XString,
200 'anySimpleType' : XString,
201 'anyURI' : XString,
202 'NOTATION' : XString,
203 'token' : XString,
204 'language' : XString,
205 'IDREFS' : XString,
206 'ENTITIES' : XString,
207 'IDREF' : XString,
208 'ENTITY' : XString,
209 'NMTOKEN' : XString,
210 'NMTOKENS' : XString,
211
212 'hexBinary' : XString,
213 'base64Binary' : XString,
214
215 'int' : XInteger,
216 'integer' : XInteger,
217 'unsignedInt' : XInteger,
218 'positiveInteger' : XInteger,
219 'negativeInteger' : XInteger,
220 'nonPositiveInteger' : XInteger,
221 'nonNegativeInteger' : XInteger,
222
223 'long' : XLong,
224 'unsignedLong' : XLong,
225
226 'short' : XInteger,
227 'unsignedShort' : XInteger,
228 'byte' : XInteger,
229 'unsignedByte' : XInteger,
230
231 'float' : XFloat,
232 'double' : XFloat,
233 'decimal' : XFloat,
234
235 'date' : XDate,
236 'time' : XTime,
237 'dateTime': XDateTime,
238 'duration': XString,
239 'gYearMonth' : XString,
240 'gYear' : XString,
241 'gMonthDay' : XString,
242 'gDay' : XString,
243 'gMonth' : XString,
244
245 'boolean' : XBoolean,
246 }
247
248 @classmethod
250 """
251 Map (override) tag => I{class} mapping.
252 @param tag: An xsd tag name.
253 @type tag: str
254 @param fn: A function or class.
255 @type fn: fn|class.
256 """
257 cls.tags[tag] = fn
258
259 @classmethod
260 - def create(cls, schema, name):
261 """
262 Create an object based on the root tag name.
263 @param schema: A schema object.
264 @type schema: L{schema.Schema}
265 @param name: The name.
266 @type name: str
267 @return: The created object.
268 @rtype: L{XBuiltin}
269 """
270 fn = cls.tags.get(name)
271 if fn is not None:
272 return fn(schema, name)
273 else:
274 return XBuiltin(schema, name)
275