def bind(x, rec=None): """Enable compilation of the given function, method, or class object. If C is a class (or anything with a '__dict__' attribute), bind(C) will rebind all functions and methods found in C.__dict__ (which means, for classes, all methods defined in the class but not in its parents). The optional second argument specifies the number of recursive compilation levels: all functions called by func are compiled up to the given depth of indirection.""" if isinstance(x, types.MethodType): x = x.im_func if isinstance(x, types.FunctionType): if rec is None: x.func_code = _psyco.proxycode(x) else: x.func_code = _psyco.proxycode(x, rec) return if hasattr(x, "__dict__"): funcs = [o for o in x.__dict__.values() if isinstance(o, types.MethodType) or isinstance(o, types.FunctionType)] if not funcs: raise error, ("nothing bindable found in %s object" % type(x).__name__) for o in funcs: bind(o, rec) return raise TypeError, "cannot bind %s objects" % type(x).__name__
def bind(x, rec=None): """Enable compilation of the given function, method, or class object. If C is a class (or anything with a '__dict__' attribute), bind(C) will rebind all functions and methods found in C.__dict__ (which means, for classes, all methods defined in the class but not in its parents). The optional second argument specifies the number of recursive compilation levels: all functions called by func are compiled up to the given depth of indirection.""" if isinstance(x, types.MethodType): x = x.im_func if isinstance(x, types.FunctionType): if rec is None: x.func_code = _psyco.proxycode(x) else: x.func_code = _psyco.proxycode(x, rec) return if hasattr(x, '__dict__'): funcs = [o for o in x.__dict__.values() if isinstance(o, types.MethodType) or isinstance(o, types.FunctionType)] if not funcs: raise error, ("nothing bindable found in %s object" % type(x).__name__) for o in funcs: bind(o, rec) return raise TypeError, "cannot bind %s objects" % type(x).__name__
def proxy(x, rec=None): """Return a Psyco-enabled copy of the function. The original function is still available for non-compiled calls. The optional second argument specifies the number of recursive compilation levels: all functions called by func are compiled up to the given depth of indirection.""" if isinstance(x, types.FunctionType): if rec is None: code = _psyco.proxycode(x) else: code = _psyco.proxycode(x, rec) return new.function(code, x.func_globals, x.func_name) if isinstance(x, types.MethodType): p = proxy(x.im_func, rec) return new.instancemethod(p, x.im_self, x.im_class) raise TypeError, "cannot proxy %s objects" % type(x).__name__
def trytobind(co, globals, log=1): try: f, clsname = function_cache[co] except KeyError: buildfncache(globals, function_cache) try: f, clsname = function_cache[co] except KeyError: if logger: logger.write("warning: cannot find function %s in %s" % (co.co_name, globals.get("__name__", "?")), 3) return # give up if logger and log: modulename = globals.get("__name__", "?") if clsname: modulename += "." + clsname logger.write("bind function: %s.%s" % (modulename, co.co_name), 1) f.func_code = _psyco.proxycode(f)
def trytobind(co, globals, log=1): try: f, clsname = function_cache[co] except KeyError: buildfncache(globals, function_cache) try: f, clsname = function_cache[co] except KeyError: if logger: logger.write( 'warning: cannot find function %s in %s' % (co.co_name, globals.get('__name__', '?')), 3) return # give up if logger and log: modulename = globals.get('__name__', '?') if clsname: modulename += '.' + clsname logger.write('bind function: %s.%s' % (modulename, co.co_name), 1) f.func_code = _psyco.proxycode(f)