1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 """
18 Contains xml document reader classes.
19 """
20
21
22 from suds.sax.parser import Parser
23 from suds.transport import Request
24 from suds.cache import Cache, NoCache
25 from suds.store import DocumentStore
26 from suds.plugin import PluginContainer
27 from logging import getLogger
28
29
30 log = getLogger(__name__)
31
32
34 """
35 The reader provides integration with cache.
36 @ivar options: An options object.
37 @type options: I{Options}
38 """
39
47
49 """
50 Mangle the name by hashing the I{name} and appending I{x}.
51 @return: the mangled name.
52 """
53 h = abs(hash(name))
54 return '%s-%s' % (h, x)
55
56
58 """
59 The XML document reader provides an integration
60 between the SAX L{Parser} and the document cache.
61 """
62
63 - def open(self, url):
64 """
65 Open an XML document at the specified I{url}.
66 First, the document attempted to be retrieved from
67 the I{object cache}. If not found, it is downloaded and
68 parsed using the SAX parser. The result is added to the
69 cache for the next open().
70 @param url: A document url.
71 @type url: str.
72 @return: The specified XML document.
73 @rtype: I{Document}
74 """
75 cache = self.cache()
76 id = self.mangle(url, 'document')
77 d = cache.get(id)
78 if d is None:
79 d = self.download(url)
80 cache.put(id, d)
81 self.plugins.document.parsed(url=url, document=d.root())
82 return d
83
102
104 """
105 Get the cache.
106 @return: The I{options} when I{cachingpolicy} = B{0}.
107 @rtype: L{Cache}
108 """
109 if self.options.cachingpolicy == 0:
110 return self.options.cache
111 else:
112 return NoCache()
113
114
116 """
117 The WSDL definitions reader provides an integration
118 between the Definitions and the object cache.
119 @ivar fn: A factory function (constructor) used to
120 create the object not found in the cache.
121 @type fn: I{Constructor}
122 """
123
125 """
126 @param options: An options object.
127 @type options: I{Options}
128 @param fn: A factory function (constructor) used to
129 create the object not found in the cache.
130 @type fn: I{Constructor}
131 """
132 Reader.__init__(self, options)
133 self.fn = fn
134
135 - def open(self, url):
136 """
137 Open a WSDL at the specified I{url}.
138 First, the WSDL attempted to be retrieved from
139 the I{object cache}. After unpickled from the cache, the
140 I{options} attribute is restored.
141 If not found, it is downloaded and instantiated using the
142 I{fn} constructor and added to the cache for the next open().
143 @param url: A WSDL url.
144 @type url: str.
145 @return: The WSDL object.
146 @rtype: I{Definitions}
147 """
148 cache = self.cache()
149 id = self.mangle(url, 'wsdl')
150 d = cache.get(id)
151 if d is None:
152 d = self.fn(url, self.options)
153 cache.put(id, d)
154 else:
155 d.options = self.options
156 for imp in d.imports:
157 imp.imported.options = self.options
158 return d
159
161 """
162 Get the cache.
163 @return: The I{options} when I{cachingpolicy} = B{1}.
164 @rtype: L{Cache}
165 """
166 if self.options.cachingpolicy == 1:
167 return self.options.cache
168 else:
169 return NoCache()
170