Skip to main content

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

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

z3c.zcmlhook-1.1.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

z3c.zcmlhook-1.1-py2.py3-none-any.whl (7.7 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file z3c.zcmlhook-1.1.tar.gz.

File metadata

  • Download URL: z3c.zcmlhook-1.1.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/None requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.9

File hashes

Hashes for z3c.zcmlhook-1.1.tar.gz
Algorithm Hash digest
SHA256 7471eb0f2f45dde3678413dcf400a6a4128ec9779aa87b40b47840b9f226eb55
MD5 4cfa067d824ad5a899f0ce6fe0743f3e
BLAKE2b-256 49a5e89278c81a33798c597bd3501110f239d06ead4862032dc60f18ca3f3012

See more details on using hashes here.

File details

Details for the file z3c.zcmlhook-1.1-py2.py3-none-any.whl.

File metadata

  • Download URL: z3c.zcmlhook-1.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/None requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.9

File hashes

Hashes for z3c.zcmlhook-1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 15a18f09b2e9b38cf5c208e8aca1fe8c81d16ad9e05aa986b42aad24ef9ecc83
MD5 cc6ee58cb290f9a278d83f39784ce0b8
BLAKE2b-256 92de4209b00b0dab604352ea8805e48c7823ebc3258cd8bd3b78f7937d601642

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page