Easily hook into the ZCML processing machinery
Project description
Introduction
This package provides means of hooking into the Zope (ZCML) configuration process.
Custom ZCML actions
It is sometimes useful to execute a function during the execution of configuration actions, for example to perform one-off configuration that does not warrant a new directive. The <zcml:customAction /> directive is provided for this purpose.
For example, you may want to call a function called my.package.finalConfiguration() “late” in the configuration action execution cycle. This can be achieved with the following ZCML statements:
<configure xmlns="http://namespaces.zope.org/zope" xmlns:zcml="http://namespaces.zope.org/zcml" i18n_domain="my.package"> <include package="z3c.zcmlhook" file="meta.zcml" /> <zcml:customAction handler="my.package.finalConfiguration" order="9999" /> </configure>
The handler attribute gives the name of a function to execute. The function should take no arguments. The order attribute is optional, and can be used to influence when in the configuration cycle the function is executed. The default value for this, as for most Zope configuration actions, is 0.
Overriding custom actions
If you want to override the invocation of a custom handler in an overrides.zcml, you need to tell zope.configuration which handler to override. You can do that by setting the discriminator explicitly. A discriminator is used to uniquely identify a configuration action. In the case of the <zcml:customAction /> directive, the discriminator is based on the full dotted name to the function by default. Thus, you could override the function call above like so:
<zcml:customAction handler="my.otherpackage.overrideFinalConfiguration" discriminator="my.package.finalConfiguration" order="9999" />
Using a handler more than once
The discriminator attribute can also be used to explicitly allow using the same handler more than once. If you wanted to call my.package.finalConfiguration again, you would normally get a configuration conflict. However, with a (unique) custom discriminator, the second call is allowed:
<zcml:customAction handler="my.package.finalConfiguration" discriminator="my.package.finalConfiguration:early" order="-9999" /> <zcml:customAction handler="my.package.finalConfiguration" discriminator="my.package.finalConfiguration:late" order="9999" />
Here, we are attempting to call our configuration action “very early” as well as “very late” in the configuration process.
Changelog
2.0 (2023-02-24)
Add support for Python 3.10, 3.11.
Drop support for Python 2.7, 3.5, 3.6.
1.1 (2021-02-15)
Add support for Python 3.5, 3.6, 3.7, 3.8 and 3.9.
Add test extra to declare test dependency on zope.component [test]. [icemac]
1.0b1 (2010-01-02)
Initial release [optilude]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file z3c.zcmlhook-2.0.tar.gz
.
File metadata
- Download URL: z3c.zcmlhook-2.0.tar.gz
- Upload date:
- Size: 8.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 21078e39af9579ceb9c25b56e0283b0959b0d7292fbe5187dc0ed75ffe5cec04 |
|
MD5 | 7a0a9284dc6f94d39e47de1bb4967940 |
|
BLAKE2b-256 | f3da09f14b2cc3d34270c3ed01521f07e1f484f92d8af0afc29b292aecac7086 |
File details
Details for the file z3c.zcmlhook-2.0-py3-none-any.whl
.
File metadata
- Download URL: z3c.zcmlhook-2.0-py3-none-any.whl
- Upload date:
- Size: 7.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6899120a092eca16eeacfb0223b6c03596ae82e9607505c8e9ee497aa56f944d |
|
MD5 | d3de65bcdb67764b87e2db868527ae27 |
|
BLAKE2b-256 | f17b12af6c2cbca827922fd2960aa219f6e05ce8b3bef7a5b62d244031026915 |