Beispiel #1
0
def changetoken(space,w_obj,w_token):
    # ASSUMPTION: if caller can pass a reference to w_token, it has permission to use it
    # check that w_obj is NOT a nametoken object (don't allow a token to change it's self-ownership)
    if isinstance(w_obj, W_NametokenObject):
        return space.w_False
    # check that w_token is a nametoken object
    if not isinstance(w_token, W_NametokenObject):
        return space.w_False
    # check that the caller has permission to change
    if not _currentframe_has_access(space, w_obj):
        return space.w_False
    _changetoken(space, w_obj, w_token)
    return space.w_True
Beispiel #2
0
    def fget_func_code(space, self):
        from pypy.module.__builtin__.namespace_helpers import SLOTNAME_ALLTOKENS, SLOTNAME_NAMETOKEN, throw_access_exceptions, print_access_exceptions, _currentframe_has_access
        from sys import stderr
        
        if _currentframe_has_access(space, self.creator_nametoken):
            return space.wrap(self.code)
        else:
            if print_access_exceptions:
                print >> stderr, "\033[1;31mAccess Error:\033[1;m " + self.name + ".func_code"

            if throw_access_exceptions:
                #SRW TODO: raise
                pass
            else:
                return space.w_None
Beispiel #3
0
    def fget_func_closure(space, self):
        from pypy.module.__builtin__.namespace_helpers import SLOTNAME_ALLTOKENS, SLOTNAME_NAMETOKEN, throw_access_exceptions, print_access_exceptions, _currentframe_has_access
        from sys import stderr

        if self.closure is not None:
            if _currentframe_has_access(space, self.creator_nametoken):
                w_res = space.newtuple( [ space.wrap(i) for i in self.closure ] )
            else:
                if print_access_exceptions:
                    print >> stderr, "\033[1;31mAccess Error:\033[1;m " + self.name + ".func_closure"

                if throw_access_exceptions:
                    #SRW TODO: raise
                    pass
                else:
                    w_res = space.w_None
        else:
            w_res = space.w_None
        return w_res
Beispiel #4
0
        return space.getitem(w_obj, w_key)
    except OperationError, e:
        if not e.match(space, space.w_KeyError):
            raise
        return None


def check_sys_modules(space, w_modulename):
    w_modules = space.sys.get('modules')
    try:
        w_mod = space.getitem(w_modules, w_modulename) 
    except OperationError, e:
        if not e.match(space, space.w_KeyError):
            raise
    else:
        if _currentframe_has_access(space, w_mod):
            return w_mod
        else:
            if print_access_exceptions:
                print >> stderr, "\033[1;31mAccess Error:\033[1;m " + str(sys._getframe().f_code.co_name) + ": modulename=" + space.str_w(w_modulename)
    return None

def importhook(space, modulename, w_globals=None,
               w_locals=None, w_fromlist=None, level=-1):
    # w_locals is not currently used by this function, so it has been 
    #   expropriated by SRW for 6.893
    # w_locals may now contain {"__nametoken__": tokenobj} which we will want to
    #   load into the module's __dict__ as well as the globals under which these
    #   objects are compiled/created
    timername = "importhook " + modulename
    space.timer.start(timername)