Skip to main content

nonebot-plugin-tempfile

✨ 适用于 NoneBot2 插件的临时文件/IO 依赖注入支持 ✨

license PyPI - Downloads pypi python

介绍

nonebot-plugin-tempfile 是帮助开发者利用依赖注入特性辅助管理临时文件/IO 的库插件,支持结束会话时自动清理临时文件(夹)。

安装

通过 nb-cli:

nb plugin install nonebot-plugin-tempfile

使用

加载模块

from nonebot import require

require("nonebot_plugin_tempfile")

简单管理临时文件(夹)

from nonebot_plugin_tempfile import SimpleTempFile, SimpleTempDir

@some_matcher.handle()
async def some_handler(tmpfile: SimpleTempFile):
    # tmp is a `pathlib.Path` in function
    ...

@some_matcher.handle()
async def some_handler(tmpdir: SimpleTempDir):
    # tmp is a `pathlib.Path` in function
    ...

注意:Simple 开头的依赖类型无法同时使用多个,注入值在同一上下文内相同。

如有管理多个临时文件的需求,请另行声明自有依赖。

自定义临时文件(夹)

from nonebot_plugin_tempfile import TempFile, TempDir

@some_matcher.handle()
async def some_handler(tmp1: Path = TempFile(".png"), tmp2: Path = TempFile(".txt", "tmp-someplugin-")):
    ...

tmpdir = TempDir(prefix="tmp-kazoo-")
tmpdir2 = TempDir(dir=tmpdir)
# 支持目录嵌套

@some_matcher.handle()
async def some_handler(
    tmp1: Path = TempFile(".png", dir=tmpdir),
    tmp2: Path = TempFile(".txt", "tmp-someplugin-", dir=tmpdir2)
):
    ...

注入虚拟 IO

from io import StringIO, BytesIO
from nonebot_plugin_tempfile import TempStringIO, TempBytesIO

@some_matcher.handle()
async def some_handler(tmp1: StringIO = TempStringIO(), tmp2: BytesIO = TempBytesIO()):
    ...

@some_matcher.handle()
async def some_handler(tmp1: BytesIO = TempBytesIO(), tmp2: BytesIO = TempBytesIO()):
    ...

配置

本插件增加了下列可选配置项,有需要的用户请自行在 .env 或选用的以 .env 开头的文件中配置:

# 下列配置项请按需解除注释并配置

# 临时文件默认前缀(字符串)
# tempfile_default_prefix=tmpnonebot

Metadata

Release files for nonebot-plugin-tempfile 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nonebot-plugin-tempfile 0.2.0
File Size Uploaded Provenance Actions
nonebot_plugin_tempfile-0.2.0.tar.gz 4.3 kB Without provenance Details for nonebot_plugin_tempfile-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for nonebot-plugin-tempfile 0.2.0
File Interpreter ABI Platform Actions
nonebot_plugin_tempfile-0.2.0-py3-none-any.whl Python 3 none any Details for nonebot_plugin_tempfile-0.2.0-py3-none-any.whl

Total release size: 9.4 kB

Release files / nonebot_plugin_tempfile-0.2.0.tar.gz

Download URL nonebot_plugin_tempfile-0.2.0.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
d331be47f42cf22d4b5854dce52d7e12e9294c3b6ca57ccd9ddd62e19dff6d39
BLAKE2b-256 checksum
How to use checksums
e361842fcaa914242022dc85838b473a29354f5fe0474cf8507d748c6539ad39
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.0.0 CPython/3.12.3

Release files / nonebot_plugin_tempfile-0.2.0-py3-none-any.whl

Download URL nonebot_plugin_tempfile-0.2.0-py3-none-any.whl
Size 5.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ca611dc6cceda3443757db9e43c85eb790688488f492c5ecafd467cd0b68a957
BLAKE2b-256 checksum
How to use checksums
8e00d79ef7bafe3abc9b150a2ed71f8f64d925d95ce4f2ae7205610b267b5206
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.0.0 CPython/3.12.3

Security for nonebot-plugin-tempfile 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page