The WSDL definitions reader provides an integration between the Definitions and the object cache. @ivar fn: A factory function (constructor) used to create the object not found in the cache. @type fn: I{Constructor}
| 112 | |
| 113 | |
| 114 | class DefinitionsReader(Reader): |
| 115 | """ |
| 116 | The WSDL definitions reader provides an integration |
| 117 | between the Definitions and the object cache. |
| 118 | @ivar fn: A factory function (constructor) used to |
| 119 | create the object not found in the cache. |
| 120 | @type fn: I{Constructor} |
| 121 | """ |
| 122 | |
| 123 | def __init__(self, options, fn): |
| 124 | """ |
| 125 | @param options: An options object. |
| 126 | @type options: I{Options} |
| 127 | @param fn: A factory function (constructor) used to |
| 128 | create the object not found in the cache. |
| 129 | @type fn: I{Constructor} |
| 130 | """ |
| 131 | Reader.__init__(self, options) |
| 132 | self.fn = fn |
| 133 | |
| 134 | def open(self, url): |
| 135 | """ |
| 136 | Open a WSDL at the specified I{url}. |
| 137 | First, the WSDL attempted to be retrieved from |
| 138 | the I{object cache}. After unpickled from the cache, the |
| 139 | I{options} attribute is restored. |
| 140 | If not found, it is downloaded and instantiated using the |
| 141 | I{fn} constructor and added to the cache for the next open(). |
| 142 | @param url: A WSDL url. |
| 143 | @type url: str. |
| 144 | @return: The WSDL object. |
| 145 | @rtype: I{Definitions} |
| 146 | """ |
| 147 | cache = self.cache() |
| 148 | id = self.mangle(url, 'wsdl') |
| 149 | d = cache.get(id) |
| 150 | if d is None: |
| 151 | d = self.fn(url, self.options) |
| 152 | cache.put(id, d) |
| 153 | else: |
| 154 | d.options = self.options |
| 155 | for imp in d.imports: |
| 156 | imp.imported.options = self.options |
| 157 | return d |
| 158 | |
| 159 | def cache(self): |
| 160 | """ |
| 161 | Get the cache. |
| 162 | @return: The I{options} when I{cachingpolicy} = B{1}. |
| 163 | @rtype: L{Cache} |
| 164 | """ |
| 165 | if self.options.cachingpolicy == 1: |
| 166 | return self.options.cache |
| 167 | else: |
| 168 | return NoCache() |