def __getitem__(self, key): if self.cache_responses: if key in self.seen_layers: return self.seen_layers[key] elif key in self.lookup_failures: # If we are caching, raise KnownUnknown if we have previously failed to find this layer raise TileStache.KnownUnknown("Layer %s previously not found", key) logging.debug("Requesting layer %s", self.url_root + "/layer/" + key) res = urlopen(self.url_root + "/layer/" + key) if (res.getcode() != 200): logging.info("Config response code %s for %s", res.getcode(), key) if (self.cache_responses): self.lookup_failures.add(key) raise TileStache.KnownUnknown("Layer %s not found", key) try: layer = self.parse_layer(res) self.seen_layers[key] = layer return layer except ValueError: logging.error("Invalid JSON response seen for %s", key) if (self.cache_responses): # If caching responses, cache this failure self.lookup_failures.add(key) # KnownUnknown seems like the appropriate thing to raise here since this is akin # to a missing configuration. raise TileStache.KnownUnknown( "Failed to parse JSON configuration for %s", key)