zcml:condition 的有效条件是什么?

发布于 2024-08-08 13:42:59 字数 229 浏览 6 评论 0原文

ZCML 可以包含以下形式的条件指令:

<configure zcml:condition="installed some.python.package">
    (conditional configuration directives)
</configure>

condition 的表达式语法是什么?允许“或”吗?

ZCML can include conditional directives of the form

<configure zcml:condition="installed some.python.package">
    (conditional configuration directives)
</configure>

What is the expression syntax for condition? Is 'or' allowed?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

街角迷惘 2024-08-15 13:42:59

我也总是要查一下这个。语法非常简单,恐怕 or 不是语法的一部分。

正如您可以从 zope.configuration 源代码中的文档,语法始终采用 verb argument 形式,其中 verb 是 have、<代码>未安装、<代码>已安装和<代码>未安装。

havenot-have 测试已注册的功能。注册的功能只是一个使用 标记注册的不透明字符串。使用它来标记某些内容已被包含,而不将其绑定到特定的实现。示例:

<configure zcml:condition="have apidoc">
    <!-- only when the apidoc feature has been provided -->
</configure>

已安装未安装只需尝试导入指定的包;如果导入成功,installed 测试也会成功。例子:

<configure zcml:condition="installed sqlalchemy"> 
    <!-- only when the sqlalchemy module can be imported -->
</configure>

I always have to look this up too. The syntax is very simple, and or is not part of the syntax, I am afraid.

As you can see from the documentation in the zope.configuration source code, the syntax is always of the form verb arguments, where verb is one of have, not-have, installed and not-installed.

have and not-have test for a registered feature. A registered feature is simply an opaque string that has been registered with a <meta:provides feature="something" /> tag. Use it to flag that something has been included without tying it to a particular implementation. Example:

<configure zcml:condition="have apidoc">
    <!-- only when the apidoc feature has been provided -->
</configure>

installed and not-installed simply try to import the named package; if the import succeeds so does the installed test. Example:

<configure zcml:condition="installed sqlalchemy"> 
    <!-- only when the sqlalchemy module can be imported -->
</configure>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文