What are the valid conditions for zcml:condition?

≡放荡痞女 提交于 2019-11-28 00:40:10

问题


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?


回答1:


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>


来源:https://stackoverflow.com/questions/1596611/what-are-the-valid-conditions-for-zcmlcondition

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!