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

joe*_*ker 8 zope zcml

ZCML可以包含表单的条件指令

<configure zcml:condition="installed some.python.package">
    (conditional configuration directives)
</configure>
Run Code Online (Sandbox Code Playgroud)

表达式的语法是condition什么?是'或'允许?

Mar*_*ers 15

我也经常要这样看.语法非常简单,or恐怕不是语法的一部分.

正如你可以看到从在zope.configuration源代码的文档,语法始终是形式的verb arguments,其中动词是一个have,not-have,installednot-installed.

havenot-have测试已注册的功能.注册的功能只是一个注册了<meta:provides feature="something" />标签的不透明字符串.使用它来标记已包含的内容,而不将其绑定到特定实现.例:

<configure zcml:condition="have apidoc">
    <!-- only when the apidoc feature has been provided -->
</configure>
Run Code Online (Sandbox Code Playgroud)

installednot-installed只是尝试导入命名包; 如果导入成功,那么installed测试也是如此.例:

<configure zcml:condition="installed sqlalchemy"> 
    <!-- only when the sqlalchemy module can be imported -->
</configure>
Run Code Online (Sandbox Code Playgroud)