def Get(self, subject): """This will create the connection if needed so should not fail.""" filename, directory = common.ResolveSubjectDestination( subject, self.path_regexes) key = common.MakeDestinationKey(directory, filename) try: return super(SqliteConnectionCache, self).Get(key) except KeyError: dirname = utils.JoinPath(self.root_path, directory) path = utils.JoinPath(dirname, filename) + SQLITE_EXTENSION dirname = utils.SmartStr(dirname) path = utils.SmartStr(path) # Make sure directory exists. if not os.path.isdir(dirname): try: os.makedirs(dirname) except OSError: pass self._EnsureDatabaseExists(path) connection = SqliteConnection(path) super(SqliteConnectionCache, self).Put(key, connection) return connection
def Get(self, subject): """This will create the object if needed so should not fail.""" filename, directory = common.ResolveSubjectDestination( subject, self.path_regexes) key = common.MakeDestinationKey(directory, filename) try: return super(RemoteMappingCache, self).Get(key) except KeyError: data_server = self.inquirer.MapKey(key) super(RemoteMappingCache, self).Put(key, data_server) return data_server