def process(self, constant, content): if constant.options["src"] is not None: try: # Translate relative paths and such. We'll need to look up # the actual XmlConfig handling this constant. Its root # element will know the name originally passed into # getConfig(name) url = getConfig(constant.root.name).get_real_location( constant.options["src"], for_import=True) fp = urlopen(url) except ValueError: # Invalid url raise else: return fp.read()
def load(self, url, namespace=LOCAL_NAMESPACE, for_import=False): # Keep track of loaded files to ward off circular dependencies. If # a file is requested to be loaded that is already, and it has not # been modified since loading, don't load it. load = False # Get normalized, real location of url url = self.get_real_location(url, for_import) # Go ahead and open the url now so that we can check the time of # last update (for reloading) content = urlopen(url) if len(self._files) == 0: # This is the first document loaded. Remember it for future # reloading and importing, etc. self._original_url = url if url in self._files: # Don't load if the file is already loaded under a difference # namespace if self._files[url]['namespace'] != namespace: # Already loaded this file, so just create a link to another # namespace. This will allow two documents to import the same # document into different namespaces. Doing so without links # would create unnecessary imports and potential circular # dependency issues self.links[namespace] = self._files[url]['namespace'] load = False # # XXX Check if 'last-modified' in headers # Reload if the file has been modified elif self._files[url]['headers']['last-modified'] \ != content.headers['last-modified']: load = True # # If file has never been loaded, it should be loaded (duh) else: load=True if load: self.on_load.fire(url, namespace) self._files[url] = { 'namespace': namespace, 'headers': dict(content.headers.items()) } self.parse(content, namespace) content.close()