-->

什么是ZCML的有效条件:条件?(What are the valid conditions for

2019-08-22 04:57发布

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

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

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

Answer 1:

我一直有看这件事了。 语法很简单, or是不是语法的一部分,我很害怕。

正如你可以看到从在zope.configuration源代码文件 ,语法是永远的形式verb arguments ,其中动词是一个havenot-haveinstallednot-installed

havenot-have试验的注册功能。 已注册的特征仅仅是已注册用一个不透明的字符串<meta:provides feature="something" />标记。 它使用的东西已被列入没有它捆绑到特定的实现标志。 例:

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

installednot-installed简单尝试导入指定的包; 如果导入成功,所以做了installed测试。 例:

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


文章来源: What are the valid conditions for zcml:condition?
标签: zope zcml