Package suds :: Module store
[hide private]
[frames] | no frames]

Source Code for Module suds.store

  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  """ 
 18  Contains XML text for documents to be distributed 
 19  with the suds lib.  Also, contains classes for accessing 
 20  these documents. 
 21  """ 
 22   
 23  from StringIO import StringIO 
 24  from logging import getLogger 
 25   
 26  log = getLogger(__name__) 
 27   
 28   
 29  # 
 30  # Soap section 5 encoding schema. 
 31  # 
 32  encoding = \ 
 33  """<?xml version="1.0" encoding="UTF-8"?> 
 34  <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://schemas.xmlsoap.org/soap/encoding/" targetNamespace="http://schemas.xmlsoap.org/soap/encoding/"> 
 35           
 36   <xs:attribute name="root"> 
 37     <xs:annotation> 
 38       <xs:documentation> 
 39         'root' can be used to distinguish serialization roots from other 
 40         elements that are present in a serialization but are not roots of 
 41         a serialized value graph  
 42       </xs:documentation> 
 43     </xs:annotation> 
 44     <xs:simpleType> 
 45       <xs:restriction base="xs:boolean"> 
 46         <xs:pattern value="0|1"/> 
 47       </xs:restriction> 
 48     </xs:simpleType> 
 49   </xs:attribute> 
 50   
 51    <xs:attributeGroup name="commonAttributes"> 
 52      <xs:annotation> 
 53        <xs:documentation> 
 54          Attributes common to all elements that function as accessors or  
 55          represent independent (multi-ref) values.  The href attribute is 
 56          intended to be used in a manner like CONREF.  That is, the element 
 57          content should be empty iff the href attribute appears 
 58        </xs:documentation> 
 59      </xs:annotation> 
 60      <xs:attribute name="id" type="xs:ID"/> 
 61      <xs:attribute name="href" type="xs:anyURI"/> 
 62      <xs:anyAttribute namespace="##other" processContents="lax"/> 
 63    </xs:attributeGroup> 
 64   
 65    <!-- Global Attributes.  The following attributes are intended to be usable via qualified attribute names on any complex type referencing them. --> 
 66          
 67    <!-- Array attributes. Needed to give the type and dimensions of an array's contents, and the offset for partially-transmitted arrays. --> 
 68      
 69    <xs:simpleType name="arrayCoordinate"> 
 70      <xs:restriction base="xs:string"/> 
 71    </xs:simpleType> 
 72             
 73    <xs:attribute name="arrayType" type="xs:string"/> 
 74    <xs:attribute name="offset" type="tns:arrayCoordinate"/> 
 75     
 76    <xs:attributeGroup name="arrayAttributes"> 
 77      <xs:attribute ref="tns:arrayType"/> 
 78      <xs:attribute ref="tns:offset"/> 
 79    </xs:attributeGroup>     
 80     
 81    <xs:attribute name="position" type="tns:arrayCoordinate"/>  
 82     
 83    <xs:attributeGroup name="arrayMemberAttributes"> 
 84      <xs:attribute ref="tns:position"/> 
 85    </xs:attributeGroup>     
 86   
 87    <xs:group name="Array"> 
 88      <xs:sequence> 
 89        <xs:any namespace="##any" minOccurs="0" maxOccurs="unbounded" processContents="lax"/> 
 90      </xs:sequence> 
 91    </xs:group> 
 92   
 93    <xs:element name="Array" type="tns:Array"/> 
 94    <xs:complexType name="Array"> 
 95      <xs:annotation> 
 96        <xs:documentation> 
 97         'Array' is a complex type for accessors identified by position  
 98        </xs:documentation> 
 99      </xs:annotation> 
100      <xs:group ref="tns:Array" minOccurs="0"/> 
101      <xs:attributeGroup ref="tns:arrayAttributes"/> 
102      <xs:attributeGroup ref="tns:commonAttributes"/> 
103    </xs:complexType>  
104   
105    <!-- 'Struct' is a complex type for accessors identified by name.  
106         Constraint: No element may be have the same name as any other, 
107         nor may any element have a maxOccurs > 1. --> 
108      
109    <xs:element name="Struct" type="tns:Struct"/> 
110   
111    <xs:group name="Struct"> 
112      <xs:sequence> 
113        <xs:any namespace="##any" minOccurs="0" maxOccurs="unbounded" processContents="lax"/> 
114      </xs:sequence> 
115    </xs:group> 
116   
117    <xs:complexType name="Struct"> 
118      <xs:group ref="tns:Struct" minOccurs="0"/> 
119      <xs:attributeGroup ref="tns:commonAttributes"/> 
120    </xs:complexType>  
121   
122    <!-- 'Base64' can be used to serialize binary data using base64 encoding 
123         as defined in RFC2045 but without the MIME line length limitation. --> 
124   
125    <xs:simpleType name="base64"> 
126      <xs:restriction base="xs:base64Binary"/> 
127    </xs:simpleType> 
128   
129   <!-- Element declarations corresponding to each of the simple types in the  
130        XML Schemas Specification. --> 
131   
132    <xs:element name="duration" type="tns:duration"/> 
133    <xs:complexType name="duration"> 
134      <xs:simpleContent> 
135        <xs:extension base="xs:duration"> 
136          <xs:attributeGroup ref="tns:commonAttributes"/> 
137        </xs:extension> 
138      </xs:simpleContent> 
139    </xs:complexType> 
140   
141    <xs:element name="dateTime" type="tns:dateTime"/> 
142    <xs:complexType name="dateTime"> 
143      <xs:simpleContent> 
144        <xs:extension base="xs:dateTime"> 
145          <xs:attributeGroup ref="tns:commonAttributes"/> 
146        </xs:extension> 
147      </xs:simpleContent> 
148    </xs:complexType> 
149   
150   
151   
152    <xs:element name="NOTATION" type="tns:NOTATION"/> 
153    <xs:complexType name="NOTATION"> 
154      <xs:simpleContent> 
155        <xs:extension base="xs:QName"> 
156          <xs:attributeGroup ref="tns:commonAttributes"/> 
157        </xs:extension> 
158      </xs:simpleContent> 
159    </xs:complexType> 
160     
161   
162    <xs:element name="time" type="tns:time"/> 
163    <xs:complexType name="time"> 
164      <xs:simpleContent> 
165        <xs:extension base="xs:time"> 
166          <xs:attributeGroup ref="tns:commonAttributes"/> 
167        </xs:extension> 
168      </xs:simpleContent> 
169    </xs:complexType> 
170   
171    <xs:element name="date" type="tns:date"/> 
172    <xs:complexType name="date"> 
173      <xs:simpleContent> 
174        <xs:extension base="xs:date"> 
175          <xs:attributeGroup ref="tns:commonAttributes"/> 
176        </xs:extension> 
177      </xs:simpleContent> 
178    </xs:complexType> 
179   
180    <xs:element name="gYearMonth" type="tns:gYearMonth"/> 
181    <xs:complexType name="gYearMonth"> 
182      <xs:simpleContent> 
183        <xs:extension base="xs:gYearMonth"> 
184          <xs:attributeGroup ref="tns:commonAttributes"/> 
185        </xs:extension> 
186      </xs:simpleContent> 
187    </xs:complexType> 
188   
189    <xs:element name="gYear" type="tns:gYear"/> 
190    <xs:complexType name="gYear"> 
191      <xs:simpleContent> 
192        <xs:extension base="xs:gYear"> 
193          <xs:attributeGroup ref="tns:commonAttributes"/> 
194        </xs:extension> 
195      </xs:simpleContent> 
196    </xs:complexType> 
197   
198    <xs:element name="gMonthDay" type="tns:gMonthDay"/> 
199    <xs:complexType name="gMonthDay"> 
200      <xs:simpleContent> 
201        <xs:extension base="xs:gMonthDay"> 
202          <xs:attributeGroup ref="tns:commonAttributes"/> 
203        </xs:extension> 
204      </xs:simpleContent> 
205    </xs:complexType> 
206   
207    <xs:element name="gDay" type="tns:gDay"/> 
208    <xs:complexType name="gDay"> 
209      <xs:simpleContent> 
210        <xs:extension base="xs:gDay"> 
211          <xs:attributeGroup ref="tns:commonAttributes"/> 
212        </xs:extension> 
213      </xs:simpleContent> 
214    </xs:complexType> 
215   
216    <xs:element name="gMonth" type="tns:gMonth"/> 
217    <xs:complexType name="gMonth"> 
218      <xs:simpleContent> 
219        <xs:extension base="xs:gMonth"> 
220          <xs:attributeGroup ref="tns:commonAttributes"/> 
221        </xs:extension> 
222      </xs:simpleContent> 
223    </xs:complexType> 
224     
225    <xs:element name="boolean" type="tns:boolean"/> 
226    <xs:complexType name="boolean"> 
227      <xs:simpleContent> 
228        <xs:extension base="xs:boolean"> 
229          <xs:attributeGroup ref="tns:commonAttributes"/> 
230        </xs:extension> 
231      </xs:simpleContent> 
232    </xs:complexType> 
233   
234    <xs:element name="base64Binary" type="tns:base64Binary"/> 
235    <xs:complexType name="base64Binary"> 
236      <xs:simpleContent> 
237        <xs:extension base="xs:base64Binary"> 
238          <xs:attributeGroup ref="tns:commonAttributes"/> 
239        </xs:extension> 
240      </xs:simpleContent> 
241    </xs:complexType> 
242   
243    <xs:element name="hexBinary" type="tns:hexBinary"/> 
244    <xs:complexType name="hexBinary"> 
245      <xs:simpleContent> 
246       <xs:extension base="xs:hexBinary"> 
247         <xs:attributeGroup ref="tns:commonAttributes"/> 
248       </xs:extension> 
249      </xs:simpleContent> 
250    </xs:complexType> 
251   
252    <xs:element name="float" type="tns:float"/> 
253    <xs:complexType name="float"> 
254      <xs:simpleContent> 
255        <xs:extension base="xs:float"> 
256          <xs:attributeGroup ref="tns:commonAttributes"/> 
257        </xs:extension> 
258      </xs:simpleContent> 
259    </xs:complexType> 
260   
261    <xs:element name="double" type="tns:double"/> 
262    <xs:complexType name="double"> 
263      <xs:simpleContent> 
264        <xs:extension base="xs:double"> 
265          <xs:attributeGroup ref="tns:commonAttributes"/> 
266        </xs:extension> 
267      </xs:simpleContent> 
268    </xs:complexType> 
269   
270    <xs:element name="anyURI" type="tns:anyURI"/> 
271    <xs:complexType name="anyURI"> 
272      <xs:simpleContent> 
273        <xs:extension base="xs:anyURI"> 
274          <xs:attributeGroup ref="tns:commonAttributes"/> 
275        </xs:extension> 
276      </xs:simpleContent> 
277    </xs:complexType> 
278   
279    <xs:element name="QName" type="tns:QName"/> 
280    <xs:complexType name="QName"> 
281      <xs:simpleContent> 
282        <xs:extension base="xs:QName"> 
283          <xs:attributeGroup ref="tns:commonAttributes"/> 
284        </xs:extension> 
285      </xs:simpleContent> 
286    </xs:complexType> 
287   
288     
289    <xs:element name="string" type="tns:string"/> 
290    <xs:complexType name="string"> 
291      <xs:simpleContent> 
292        <xs:extension base="xs:string"> 
293          <xs:attributeGroup ref="tns:commonAttributes"/> 
294        </xs:extension> 
295      </xs:simpleContent> 
296    </xs:complexType> 
297   
298    <xs:element name="normalizedString" type="tns:normalizedString"/> 
299    <xs:complexType name="normalizedString"> 
300      <xs:simpleContent> 
301        <xs:extension base="xs:normalizedString"> 
302          <xs:attributeGroup ref="tns:commonAttributes"/> 
303        </xs:extension> 
304      </xs:simpleContent> 
305    </xs:complexType> 
306   
307    <xs:element name="token" type="tns:token"/> 
308    <xs:complexType name="token"> 
309      <xs:simpleContent> 
310        <xs:extension base="xs:token"> 
311          <xs:attributeGroup ref="tns:commonAttributes"/> 
312        </xs:extension> 
313      </xs:simpleContent> 
314    </xs:complexType> 
315   
316    <xs:element name="language" type="tns:language"/> 
317    <xs:complexType name="language"> 
318      <xs:simpleContent> 
319        <xs:extension base="xs:language"> 
320          <xs:attributeGroup ref="tns:commonAttributes"/> 
321        </xs:extension> 
322      </xs:simpleContent> 
323    </xs:complexType> 
324   
325    <xs:element name="Name" type="tns:Name"/> 
326    <xs:complexType name="Name"> 
327      <xs:simpleContent> 
328        <xs:extension base="xs:Name"> 
329          <xs:attributeGroup ref="tns:commonAttributes"/> 
330        </xs:extension> 
331      </xs:simpleContent> 
332    </xs:complexType> 
333   
334    <xs:element name="NMTOKEN" type="tns:NMTOKEN"/> 
335    <xs:complexType name="NMTOKEN"> 
336      <xs:simpleContent> 
337        <xs:extension base="xs:NMTOKEN"> 
338          <xs:attributeGroup ref="tns:commonAttributes"/> 
339        </xs:extension> 
340      </xs:simpleContent> 
341    </xs:complexType> 
342   
343    <xs:element name="NCName" type="tns:NCName"/> 
344    <xs:complexType name="NCName"> 
345      <xs:simpleContent> 
346        <xs:extension base="xs:NCName"> 
347          <xs:attributeGroup ref="tns:commonAttributes"/> 
348        </xs:extension> 
349      </xs:simpleContent> 
350    </xs:complexType> 
351   
352    <xs:element name="NMTOKENS" type="tns:NMTOKENS"/> 
353    <xs:complexType name="NMTOKENS"> 
354      <xs:simpleContent> 
355        <xs:extension base="xs:NMTOKENS"> 
356          <xs:attributeGroup ref="tns:commonAttributes"/> 
357        </xs:extension> 
358      </xs:simpleContent> 
359    </xs:complexType> 
360   
361    <xs:element name="ID" type="tns:ID"/> 
362    <xs:complexType name="ID"> 
363      <xs:simpleContent> 
364        <xs:extension base="xs:ID"> 
365          <xs:attributeGroup ref="tns:commonAttributes"/> 
366        </xs:extension> 
367      </xs:simpleContent> 
368    </xs:complexType> 
369   
370    <xs:element name="IDREF" type="tns:IDREF"/> 
371    <xs:complexType name="IDREF"> 
372      <xs:simpleContent> 
373        <xs:extension base="xs:IDREF"> 
374          <xs:attributeGroup ref="tns:commonAttributes"/> 
375        </xs:extension> 
376      </xs:simpleContent> 
377    </xs:complexType> 
378   
379    <xs:element name="ENTITY" type="tns:ENTITY"/> 
380    <xs:complexType name="ENTITY"> 
381      <xs:simpleContent> 
382        <xs:extension base="xs:ENTITY"> 
383          <xs:attributeGroup ref="tns:commonAttributes"/> 
384        </xs:extension> 
385      </xs:simpleContent> 
386    </xs:complexType> 
387   
388    <xs:element name="IDREFS" type="tns:IDREFS"/> 
389    <xs:complexType name="IDREFS"> 
390      <xs:simpleContent> 
391        <xs:extension base="xs:IDREFS"> 
392          <xs:attributeGroup ref="tns:commonAttributes"/> 
393        </xs:extension> 
394      </xs:simpleContent> 
395    </xs:complexType> 
396   
397    <xs:element name="ENTITIES" type="tns:ENTITIES"/> 
398    <xs:complexType name="ENTITIES"> 
399      <xs:simpleContent> 
400        <xs:extension base="xs:ENTITIES"> 
401          <xs:attributeGroup ref="tns:commonAttributes"/> 
402        </xs:extension> 
403      </xs:simpleContent> 
404    </xs:complexType> 
405   
406    <xs:element name="decimal" type="tns:decimal"/> 
407    <xs:complexType name="decimal"> 
408      <xs:simpleContent> 
409        <xs:extension base="xs:decimal"> 
410          <xs:attributeGroup ref="tns:commonAttributes"/> 
411        </xs:extension> 
412      </xs:simpleContent> 
413    </xs:complexType> 
414   
415    <xs:element name="integer" type="tns:integer"/> 
416    <xs:complexType name="integer"> 
417      <xs:simpleContent> 
418        <xs:extension base="xs:integer"> 
419          <xs:attributeGroup ref="tns:commonAttributes"/> 
420        </xs:extension> 
421      </xs:simpleContent> 
422    </xs:complexType> 
423   
424    <xs:element name="nonPositiveInteger" type="tns:nonPositiveInteger"/> 
425    <xs:complexType name="nonPositiveInteger"> 
426      <xs:simpleContent> 
427        <xs:extension base="xs:nonPositiveInteger"> 
428          <xs:attributeGroup ref="tns:commonAttributes"/> 
429        </xs:extension> 
430      </xs:simpleContent> 
431    </xs:complexType> 
432   
433    <xs:element name="negativeInteger" type="tns:negativeInteger"/> 
434    <xs:complexType name="negativeInteger"> 
435      <xs:simpleContent> 
436        <xs:extension base="xs:negativeInteger"> 
437          <xs:attributeGroup ref="tns:commonAttributes"/> 
438        </xs:extension> 
439      </xs:simpleContent> 
440    </xs:complexType> 
441   
442    <xs:element name="long" type="tns:long"/> 
443    <xs:complexType name="long"> 
444      <xs:simpleContent> 
445        <xs:extension base="xs:long"> 
446          <xs:attributeGroup ref="tns:commonAttributes"/> 
447        </xs:extension> 
448      </xs:simpleContent> 
449    </xs:complexType> 
450   
451    <xs:element name="int" type="tns:int"/> 
452    <xs:complexType name="int"> 
453      <xs:simpleContent> 
454        <xs:extension base="xs:int"> 
455          <xs:attributeGroup ref="tns:commonAttributes"/> 
456        </xs:extension> 
457      </xs:simpleContent> 
458    </xs:complexType> 
459   
460    <xs:element name="short" type="tns:short"/> 
461    <xs:complexType name="short"> 
462      <xs:simpleContent> 
463        <xs:extension base="xs:short"> 
464          <xs:attributeGroup ref="tns:commonAttributes"/> 
465        </xs:extension> 
466      </xs:simpleContent> 
467    </xs:complexType> 
468   
469    <xs:element name="byte" type="tns:byte"/> 
470    <xs:complexType name="byte"> 
471      <xs:simpleContent> 
472        <xs:extension base="xs:byte"> 
473          <xs:attributeGroup ref="tns:commonAttributes"/> 
474        </xs:extension> 
475      </xs:simpleContent> 
476    </xs:complexType> 
477   
478    <xs:element name="nonNegativeInteger" type="tns:nonNegativeInteger"/> 
479    <xs:complexType name="nonNegativeInteger"> 
480      <xs:simpleContent> 
481        <xs:extension base="xs:nonNegativeInteger"> 
482          <xs:attributeGroup ref="tns:commonAttributes"/> 
483        </xs:extension> 
484      </xs:simpleContent> 
485    </xs:complexType> 
486   
487    <xs:element name="unsignedLong" type="tns:unsignedLong"/> 
488    <xs:complexType name="unsignedLong"> 
489      <xs:simpleContent> 
490        <xs:extension base="xs:unsignedLong"> 
491          <xs:attributeGroup ref="tns:commonAttributes"/> 
492        </xs:extension> 
493      </xs:simpleContent> 
494    </xs:complexType> 
495   
496    <xs:element name="unsignedInt" type="tns:unsignedInt"/> 
497    <xs:complexType name="unsignedInt"> 
498      <xs:simpleContent> 
499        <xs:extension base="xs:unsignedInt"> 
500          <xs:attributeGroup ref="tns:commonAttributes"/> 
501        </xs:extension> 
502      </xs:simpleContent> 
503    </xs:complexType> 
504   
505    <xs:element name="unsignedShort" type="tns:unsignedShort"/> 
506    <xs:complexType name="unsignedShort"> 
507      <xs:simpleContent> 
508        <xs:extension base="xs:unsignedShort"> 
509          <xs:attributeGroup ref="tns:commonAttributes"/> 
510        </xs:extension> 
511      </xs:simpleContent> 
512    </xs:complexType> 
513   
514    <xs:element name="unsignedByte" type="tns:unsignedByte"/> 
515    <xs:complexType name="unsignedByte"> 
516      <xs:simpleContent> 
517        <xs:extension base="xs:unsignedByte"> 
518          <xs:attributeGroup ref="tns:commonAttributes"/> 
519        </xs:extension> 
520      </xs:simpleContent> 
521    </xs:complexType> 
522   
523    <xs:element name="positiveInteger" type="tns:positiveInteger"/> 
524    <xs:complexType name="positiveInteger"> 
525      <xs:simpleContent> 
526        <xs:extension base="xs:positiveInteger"> 
527          <xs:attributeGroup ref="tns:commonAttributes"/> 
528        </xs:extension> 
529      </xs:simpleContent> 
530    </xs:complexType> 
531   
532    <xs:element name="anyType"/> 
533  </xs:schema> 
534  """ 
535   
536   
537 -class DocumentStore:
538 """ 539 The I{suds} document store provides a local repository 540 for xml documnts. 541 @cvar protocol: The URL protocol for the store. 542 @type protocol: str 543 @cvar store: The mapping of URL location to documents. 544 @type store: dict 545 """ 546 547 protocol = 'suds' 548 549 store = { 550 'schemas.xmlsoap.org/soap/encoding/' : encoding 551 } 552
553 - def open(self, url):
554 """ 555 Open a document at the specified url. 556 @param url: A document URL. 557 @type url: str 558 @return: A file pointer to the document. 559 @rtype: StringIO 560 """ 561 protocol, location = self.split(url) 562 if protocol == self.protocol: 563 return self.find(location) 564 else: 565 return None
566
567 - def find(self, location):
568 """ 569 Find the specified location in the store. 570 @param location: The I{location} part of a URL. 571 @type location: str 572 @return: An input stream to the document. 573 @rtype: StringIO 574 """ 575 try: 576 content = self.store[location] 577 return StringIO(content) 578 except: 579 reason = 'location "%s" not in document store' % location 580 raise Exception, reason
581
582 - def split(self, url):
583 """ 584 Split the url into I{protocol} and I{location} 585 @param url: A URL. 586 @param url: str 587 @return: (I{url}, I{location}) 588 @rtype: tuple 589 """ 590 parts = url.split('://', 1) 591 if len(parts) == 2: 592 return parts 593 else: 594 return (None, url)
595