[Zope-CMF] CMFDefault.utils is not monkey-patchable

Paul Winkler pw_lists@slinkp.com
Tue, 12 Nov 2002 12:57:21 -0800


<rant>
I like doing "monkey patches" to change default behavior
of downloaded Zope products without having to build
wrapper products or patch the actual source.

I just discovered something annoying when trying
to figure out why I was getting no results from
a seemingly trivial monkeypatch to turn off
the bit of CMFDefault.utils that filters out
javascript: 

the function in question is called scrubHTML.
let's go looking for it in the ZEO debugger:

>>> from Products.CMFDefault.utils import scrubHTML
>>> scrubHTML.__name__
'scrubHTML'

Here's the weird bit:

>>> import Products.CMFDefault.utils
>>> hasattr(Products.CMFDefault.utils, 'scrubHTML')
0
>>> Products.CMFDefault.utils.__name__
'Products.CMFCore.utils'

The reason for this is that in CMFDefault/__init__.py, 
we find this:
from Products.CMFCore import utils

This is bad, because CMFCore/utils.py now "masks"
CMFDefault/utils.py such that you can ONLY get
at attributes of the latter by importing them
directly into the current namespace, as in:
from Products.CMFDefault.utils import foo

IMHO this is Bad and Wrong. "from foo import bar"
is generally frowned upon due to namespace pollution
and masking issues, and here we have one usage of this
idiom enforcing more usage of this idiom.

Well, off I go to change every instance of
from Products.CMFDefault.utils import scrubHTML
in my skins...
</rant>

-- 

Paul Winkler
http://www.slinkp.com
"Welcome to Muppet Labs, where the future is made - today!"