예제 #1
0
    def wrapper(username, id, **kwds):
        worksheet_filename = username + "/" + id
        try:
            worksheet = kwds["worksheet"] = g.notebook.get_worksheet_with_filename(worksheet_filename)
        except KeyError:
            return _("You do not have permission to access this worksheet")

        with worksheet_locks[worksheet]:
            owner = worksheet.owner()

            if owner != "_sage_" and g.username != owner:
                if not worksheet.is_published():
                    if not g.username in worksheet.collaborators() and not g.notebook.user_manager().user_is_admin(
                        g.username
                    ):
                        return current_app.message(_("You do not have permission to access this worksheet"))

            if not worksheet.is_published():
                worksheet.set_active(g.username)

            # This was in twist.Worksheet.childFactory
            from base import notebook_updates

            notebook_updates()

            return f(username, id, **kwds)
예제 #2
0
    def wrapper(username, id, **kwds):
        worksheet_filename = username + "/" + id
        try:
            worksheet = kwds[
                'worksheet'] = g.notebook.get_worksheet_with_filename(
                    worksheet_filename)
        except KeyError:
            return current_app.message(
                _("You do not have permission to access this worksheet"))

        with worksheet_locks[worksheet]:
            owner = worksheet.owner()

            if owner != '_sage_' and g.username != owner:
                if not worksheet.is_published():
                    if (not g.username in worksheet.collaborators()
                            and not g.notebook.user_manager().user_is_admin(
                                g.username)):
                        return current_app.message(
                            _("You do not have permission to access this worksheet"
                              ))

            if not worksheet.is_published():
                worksheet.set_active(g.username)

            #This was in twist.Worksheet.childFactory
            from base import notebook_updates
            notebook_updates()

            return f(username, id, **kwds)
예제 #3
0
def worksheet_eval(worksheet):
    """
    Evaluate a worksheet cell.

    If the request is not authorized (the requester did not enter the
    correct password for the given worksheet), then the request to
    evaluate or introspect the cell is ignored.

    If the cell contains either 1 or 2 question marks at the end (not
    on a comment line), then this is interpreted as a request for
    either introspection to the documentation of the function, or the
    documentation of the function and the source code of the function
    respectively.
    """
    from sagenb.notebook.twist import encode_list
    from base import notebook_updates

    id = get_cell_id()
    input_text = unicode_str(request.values.get('input',
                                                '')).replace('\r\n',
                                                             '\n')  #DOS

    worksheet.increase_state_number()

    cell = worksheet.get_cell_with_id(id)
    cell.set_input_text(input_text)

    if request.values.get('save_only', '0') == '1':
        notebook_updates()
        return ''
    elif request.values.get('text_only', '0') == '1':
        notebook_updates()
        return encode_list([str(id), cell.html()])
    else:
        new_cell = int(request.values.get(
            'newcell', 0))  #wheter to insert a new cell or not

    cell.evaluate(username=g.username)

    if cell.is_last():
        new_cell = worksheet.append_new_cell()
        s = encode_list(
            [new_cell.id(), 'append_new_cell',
             new_cell.html(div_wrap=False)])
    elif new_cell:
        new_cell = worksheet.new_cell_after(id)
        s = encode_list([
            new_cell.id(), 'insert_cell',
            new_cell.html(div_wrap=False),
            str(id)
        ])
    else:
        s = encode_list([cell.next_id(), 'no_new_cell', str(id)])

    notebook_updates()
    return s
예제 #4
0
def worksheet_eval(worksheet):
    """
    Evaluate a worksheet cell.

    If the request is not authorized (the requester did not enter the
    correct password for the given worksheet), then the request to
    evaluate or introspect the cell is ignored.

    If the cell contains either 1 or 2 question marks at the end (not
    on a comment line), then this is interpreted as a request for
    either introspection to the documentation of the function, or the
    documentation of the function and the source code of the function
    respectively.
    """    
    from sagenb.notebook.twist import encode_list
    from base import notebook_updates
    
    id = get_cell_id()
    input_text = unicode_str(request.values.get('input', '')).replace('\r\n', '\n') #DOS

    worksheet.increase_state_number()

    cell = worksheet.get_cell_with_id(id)
    cell.set_input_text(input_text)

    if request.values.get('save_only', '0') == '1':
        notebook_updates()
        return ''
    elif request.values.get('text_only', '0') == '1':
        notebook_updates()
        return encode_list([str(id), cell.html()])
    else:
        new_cell = int(request.values.get('newcell', 0)) #wheter to insert a new cell or not

    cell.evaluate(username=g.username)

    if cell.is_last():
        new_cell = worksheet.append_new_cell()
        s = encode_list([new_cell.id(), 'append_new_cell', new_cell.html(div_wrap=False)])
    elif new_cell:
        new_cell = worksheet.new_cell_after(id)
        s = encode_list([new_cell.id(), 'insert_cell', new_cell.html(div_wrap=False), str(id)])
    else:
        s = encode_list([cell.next_id(), 'no_new_cell', str(id)])

    notebook_updates()
    return s
