ToolDelta ICU

tempjson

attributePathLike
= str | os.PathLike[str]
attributeVT
= TypeVar('VT')
attributetempjson_rw_lock
= Lock()
attributetempjson_pathsdict[PathLike, _jsonfile_status]
= {}
funcload_from_path(path, need_file_exists=True, default=None, unload_delay=None) -> _jsonfile_status

将 json 文件从磁盘加载到缓存区,以便快速读写. 在缓存文件已加载的情况下,再使用一次该方法不会有任何作用.

Args: path (str): 作为文件的磁盘内路径的同时也会作为在缓存区的虚拟路径 needFileExists (bool, optional): 默认为 True, 为 False 时,若文件路径不存在,就会自动创建一个文件 default (Any, optional): 默认为 None, 为 None 时,若文件路径不存在,就会自动创建一个文件,且写入默认值 null unload_delay (int, optional): 多久没有再进行读写操作时, 将其从缓存卸载

Raises: err: 文件不存在时

parampathPathLike
paramneed_file_existsbool
= True
paramdefaultAny
= None
paramunload_delayint | None
= None

Returns

tooldelta.utils.tempjson._jsonfile_status
funcunload_to_path(path) -> bool

将 json 文件从缓存区卸载 (保存内容到磁盘), 之后不能再在缓存区对这个文件进行读写. 在缓存文件已卸载的情况下,再使用一次该方法不会有任何作用,但是可以通过其返回的值来知道存盘有没有成功.

Args: path (str): 文件的虚拟路径

Returns: bool: 存盘是否成功

parampathPathLike

Returns

bool
funcread(path, deepcopy=True)

对缓存区的该虚拟路径的文件进行读操作,返回一个深拷贝的 JSON 对象

Args: path (str): 文件的虚拟路径

Raises: Exception: json 路径未初始化,不能进行读取和写入操作

Returns: list[Any] | dict[Any, Any] | Any: 该虚拟路径的 JSON

parampathPathLike
paramdeepcopybool
= True

Returns

None
funcget(path) -> Any

直接获取缓存区的该虚拟路径的 JSON, 不使用 copy WARNING: 如果你不知道有什么后果,请老老实实使用read(...)而不是get(...)!

Args: path (str): 文件的虚拟路径

parampathPathLike

Returns

typing.Any
funcwrite(path, obj) -> None

对缓存区的该虚拟路径的文件进行写操作,这将会覆盖之前的内容

Args: path (str): 文件的虚拟路径 obj (Any): 任何合法的 JSON 类型 例如 dict/list/str/bool/int/float

parampathPathLike
paramobjAny

Returns

None
funcload_and_read(path, need_file_exists=True, timeout=60, default={}) -> VT

读取 json 文件并将其从磁盘加载到缓存区,以便一段时间内能快速读写.

Args: path (str): 作为文件的磁盘内路径的同时也会作为在缓存区的虚拟路径 needFileExists (bool, optional): 默认为 True, 为 False 时,若文件路径不存在,就会自动创建一个文件,且写入默认值 null timeout (int, optional): 多久没有再进行读取操作时卸载缓存 default (() -> Any | Any, optional):

Returns: Any: 该虚拟路径的 JSON

parampathPathLike
paramneed_file_existsbool
= True
paramtimeoutint
= 60
paramdefaultCallable[[], VT] | VT
= {}

Returns

tooldelta.utils.tempjson.VT
funcload_and_write(path, obj, need_file_exists=True, timeout=60) -> None

写入 json 文件并将其从磁盘加载到缓存区,以便一段时间内能快速读写.

Args: path (str): 作为文件的磁盘内路径的同时也会作为在缓存区的虚拟路径 obj (Any): 任何合法的 JSON 类型 例如 dict/list/str/bool/int/float needFileExists (bool, optional): 默认为 True, 为 False 时,若文件路径不存在,就会自动创建一个文件,且写入默认值 null timeout (int, optional): 多久没有再进行读取操作时卸载缓存

parampathPathLike
paramobjAny
paramneed_file_existsbool
= True
paramtimeoutint
= 60

Returns

None
funccancel_change(path)

取消缓存 json 所做的更改,非必要情况请勿调用,你不知道什么时候会自动保存所做更改

parampathstr

Returns

None
funcflush(path=None)

刷新单个/全部JSON缓存区的缓存文件, 存入磁盘

Args: path (str | None, optional): 文件虚拟路径, 默认全部存盘

parampathPathLike | None
= None

Returns

None
funcget_tmps() -> dict

获取缓存区中所有临时文件

Returns

dict
funcjsonfile_auto_save()

Returns

None
funcsave_all()

Returns

None
funcreset()

Returns

None