Пример #1
0
    def LOAD_DEREF(f, varindex, *ignored):
        # nested scopes: access a variable through its cell object
        cell = f.cells[varindex]
        try:
            w_value = cell.get()
            if not namecheck_load(f, w_value):
                if print_access_exceptions:
                    print >> stderr, "\033[1;31mAccess Error:\033[1;m " + str(
                        sys._getframe().f_code.co_name
                    ) + ": cellindex=" + str(varindex)

                if throw_access_exceptions:
                    # SRW TODO: raise
                    pass
                else:
                    raise ValueError()
        except ValueError:
            varname = f.getfreevarname(varindex)
            if f.iscellvar(varindex):
                message = "local variable '%s' referenced before assignment" % varname
                w_exc_type = f.space.w_UnboundLocalError
            else:
                message = "free variable '%s' referenced before assignment" " in enclosing scope" % varname
                w_exc_type = f.space.w_NameError
            raise OperationError(w_exc_type, f.space.wrap(message))
        else:
            f.pushvalue(w_value)
Пример #2
0
    def LOAD_CLOSURE(f, varindex, *ignored):
        # nested scopes: access the cell object
        cell = f.cells[varindex]
        w_value = f.space.wrap(cell)
        if namecheck_load(f, w_value):
            f.pushvalue(w_value)
        else:
            if print_access_exceptions:
                print >> stderr, "\033[1;31mAccess Error:\033[1;m " + str(
                    sys._getframe().f_code.co_name
                ) + ": cellindex=" + str(varindex)

            if throw_access_exceptions:
                # SRW TODO: raise
                pass
            else:
                f.pushvalue(w_None)  # TODO: BETTER THAN THIS