Exemplo n.º 1
0
 def __init__(self,
              spill_directory: str,
              max_weight: int | Literal[False] = False):
     super().__init__(
         partial(serialize_bytelist, on_error="raise"),
         deserialize_bytes,
         zict.File(spill_directory),
     )
     self.max_weight = max_weight
     self.weight_by_key = {}
     self.total_weight = SpilledSize(0, 0)
Exemplo n.º 2
0
        def __init__(self, directory):
            self._directory = directory
            self._file = zict.File(directory)
            self._cache = {}
            super().__init__(self._dump, self._load, self._file)
            self.reload()

            # Similar to flush() or _do_update(), but without reference to self
            # to avoid circular reference preventing collection.
            # NOTE: This still doesn't guarantee call on delete or gc.collect()!
            #       Explicitly call flush() if immediate write to disk required.
            def finalize(zfile, cache, dump):
                zfile.update((k, dump(v)) for k, v in cache.items())

            import weakref
            self._finalizer = weakref.finalize(
                self, finalize, self._file, self._cache, PersistentDict._dump)
Exemplo n.º 3
0
 def __init__(self, directory):
     self._directory = directory
     self._file = zict.File(directory)
     super().__init__(self._dump, self._load, self._file)
Exemplo n.º 4
0
    def user_log(self):
        return Directory(self.user_log_dir)

    @property
    def user_state(self):
        return Directory(self.user_state_dir)


renvdirs = ReplEnvDirs()

if not renvdirs.user_config.exists:
    renvdirs.user_config.makedirs()

ENCODING = sys.getfilesystemencoding().upper()  # 'UTF-8'

zfile = zict.File(str(renvdirs.user_config), mode='a')
zutf8 = zict.Func(dump=attr(plistlib, 'dumps', 'writePlistToString'),
                  load=attr(plistlib, 'loads', 'readPlistFromString'),
                  d=zfile)
zfunc = zict.Func(
    dump=lambda value: isstring(value) and value.encode(ENCODING) or value,
    load=lambda value: isbytes(value) and value.decode(ENCODING) or value,
    d=zutf8)


@export
def has(key):
    """ Test if a key is contained in the key-value store. """
    return key in zfunc