[XML-SIG] Availability of libxml2 and libxslt Python bindings

Fred L. Drake, Jr. fdrake@acm.org
Thu, 21 Feb 2002 14:19:22 -0500


Hannu Krosing writes:
 > I looked them up in /usr/include/bits/dlfcn.h and wirth this it works
 > 
 > >>> sys.setdlopenflags(0x00002|0x00100)   
 > >>> import libxslt

That's not just annoying, that's down right ugly!  I don't know how
portable the constants are, either.  If this ends up being the only
way to deal with this problem, I'd hope the libxml2/libxslt modules
end up "wrapped" by modules written in Python that do something like
this:

------------------------------------------------
import sys

try:
    from dl import RTLD_GLOBAL, RTLD_NOW
except ImportError:
    # hopefully something better is available...
    RTLD_GLOBAL = 0x00100
    RTLD_NOW = 0x00002

flags = sys.getdlopenflags()
sys.setdlopenflags(RTLD_GLOBAL | RTLD_NOW)
try:
    import libxml2
    import libxslt
finally:
    sys.setdlopenflags(flags)
------------------------------------------------

 > So will this be the standard way to work with python 2.2 and libxslt ;)

Aaarrgghhh!

Actually, I think there is another option, but it really wonderful
either.  It might be better than this.  Both C extension modules can
be implemented by a single .so this way:

1. Implement two internal functions that do what the current
   init<module> functions do; let's call these _init_1 and _init_2.

2. Write *two* init<module> functions (initA and initB), each of which
   calls both _init_1 and _init_2.

3. Install the .so as A.so *and* B.so, so it doesn't matter which gets
   imported first.  When imported, both modules are initialized and
   inserted in sys.modules, so subsequent imports will pick up the
   cached module.

Somewhat painful, but it should avoid these library dependence
problems, at least in this case.


  -Fred

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