Skip to main content

Disable specific ZCML directives in other package's configuration

Project description

Documentation

Introduction

This package allows you to disable specific bits of ZCML configuration that may occur in other packages. For instance, let’s consider a simple ZCML directive that prints strings and a silly one that prints lolcat messages:

>>> zcml("""
... <print msg="Hello World!" />
... <lolcat who="I" canhas="cheezburger" />
... """)
Hello World!
I can has cheezburger?

Now let’s say this directive were used a bunch of times, but we wanted to prevent one or two of its occurrences. To do that we simply repeat the directive inside the unconfigure grouping directive. This grouping directive will look at all the previous directives and filter out the ones we want to exclude:

>>> 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!

If you’re trying to unconfigure something that hasn’t been configured in the first place, nothing will happen:

>>> zcml("""
... <configure>
...   <include package="z3c.unconfigure" file="meta.zcml" />
...   <unconfigure>
...     <lolcat who="I" canhas="cheezburger" />
...   </unconfigure>
... </configure>
... """)

Where to place “unconfiguration”

What’s a good place to add the unconfigure directives, you may ask. Certainly, the example from above is not very realistic because both the original directives and the filters are in one file. What typically happens is that you have some third party package that has much configuration of which you’d like to disable just one or two directives. Like this file, for instance:

>>> 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>

What you can do now is write a separate ZCML file in your package. A good name for it would be overrides.zcml (which is the naming convention for ZCML files containing overriding directives, a technique not unlike to what unconfigure does). For example, let’s say we wanted to undo some silly configuration in the above third party file:

>>> cat('overrides.zcml')
<configure>
  <include package="z3c.unconfigure" file="meta.zcml" />
  <unconfigure>
    <lolcat who="I" canhas="cheezburger" />
    <print msg="LOL!" />
  </unconfigure>
</configure>

What you would do now is include first that third party package’s configuration and then load your overrides (which is typically done using includeOverrides, either explicitly by you or for you by 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

In this case, simply including the file with the <include /> directive would’ve sufficed as well. What matters is that the “unconfiguration” happens after the original configuration, and override files are a good place to ensure this.

It can also be conveniend to unconfigure an entire zcml file. This can be done without using z3c.unconfigure, if you use the <exclude /> directive before you include that file:

>>> 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

Or you can try to use an include statement inside an unconfigure block:

>>> 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

Changes

2.0 (2023-02-10)

  • Drop support for Python < 3.7.

  • Add support for Python 3.7, 3.8, 3.9, 3.10, 3.11.

1.1 (2012-10-26)

  • Added support for zope.configuration 3.8.0, which changed the internal data structures from tuples to dicts.

  • Dropped support for zope.configuration 3.7.x and older.

  • Unconfiguring an entire zcml file (include statement inside an unconfigure block) now works.

1.0.1 (2008-08-07)

  • Added a meta.zcml file so that the <unconfigure> directive can actually be registered from ZCML.

1.0 (2008-08-07)

First public release.

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.unconfigure-2.0.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

z3c.unconfigure-2.0-py3-none-any.whl (14.4 kB view details)

Uploaded Python 3

File details

Details for the file z3c.unconfigure-2.0.tar.gz.

File metadata

  • Download URL: z3c.unconfigure-2.0.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for z3c.unconfigure-2.0.tar.gz
Algorithm Hash digest
SHA256 256f5ae5a5b392c103f750fa4ea7e5c884a0b4a788c5d07e63601180d5be5a43
MD5 ca7c6385a3d15a7f2592620c8bc2f703
BLAKE2b-256 01a09e4a4af3ac2b94cc91a316bc1788cc2884dceabf357b1eb607c25537e9a4

See more details on using hashes here.

File details

Details for the file z3c.unconfigure-2.0-py3-none-any.whl.

File metadata

  • Download URL: z3c.unconfigure-2.0-py3-none-any.whl
  • Upload date:
  • Size: 14.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for z3c.unconfigure-2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 df82bb41b1ad13652094c04e59d53765f1b62c1453d482e3bc1ba9d818d989a9
MD5 35d7ab7b98a219c7db3c0b369e495898
BLAKE2b-256 d496b7a66013290ef3a5a666cad00a3cc85f60999d78c69b872598bc0a0d4b2b

See more details on using hashes here.

Supported by

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