Esempio n. 1
0
 def _load_lazily(self, space, name):
     w_name = space.new_interned_str(name)
     try:
         loader = self.loaders[name]
     except KeyError:
         return None
     else:
         w_value = loader(space)
         # the idea of the following code is that all functions that are
         # directly in a mixed-module are "builtin", e.g. they get a
         # special type without a __get__
         # note that this is not just all functions that contain a
         # builtin code object, as e.g. methods of builtin types have to
         # be normal Functions to get the correct binding behaviour
         func = w_value
         if (isinstance(func, Function) and
             type(func) is not BuiltinFunction):
             try:
                 bltin = func._builtinversion_
             except AttributeError:
                 bltin = BuiltinFunction(func)
                 bltin.w_module = self.w_name
                 func._builtinversion_ = bltin
                 bltin.name = name
             w_value = space.wrap(bltin)
         space.setitem(self.w_dict, w_name, w_value)
         return w_value
Esempio n. 2
0
 def _load_lazily(self, space, name):
     w_name = space.new_interned_str(name)
     try: 
         loader = self.loaders[name]
     except KeyError: 
         return None 
     else: 
         w_value = loader(space) 
         func = space.interpclass_w(w_value)
         # the idea of the following code is that all functions that are
         # directly in a mixed-module are "builtin", e.g. they get a
         # special type without a __get__
         # note that this is not just all functions that contain a
         # builtin code object, as e.g. methods of builtin types have to
         # be normal Functions to get the correct binding behaviour
         if (isinstance(func, Function) and
             type(func) is not BuiltinFunction):
             try:
                 bltin = func._builtinversion_
             except AttributeError:
                 bltin = BuiltinFunction(func)
                 bltin.w_module = self.w_name
                 func._builtinversion_ = bltin
                 bltin.name = name
             w_value = space.wrap(bltin)
         space.setitem(self.w_dict, w_name, w_value) 
         return w_value
Esempio n. 3
0
 def getdictvalue(self, space, w_name):
     w_value = space.finditem(self.w_dict, w_name)
     if self.lazy and w_value is None:
         name = space.str_w(w_name)
         w_name = space.new_interned_w_str(w_name)
         try:
             loader = self.loaders[name]
         except KeyError:
             return None
         else:
             #print "trying to load", name
             w_value = loader(space)
             #print "loaded", w_value
             # obscure
             func = space.interpclass_w(w_value)
             if type(func) is Function:
                 try:
                     bltin = func._builtinversion_
                 except AttributeError:
                     bltin = BuiltinFunction(func)
                     bltin.w_module = self.w_name
                     func._builtinversion_ = bltin
                     bltin.name = name
                 w_value = space.wrap(bltin)
             space.setitem(self.w_dict, w_name, w_value)
     return w_value
Esempio n. 4
0
 def getdictvalue(self, space, w_name):
     w_value = space.finditem(self.w_dict, w_name)
     if self.lazy and w_value is None:
         name = space.str_w(w_name)
         w_name = space.new_interned_w_str(w_name)
         try:
             loader = self.loaders[name]
         except KeyError:
             return None
         else:
             # print "trying to load", name
             w_value = loader(space)
             # print "loaded", w_value
             # obscure
             func = space.interpclass_w(w_value)
             if type(func) is Function:
                 try:
                     bltin = func._builtinversion_
                 except AttributeError:
                     bltin = BuiltinFunction(func)
                     bltin.w_module = self.w_name
                     func._builtinversion_ = bltin
                     bltin.name = name
                 w_value = space.wrap(bltin)
             space.setitem(self.w_dict, w_name, w_value)
     return w_value
Esempio n. 5
0
def builtinify(space, w_func):
    """To implement at app-level modules that are, in CPython,
    implemented in C: this decorator protects a function from being ever
    bound like a method.  Useful because some tests do things like put
    a "built-in" function on a class and access it via the instance.
    """
    from pypy.interpreter.function import Function, BuiltinFunction
    func = space.interp_w(Function, w_func)
    bltn = BuiltinFunction(func)
    return bltn
Esempio n. 6
0
def builtinify(space, w_func):
    from pypy.interpreter.function import Function, BuiltinFunction
    func = space.interp_w(Function, w_func)
    bltn = BuiltinFunction(func)
    return space.wrap(bltn)
Esempio n. 7
0
def fake_builtin_function(space, fn):
    func = fake_builtin_callable(space, fn)
    if fn.__self__ is None:
        func = BuiltinFunction(func)
    return func