[XML-SIG] Deep copy of an element from one document to another

Fred L. Drake, Jr. fdrake@acm.org
Wed, 19 Jun 2002 23:05:58 -0400

Uche Ogbuji writes:
 > Hmm.  Color me slow  :-)

No, that I won't!

 > I see nothing in Lib/email/Iterators.py itself.  And just in case, I
 > tried loading it with python 1.5 and got the expected blow-up.
 > So I assume you mean something more devious than code.
 > Barry got his utility functions packaged with Python so that he could
 > just ship portable code, which would try to import these souped-up
 > functions, and fall back to pre-iterator forms if not available?
 > If so, Barry gets my Daily Machination Award  ;-)

Hehe, yeah, that's all there is to it.

email._compat22 uses Python 2.2.x-only syntax; if importing that
fails, it falls back to the Python 2.1.x-compatible version in

He doesn't support Python 1.5.2 in the email package, but doing so if
similar to this; just write a group of modules that each require some
feature specific to the oldest version of Python they support, and use
a "master" module (email.Iterators in this example) that imports each
and catches the exception from each that indicates the running Python
is too old to support the implementation.  For the oldest supported
version, just don't catch any exceptions.

The magic is all in using the right checks and exceptions types.
Others call it the brute force approach.  ;-)


Fred L. Drake, Jr.  <fdrake at acm.org>
PythonLabs at Zope Corporation