PageSourceSearch

https://lincdocs.github.io/nonebot2/assets/utils.html-BHzwJw9f.js

js lincdocs.github.io collected 2026-10-03 09:32:26 UTC 11,896 bytes, 1 lines download raw bytes

1import{_ as n,c as r,a as t,b as e,d as o,e as p,w as s,r as c,o as d}from"./app-cR-NuifS.js";const u={};function a(g,l){const i=c("RouteLink");return d(),r("div",null,[l[6]||(l[6]=t('<h1 id="nonebot-utils" tabindex="-1">nonebot.utils</h1><p>本模块包含了 NoneBot 的一些工具函数</p><h2 id="escape-tag" tabindex="-1"><em>def</em> <code>escape_tag(s)</code></h2><ul><li><p><strong>说明</strong></p><p>用于记录带颜色日志时转义 <code>&lt;tag&gt;</code> 类型特殊标签</p><p>参考: <a href="https://loguru.readthedocs.io/en/stable/api/logger.html#color" target="_blank" rel="noopener noreferrer">loguru color 标签</a></p></li><li><p><strong>参数</strong></p><ul><li><code>s</code> (str): 需要转义的字符串</li></ul></li><li><p><strong>返回</strong></p><ul><li>str</li></ul></li></ul><h2 id="deep-update" tabindex="-1"><em>def</em> <code>deep_update(mapping, *updating_mappings)</code></h2><ul><li><p><strong>说明:</strong> 深度更新合并字典</p></li><li><p><strong>参数</strong></p><ul><li><p><code>mapping</code> (dict[K, Any])</p></li><li><p><code>*updating_mappings</code> (dict[K, Any])</p></li></ul></li><li><p><strong>返回</strong></p><ul><li>dict[K, Any]</li></ul></li></ul><h2 id="lenient-issubclass" tabindex="-1"><em>def</em> <code>lenient_issubclass(cls, class_or_tuple)</code></h2><ul><li><p><strong>说明:</strong> 检查 cls 是否是 class_or_tuple 中的一个类型子类并忽略类型错误。</p></li><li><p><strong>参数</strong></p><ul><li><p><code>cls</code> (Any)</p></li><li><p><code>class_or_tuple</code> (type[Any] | tuple[type[Any], ...])</p></li></ul></li><li><p><strong>返回</strong></p><ul><li>bool</li></ul></li></ul><h2 id="generic-check-issubclass" tabindex="-1"><em>def</em> <code>generic_check_issubclass(cls, class_or_tuple)</code></h2><ul><li><p><strong>说明</strong></p><p>检查 cls 是否是 class_or_tuple 中的一个类型子类。</p><p>特别的:</p><ul><li>如果 cls 是 <code>typing.TypeVar</code> 类型,<br> 则会检查其 <code>__bound__</code> 或 <code>__constraints__</code><br> 是否是 class_or_tuple 中一个类型的子类或 None。</li><li>如果 cls 是 <code>typing.Union</code> 或 <code>types.UnionType</code> 类型,<br> 则会检查其中的所有类型是否是 class_or_tuple 中一个类型的子类或 None。</li><li>如果 cls 是 <code>typing.Literal</code> 类型,<br> 则会检查其中的所有值是否是 class_or_tuple 中一个类型的实例。</li><li>如果 cls 是 <code>typing.List</code>、<code>typing.Dict</code> 等泛型类型,<br> 则会检查其原始类型是否是 class_or_tuple 中一个类型的子类。</li></ul></li><li><p><strong>参数</strong></p><ul><li><p><code>cls</code> (Any)</p></li><li><p><code>class_or_tuple</code> (type[Any] | tuple[type[Any], ...])</p></li></ul></li><li><p><strong>返回</strong></p><ul><li>bool</li></ul></li></ul><h2 id="type-is-complex" tabindex="-1"><em>def</em> <code>type_is_complex(type_)</code></h2><ul><li><p><strong>说明:</strong> 检查 type_ 是否是复杂类型</p></li><li><p><strong>参数</strong></p><ul><li><code>type_</code> (type[Any])</li></ul></li><li><p><strong>返回</strong></p><ul><li>bool</li></ul></li></ul><h2 id="is-coroutine-callable" tabindex="-1"><em>def</em> <code>is_coroutine_callable(call)</code></h2><ul><li><p><strong>说明:</strong> 检查 call 是否是一个 callable 协程函数</p></li><li><p><strong>参数</strong></p><ul><li><code>call</code> ((...) -&gt; Any)</li></ul></li><li><p><strong>返回</strong></p><ul><li>bool</li></ul></li></ul><h2 id="is-gen-callable" tabindex="-1"><em>def</em> <code>is_gen_callable(call)</code></h2><ul><li><p><strong>说明:</strong> 检查 call 是否是一个生成器函数</p></li><li><p><strong>参数</strong></p><ul><li><code>call</code> ((...) -&gt; Any)</li></ul></li><li><p><strong>返回</strong></p><ul><li>bool</li></ul></li></ul><h2 id="is-async-gen-callable" tabindex="-1"><em>def</em> <code>is_async_gen_callable(call)</code></h2><ul><li><p><strong>说明:</strong> 检查 call 是否是一个异步生成器函数</p></li><li><p><strong>参数</strong></p><ul><li><code>call</code> ((...) -&gt; Any)</li></ul></li><li><p><strong>返回</strong></p><ul><li>bool</li></ul></li></ul><h2 id="run-sync" tabindex="-1"><em>def</em> <code>run_sync(call)</code></h2><ul><li><p><strong>说明:</strong> 一个用于包装 sync function 为 async function 的装饰器</p></li><li><p><strong>参数</strong></p><ul><li><code>call</code> ((P) -&gt; R): 被装饰的同步函数</li></ul></li><li><p><strong>返回</strong></p><ul><li>(P) -&gt; Coroutine[None, None, R]</li></ul></li></ul><h2 id="run-sync-ctx-manager" tabindex="-1"><em>def</em> <code>run_sync_ctx_manager(cm)</code></h2><ul><li><p><strong>说明:</strong> 一个用于包装 sync context manager 为 async context manager 的执行函数</p></li><li><p><strong>参数</strong></p><ul><li><code>cm</code> (AbstractContextManager[T])</li></ul></li><li><p><strong>返回</strong></p><ul><li>AsyncGenerator[T, None]</li></ul></li></ul><h2 id="run-coro-with-catch" tabindex="-1"><em>async def</em> <code>run_coro_with_catch(coro, exc, return_on_err=None)</code></h2><ul><li><p><strong>说明:</strong> 运行协程并当遇到指定异常时返回指定值。</p></li><li><p><strong>重载</strong></p><p><strong>1.</strong> <code>(coro, exc, return_on_err=None) -&gt; T | None</code></p><ul><li><p><strong>参数</strong></p><ul><li><p><code>coro</code> (Coroutine[Any, Any, T])</p></li><li><p><code>exc</code> (tuple[type[Exception], ...])</p></li><li><p><code>return_on_err</code> (None)</p></li></ul></li><li><p><strong>返回</strong></p><ul><li>T | None</li></ul></li></ul><p><strong>2.</strong> <code>(coro, exc, return_on_err) -&gt; T | R</code></p><ul><li><p><strong>参数</strong></p><ul><li><p><code>coro</code> (Coroutine[Any, Any, T])</p></li><li><p><code>exc</code> (tuple[type[Exception], ...])</p></li><li><p><code>return_on_err</code> (R)</p></li></ul></li><li><p><strong>返回</strong></p><ul><li>T | R</li></ul></li></ul></li><li><p><strong>参数</strong></p><ul><li><p><code>coro</code>: 要运行的协程</p></li><li><p><code>exc</code>: 要捕获的异常</p></li><li><p><code>return_on_err</code>: 当发生异常时返回的值</p></li></ul></li><li><p><strong>返回</strong></p><p>协程的返回值或发生异常时的指定值</p></li></ul><h2 id="run-coro-with-shield" tabindex="-1"><em>async def</em> <code>
1run_coro_with_shield(coro)</code></h2><ul><li><p><strong>说明:</strong> 运行协程并在取消时屏蔽取消异常。</p></li><li><p><strong>参数</strong></p><ul><li><code>coro</code> (Coroutine[Any, Any, T]): 要运行的协程</li></ul></li><li><p><strong>返回</strong></p><ul><li>T: 协程的返回值</li></ul></li></ul><h2 id="flatten-exception-group" tabindex="-1"><em>def</em> <code>flatten_exception_group(exc_group)</code></h2><ul><li><p><strong>参数</strong></p><ul><li><code>exc_group</code> (BaseExceptionGroup[E])</li></ul></li><li><p><strong>返回</strong></p><ul><li>Generator[E, None, None]</li></ul></li></ul><h2 id="get-name" tabindex="-1"><em>def</em> <code>get_name(obj)</code></h2><ul><li><p><strong>说明:</strong> 获取对象的名称</p></li><li><p><strong>参数</strong></p><ul><li><code>obj</code> (Any)</li></ul></li><li><p><strong>返回</strong></p><ul><li>str</li></ul></li></ul><h2 id="path-to-module-name" tabindex="-1"><em>def</em> <code>path_to_module_name(path)</code></h2><ul><li><p><strong>说明:</strong> 转换路径为模块名</p></li><li><p><strong>参数</strong></p><ul><li><code>path</code> (Path)</li></ul></li><li><p><strong>返回</strong></p><ul><li>str</li></ul></li></ul><h2 id="resolve-dot-notation" tabindex="-1"><em>def</em> <code>resolve_dot_notation(obj_str, default_attr, default_prefix=None)</code></h2><ul><li><p><strong>说明:</strong> 解析并导入点分表示法的对象</p></li><li><p><strong>参数</strong></p><ul><li><p><code>obj_str</code> (str)</p></li><li><p><code>default_attr</code> (str)</p></li><li><p><code>default_prefix</code> (str | None)</p></li></ul></li><li><p><strong>返回</strong></p><ul><li>Any</li></ul></li></ul><h2 id="classproperty" tabindex="-1"><em>class</em> <code>classproperty(func)</code></h2><ul><li><p><strong>说明:</strong> 类属性装饰器</p></li><li><p><strong>参数</strong></p><ul><li><code>func</code> ((Any) -&gt; T)</li></ul></li></ul><h2 id="DataclassEncoder" tabindex="-1"><em>class</em> <code>DataclassEncoder(&lt;auto&gt;)</code></h2>',37)),e("ul",null,[e("li",null,[e("p",null,[l[1]||(l[1]=e("strong",null,"说明:",-1)),l[2]||(l[2]=o(" 可以序列化 ",-1)),p(i,{to:"/version-2.4.3/api/adapters/#Message"},{default:s(()=>[...l[0]||(l[0]=[o("Message",-1)])]),_:1}),l[3]||(l[3]=o("(List[Dataclass]) 的 ",-1)),l[4]||(l[4]=e("code",null,"JSONEncoder",-1))])]),l[5]||(l[5]=e("li",null,[e("p",null,[e("strong",null,"参数")]),e("p",null,"auto")],-1))]),l[7]||(l[7]=t('<h3 id="DataclassEncoder-default" tabindex="-1"><em>method</em> <code>default(o)</code></h3><ul><li><p><strong>参数</strong></p><ul><li><code>o</code></li></ul></li><li><p><strong>返回</strong></p><ul><li>untyped</li></ul></li></ul><h2 id="logger-wrapper" tabindex="-1"><em>def</em> <code>logger_wrapper(logger_name)</code></h2><ul><li><p><strong>说明:</strong> 用于打印 adapter 的日志。</p></li><li><p><strong>参数</strong></p><ul><li><code>logger_name</code> (str): adapter 的名称</li></ul></li><li><p><strong>返回</strong></p><ul><li><p>untyped: 日志记录函数</p><p>日志记录函数的参数:</p><ul><li>level: 日志等级</li><li>message: 日志信息</li><li>exception: 异常信息</li></ul></li></ul></li></ul>',4))])}const _=n(u,[["render",a]]),h=JSON.parse('{"path":"/version-2.4.3/api/utils.html","title":"nonebot.utils","lang":"zh-CN","frontmatter":{"mdx":{"format":"md"},"sidebar_position":8,"description":"nonebot.utils 模块","head":[["script",{"type":"application/ld+json"},"{\\"@context\\":\\"https://schema.org\\",\\"@type\\":\\"Article\\",\\"headline\\":\\"nonebot.utils\\",\\"image\\":[\\"\\"],\\"dateModified\\":null,\\"author\\":[]}"],["meta",{"property":"og:url","content":"https://LincDocs.github.io/nonebot2/version-2.4.3/api/utils.html"}],["meta",{"property":"og:site_name","content":"nonebot2"}],["meta",{"property":"og:title","content":"nonebot.utils"}],["meta",{"property":"og:description","content":"nonebot.utils 模块"}],["meta",{"property":"og:type","content":"article"}],["meta",{"property":"og:locale","content":"zh-CN"}]]},"git":{},"readingTime":{"minutes":2.96,"words":887},"filePathRelative":"version-2.4.3/api/utils.md","excerpt":"\\n<p>本模块包含了 NoneBot 的一些工具函数</p>\\n<h2><em>def</em> <code>escape_tag(s)</code></h2>\\n<ul>\\n<li>\\n<p><strong>说明</strong></p>\\n<p>用于记录带颜色日志时转义 <code>&lt;tag&gt;</code> 类型特殊标签</p>\\n<p>参考: <a href=\\"https://loguru.readthedocs.io/en/stable/api/logger.html#color\\" target=\\"_blank\\" rel=\\"noopener noreferrer\\">loguru color 标签</a></p>\\n</li>\\n<li>\\n<p><strong>参数</strong></p>\\n<ul>\\n<li><code>s</code> (str): 需要转义的字符串</li>\\n</ul>\\n</li>\\n<li>\\n<p><strong>返回</strong></p>\\n<ul>\\n<li>str</li>\\n</ul>\\n</li>\\n</ul>","bioChainData":{"outlink":[{"title":"index","link":"version-2.4.3/api/adapter
1s/index.html"}],"backlink":[],"localMap":{"nodes":[{"id":"version-2.4.3/api/utils.md","value":{"title":"utils","path":"version-2.4.3/api/utils.md","outlink":["version-2.4.3/api/adapters/index.md"],"backlink":[]}},{"id":"version-2.4.3/api/adapters/index.md","value":{"title":"index","path":"version-2.4.3/api/adapters/index.md","outlink":[],"backlink":[]}}],"links":[{"source":"version-2.4.3/api/utils.md","target":"version-2.4.3/api/adapters/index.md"}]}}}');export{_ as comp,h as data};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.