1# 2# Both libxml2mod and libxsltmod have a dependancy on libxml2.so 3# and they should share the same module, try to convince the python 4# loader to work in that mode if feasible 5# 6import sys 7if not hasattr(sys,'getdlopenflags'): 8 import libxml2mod 9 import libxsltmod 10 import libxml2 11else: 12 try: 13 from dl import RTLD_GLOBAL, RTLD_NOW 14 except ImportError: 15 RTLD_GLOBAL = -1 16 RTLD_NOW = -1 17 try: 18 import os 19 osname = os.uname()[0] 20 if osname == 'Linux' or osname == 'SunOS': 21 RTLD_GLOBAL = 0x00100 22 RTLD_NOW = 0x00002 23 elif osname == 'Darwin': 24 RTLD_GLOBAL = 0x8 25 RTLD_NOW = 0x2 26 # 27 # is there a better method ? 28 # 29# else: 30# print "libxslt could not guess RTLD_GLOBAL and RTLD_NOW " + \ 31# "on this platform: %s" % (osname) 32 except: 33 pass 34# print "libxslt could not guess RTLD_GLOBAL and RTLD_NOW " + \ 35# "on this platform: %s" % (osname) 36 except: 37 RTLD_GLOBAL = -1 38 RTLD_NOW = -1 39 40 if RTLD_GLOBAL != -1 and RTLD_NOW != -1: 41 try: 42 flags = sys.getdlopenflags() 43 sys.setdlopenflags(RTLD_GLOBAL | RTLD_NOW) 44 try: 45 import libxml2mod 46 import libxsltmod 47 import libxml2 48 finally: 49 sys.setdlopenflags(flags) 50 except: 51 import libxml2mod 52 import libxsltmod 53 import libxml2 54 else: 55 import libxml2mod 56 import libxsltmod 57 import libxml2 58 59 60class transformCtxtBase: 61 def __init__(self, _obj=None): 62 if _obj != None: 63 self._o = _obj; 64 return 65 self._o = None 66 def __hash__(self): 67 v = libxsltmod.xsltGetTransformContextHashCode(self._o) 68 return v 69 def __eq__(self, other): 70 if other == None: 71 return 0 72 v = libxsltmod.xsltCompareTransformContextsEqual(self._o, other._o) 73 return v 74 75class stylesheetBase: 76 def __init__(self, _obj=None): 77 if _obj != None: 78 self._o = _obj; 79 return 80 self._o = None 81 def __hash__(self): 82 v = libxsltmod.xsltGetStylesheetHashCode(self._o) 83 return v 84 def __eq__(self, other): 85 if other == None: 86 return 0 87 v = libxsltmod.xsltCompareStylesheetsEqual(self._o, other._o) 88 return v 89 90class extensionModule: 91 def _styleInit(self, style, URI): 92 return self.styleInit(stylesheet(_obj=style), URI) 93 94 def _styleShutdown(self, style, URI, data): 95 return self.styleShutdown(stylesheet(_obj=style), URI, data) 96 97 def _ctxtInit(self, ctxt, URI): 98 return self.ctxtInit(transformCtxt(_obj=ctxt), URI) 99 100 def _ctxtShutdown(self, ctxt, URI, data): 101 return self.ctxtShutdown(transformCtxt(_obj=ctxt), URI, data) 102 103 def styleInit(self, style, URI): 104 """Callback function when used in a newly compiled stylesheet, 105 the return value is passed in subsequent calls""" 106 pass 107 108 def styleShutdown(self, style, URI, data): 109 """Callback function when a stylesheet using it is destroyed""" 110 pass 111 112 def ctxtInit(self, ctxt, URI): 113 """Callback function when used in a new transformation process, 114 the return value is passed in subsequent calls""" 115 pass 116 117 def ctxtShutdown(self, ctxt, URI, data): 118 """Callback function when a transformation using it finishes""" 119 pass 120 121def cleanup(): 122 """Cleanup all libxslt and libxml2 memory allocated""" 123 libxsltmod.xsltPythonCleanup() 124 libxml2.cleanupParser() 125 126# 127# Everything below this point is automatically generated 128# 129 130