禁用其他包配置中的特定ZCML指令
项目描述
文档
简介
此包允许您禁用其他包中可能存在的特定ZCML配置部分。例如,让我们考虑一个打印字符串的简单ZCML指令和一个打印lolcat消息的愚蠢指令
>>> zcml(""" ... <print msg="Hello World!" /> ... <lolcat who="I" canhas="cheezburger" /> ... """) Hello World! I can has cheezburger?
现在假设这个指令被使用了多次,但我们需要防止其中一两个实例的发生。要做到这一点,我们只需在unconfigure分组指令内重复该指令。这个分组指令将查看所有之前的指令并过滤掉我们想要排除的指令
>>> zcml(""" ... <configure> ... <print msg="Hello World!" /> ... <lolcat who="I" canhas="cheezburger" /> ... <print msg="Goodbye World!" /> ... <print msg="LOL!" /> ... ... <include package="z3c.unconfigure" file="meta.zcml" /> ... <unconfigure> ... <lolcat who="I" canhas="cheezburger" /> ... <print msg="LOL!" /> ... </unconfigure> ... </configure> ... """) Hello World! Goodbye World!
如果您尝试取消配置一开始就没有配置的内容,则不会发生任何事情
>>> zcml(""" ... <configure> ... <include package="z3c.unconfigure" file="meta.zcml" /> ... <unconfigure> ... <lolcat who="I" canhas="cheezburger" /> ... </unconfigure> ... </configure> ... """)
“未配置”放置位置
您可能会问,将unconfigure指令添加到什么位置才算合适。当然,上面提供的例子并不太现实,因为原始指令和过滤器都在一个文件中。通常情况下,您可能有一些第三方包,其中包含大量配置,但您只想禁用其中一两个指令。例如,这个文件就是这样。
>>> cat('lolcat.zcml') <configure> <print msg="Hello World!" /> <print msg="Important configuration here." /> <lolcat who="I" canhas="cheezburger" /> <print msg="Goodbye World!" /> <print msg="LOL!" /> <print msg="This is the last directive" /> </configure>
现在,您可以在您的包中编写一个单独的ZCML文件。一个不错的名字可以是overrides.zcml(这是包含覆盖指令的ZCML文件的命名约定,这与unconfigure所做的工作类似)。例如,假设我们想要撤销上面第三方文件中的某些愚蠢的配置
>>> cat('overrides.zcml') <configure> <include package="z3c.unconfigure" file="meta.zcml" /> <unconfigure> <lolcat who="I" canhas="cheezburger" /> <print msg="LOL!" /> </unconfigure> </configure>
现在您需要做的是首先包含第三方包的配置,然后加载您的覆盖(这通常是通过includeOverrides完成的,您可以直接或由site.zcml为您完成)
>>> zcml(""" ... <configure> ... <include file="lolcat.zcml" /> ... <includeOverrides file="overrides.zcml" /> ... </configure> ... """) Hello World! Important configuration here. Goodbye World! This is the last directive
在这种情况下,仅通过<include />指令包含该文件也足够了。重要的是“未配置”发生在原始配置之后,覆盖文件是确保这一点的好地方。
还可以方便地取消整个zcml文件的配置。如果您在包含该文件之前使用<exclude />指令,则可以不使用z3c.unconfigure来完成此操作
>>> zcml(""" ... <configure> ... <exclude file="lolcat.zcml" /> ... <print msg="The new hello" /> ... <include file="lolcat.zcml" /> ... <include package="z3c.unconfigure" file="meta.zcml" /> ... <print msg="The final goodbye" /> ... </configure> ... """) The new hello The final goodbye
或者,您可以在未配置块内尝试使用包含语句
>>> zcml(""" ... <configure> ... <print msg="The new hello" /> ... <include file="lolcat.zcml" /> ... <include package="z3c.unconfigure" file="meta.zcml" /> ... <unconfigure> ... <include file="lolcat.zcml" /> ... </unconfigure> ... <print msg="The final goodbye" /> ... </configure> ... """) The new hello The final goodbye
变更
2.0 (2023-02-10)
放弃对Python < 3.7的支持。
添加对Python 3.7、3.8、3.9、3.10、3.11的支持。
1.1 (2012-10-26)
添加了对zope.configuration 3.8.0的支持,该版本将内部数据结构从元组更改为字典。
放弃对zope.configuration 3.7.x和旧版本的支持。
现在可以取消整个zcml文件的配置(在未配置块内使用包含语句)了。
1.0.1 (2008-08-07)
添加了.zcml文件,以便从ZCML注册<unconfigure>指令。
1.0 (2008-08-07)
第一个公共版本。
项目详情
下载文件
下载适合您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。
源代码分发
构建分发
z3c.unconfigure-2.0.tar.gz的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 256f5ae5a5b392c103f750fa4ea7e5c884a0b4a788c5d07e63601180d5be5a43 |
|
MD5 | ca7c6385a3d15a7f2592620c8bc2f703 |
|
BLAKE2b-256 | 01a09e4a4af3ac2b94cc91a316bc1788cc2884dceabf357b1eb607c25537e9a4 |
z3c.unconfigure-2.0-py3-none-any.whl的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | df82bb41b1ad13652094c04e59d53765f1b62c1453d482e3bc1ba9d818d989a9 |
|
MD5 | 35d7ab7b98a219c7db3c0b369e495898 |
|
BLAKE2b-256 | d496b7a66013290ef3a5a666cad00a3cc85f60999d78c69b872598bc0a0d4b2b |