예제 #5
0
def worksheet_eval(worksheet):
    """
    Evaluate a worksheet cell.

    If the request is not authorized (the requester did not enter the
    correct password for the given worksheet), then the request to
    evaluate or introspect the cell is ignored.

    If the cell contains either 1 or 2 question marks at the end (not
    on a comment line), then this is interpreted as a request for
    either introspection to the documentation of the function, or the
    documentation of the function and the source code of the function
    respectively.
    """
    from base import notebook_updates

    r = {}

    r['id'] = id = get_cell_id()
    cell = worksheet.get_cell_with_id(id)
    public = worksheet.tags().get('_pub_', [False])[0] #this is set in pub_worksheet

    if public and not cell.is_interactive_cell():
        r['command'] = 'error'
        r['message'] = 'Cannot evaluate non-interactive public cell with ID %r.' % id
        return encode_response(r)

    worksheet.increase_state_number()

    if public:
        # Make public input cells read-only.
        input_text = cell.input_text()
    else:
        input_text = unicode_str(request.values.get('input', '')).replace('\r\n', '\n') #DOS

    # Handle an updated / recomputed interact.  TODO: JSON encode
    # the update data.
    if 'interact' in request.values:
        r['interact'] = 1
        input_text = INTERACT_UPDATE_PREFIX
        variable = request.values.get('variable', '')
        if variable!='':
            adapt_number = int(request.values.get('adapt_number', -1))
            value = request.values.get('value', '')
            input_text += "\n_interact_.update('%s', '%s', %s, _interact_.standard_b64decode('%s'), globals())" % (id, variable, adapt_number, value)

        if int(request.values.get('recompute', 0)):
            input_text += "\n_interact_.recompute('%s')" % id

    cell.set_input_text(input_text)

    if int(request.values.get('save_only', '0')):
        notebook_updates()
        return encode_response(r)
    elif int(request.values.get('text_only', '0')):
        notebook_updates()
        r['cell_html'] = cell.html()
        return encode_response(r)

    cell.evaluate(username=g.username)

    new_cell = int(request.values.get('newcell', 0)) #whether to insert a new cell or not
    if new_cell:
        new_cell = worksheet.new_cell_after(id)
        r['command'] = 'insert_cell'
        r['new_cell_id'] = new_cell.id()
        r['new_cell_html'] = new_cell.html(div_wrap=False)
    else:
        r['next_id'] = cell.next_compute_id()

    notebook_updates()

    return encode_response(r)
예제 #6
0
def worksheet_eval(worksheet):
    """
    Evaluate a worksheet cell.

    If the request is not authorized (the requester did not enter the
    correct password for the given worksheet), then the request to
    evaluate or introspect the cell is ignored.

    If the cell contains either 1 or 2 question marks at the end (not
    on a comment line), then this is interpreted as a request for
    either introspection to the documentation of the function, or the
    documentation of the function and the source code of the function
    respectively.
    """
    from base import notebook_updates

    r = {}

    r['id'] = id = get_cell_id()
    cell = worksheet.get_cell_with_id(id)
    public = worksheet.tags().get('_pub_',
                                  [False])[0]  #this is set in pub_worksheet

    if public and not cell.is_interactive_cell():
        r['command'] = 'error'
        r['message'] = 'Cannot evaluate non-interactive public cell with ID %r.' % id
        return encode_response(r)

    worksheet.increase_state_number()

    if public:
        # Make public input cells read-only.
        input_text = cell.input_text()
    else:
        input_text = unicode_str(request.values.get('input',
                                                    '')).replace('\r\n',
                                                                 '\n')  #DOS

    # Handle an updated / recomputed interact.  TODO: JSON encode
    # the update data.
    if 'interact' in request.values:
        r['interact'] = 1
        input_text = INTERACT_UPDATE_PREFIX
        variable = request.values.get('variable', '')
        if variable != '':
            adapt_number = int(request.values.get('adapt_number', -1))
            value = request.values.get('value', '')
            input_text += "\n_interact_.update('%s', '%s', %s, _interact_.standard_b64decode('%s'), globals())" % (
                id, variable, adapt_number, value)

        if int(request.values.get('recompute', 0)):
            input_text += "\n_interact_.recompute('%s')" % id

    cell.set_input_text(input_text)

    if int(request.values.get('save_only', '0')):
        notebook_updates()
        return encode_response(r)
    elif int(request.values.get('text_only', '0')):
        notebook_updates()
        r['cell_html'] = cell.html()
        return encode_response(r)

    cell.evaluate(username=g.username)

    new_cell = int(request.values.get('newcell',
                                      0))  #whether to insert a new cell or not
    if new_cell:
        new_cell = worksheet.new_cell_after(id)
        r['command'] = 'insert_cell'
        r['new_cell_id'] = new_cell.id()
        r['new_cell_html'] = new_cell.html(div_wrap=False)
    else:
        r['next_id'] = cell.next_compute_id()

    notebook_updates()

    return encode_response(r)