本文整理汇总了Python中sagenb.notebook.misc.encode_response函数的典型用法代码示例。如果您正苦于以下问题:Python encode_response函数的具体用法?Python encode_response怎么用?Python encode_response使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了encode_response函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: worksheet_cell_list
def worksheet_cell_list(worksheet):
"""
Return a list of cells in JSON format.
"""
r = {}
r["state_number"] = worksheet.state_number()
r["cell_list"] = [c.basic() for c in worksheet.cell_list()]
return encode_response(r)
开发者ID:lukas-lansky,项目名称:sagenb,代码行数:8,代码来源:worksheet.py
示例2: worksheet_delete_cell_output
def worksheet_delete_cell_output(worksheet):
"""Delete's a cell's output."""
r = {}
r["id"] = id = get_cell_id()
worksheet.get_cell_with_id(id).delete_output()
r["command"] = "delete_output"
return encode_response(r)
开发者ID:lukas-lansky,项目名称:sagenb,代码行数:8,代码来源:worksheet.py
示例3: worksheet_delete_cell_output
def worksheet_delete_cell_output(worksheet):
"""Delete's a cell's output."""
r = {}
r['id'] = id = get_cell_id()
worksheet.get_cell_with_id(id).delete_output()
r['command'] = 'delete_output'
from sagenb.notebook.misc import encode_response
return encode_response(r)
开发者ID:philbrks,项目名称:sagenb,代码行数:9,代码来源:worksheet.py
示例4: worksheet_introspect
def worksheet_introspect(worksheet):
"""
Cell introspection. This is called when the user presses the tab
key in the browser in order to introspect.
"""
r = {}
r['id'] = id = get_cell_id()
if worksheet.tags().get('_pub_', [False])[0]: #tags set in pub_worksheet
r['command'] = 'error'
r['message'] = 'Cannot evaluate public cell introspection.'
return encode_response(r)
before_cursor = request.values.get('before_cursor', '')
after_cursor = request.values.get('after_cursor', '')
cell = worksheet.get_cell_with_id(id)
cell.evaluate(introspect=[before_cursor, after_cursor])
r['command'] = 'introspect'
return encode_response(r)
开发者ID:SnarkBoojum,项目名称:sagenb,代码行数:20,代码来源:worksheet.py
示例5: suspend_user
def suspend_user():
user = request.values['username']
try:
U = g.notebook.user_manager().user(user)
U.set_suspension()
except KeyError:
pass
return encode_response({
'message': _('User <strong>%(username)s</strong> has been suspended/unsuspended.', username=user)
})
开发者ID:Darot,项目名称:sagenb,代码行数:11,代码来源:admin.py
示例6: worksheet_introspect
def worksheet_introspect(worksheet):
"""
Cell introspection. This is called when the user presses the tab
key in the browser in order to introspect.
"""
r = {}
r["id"] = id = get_cell_id()
if worksheet.tags().get("_pub_", [False])[0]: # tags set in pub_worksheet
r["command"] = "error"
r["message"] = "Cannot evaluate public cell introspection."
return encode_response(r)
before_cursor = request.values.get("before_cursor", "")
after_cursor = request.values.get("after_cursor", "")
cell = worksheet.get_cell_with_id(id)
cell.evaluate(introspect=[before_cursor, after_cursor])
r["command"] = "introspect"
return encode_response(r)
开发者ID:lukas-lansky,项目名称:sagenb,代码行数:20,代码来源:worksheet.py
示例7: worksheet_cell_list
def worksheet_cell_list(worksheet):
"""
Return the state number and the HTML for the main body of the
worksheet, which consists of a list of cells.
"""
r = {}
r['state_number'] = worksheet.state_number()
# TODO: Send and actually use the body's HTML.
r['html_cell_list'] = ''
#r['html_cell_list'] = W.html_cell_list()
return encode_response(r)
开发者ID:SnarkBoojum,项目名称:sagenb,代码行数:12,代码来源:worksheet.py
示例8: worksheet_new_cell_after
def worksheet_new_cell_after(worksheet):
"""Add a new cell after a given cell."""
r = {}
r['id'] = id = get_cell_id()
input = unicode_str(request.values.get('input', ''))
cell = worksheet.new_cell_after(id, input=input)
worksheet.increase_state_number()
r['new_id'] = cell.id()
r['new_html'] = cell.html(div_wrap=True)
return encode_response(r)
开发者ID:SnarkBoojum,项目名称:sagenb,代码行数:12,代码来源:worksheet.py
示例9: add_user
def add_user():
from sagenb.notebook.misc import is_valid_username
username = request.values['username']
password = random_password()
if not is_valid_username(username):
return encode_response({
'error': _('<strong>Invalid username!</strong>')
})
if username in g.notebook.user_manager().usernames():
return encode_response({
'error': _('The username <strong>%(username)s</strong> is already taken!', username=username)
})
g.notebook.user_manager().add_user(username, password, '', force=True)
return encode_response({
'message': _('The temporary password for the new user <strong>%(username)s</strong> is <strong>%(password)s</strong>',
username=username, password=password)
})
开发者ID:Darot,项目名称:sagenb,代码行数:21,代码来源:admin.py
示例10: worksheet_new_cell_before
def worksheet_new_cell_before(self, worksheet):
"""Add a new cell before a given cell."""
r = {}
r['id'] = id = self.get_cell_id()
input = unicode_str(self.request_values.get('input', ''))
cell = worksheet.new_cell_before(id, input=input)
worksheet.increase_state_number()
r['new_id'] = cell.id()
#r['new_html'] = cell.html(div_wrap=False)
return encode_response(r)
开发者ID:rljacobson,项目名称:Guru-NB,代码行数:12,代码来源:WorksheetController.py
示例11: worksheet_new_cell_before
def worksheet_new_cell_before(worksheet):
"""Add a new cell before a given cell."""
r = {}
r["id"] = id = get_cell_id()
input = unicode_str(request.values.get("input", ""))
cell = worksheet.new_cell_before(id, input=input)
worksheet.increase_state_number()
r["new_id"] = cell.id()
# r['new_html'] = cell.html(div_wrap=False)
return encode_response(r)
开发者ID:lukas-lansky,项目名称:sagenb,代码行数:12,代码来源:worksheet.py
示例12: worksheet_new_cell_before
def worksheet_new_cell_before(worksheet):
"""Add a new cell before a given cell."""
r = {}
r['id'] = id = get_cell_id()
input = unicode_str(request.values.get('input', ''))
cell = worksheet.new_cell_before(id, input=input)
worksheet.increase_state_number()
r['new_id'] = cell.id()
r['new_html'] = cell.html(div_wrap=False)
from sagenb.notebook.misc import encode_response
return encode_response(r)
开发者ID:philbrks,项目名称:sagenb,代码行数:13,代码来源:worksheet.py
示例13: reset_user_password
def reset_user_password():
user = request.values['username']
password = random_password()
try:
# U = g.notebook.user_manager().user(user)
g.notebook.user_manager().set_password(user, password)
except KeyError:
pass
return encode_response({
'message': _('The temporary password for the new user <strong>%(username)s</strong> is <strong>%(password)s</strong>',
username=user, password=password)
})
开发者ID:Darot,项目名称:sagenb,代码行数:13,代码来源:admin.py
示例14: worksheet_list
def worksheet_list():
"""
Returns a worksheet listing.
INPUT:
- ``args`` - ctx.args where ctx is the dict passed
into a resource's render method
- ``pub`` - boolean, True if this is a listing of
public worksheets
- ``username`` - the user whose worksheets we are
listing
OUTPUT:
a string
"""
from sagenb.notebook.notebook import sort_worksheet_list
from sagenb.misc.misc import unicode_str, SAGE_VERSION
from sagenb.notebook.misc import encode_response
r = {}
pub = 'pub' in request.args
readonly = g.notebook.readonly_user(g.username)
typ = request.args['type'] if 'type' in request.args else 'active'
search = unicode_str(request.args['search']) if 'search' in request.args else None
sort = request.args['sort'] if 'sort' in request.args else 'last_edited'
reverse = (request.args['reverse'] == 'True') if 'reverse' in request.args else False
try:
if not pub:
r['worksheets'] = [x.basic() for x in g.notebook.worksheet_list_for_user(g.username, typ=typ, sort=sort, search=search, reverse=reverse)]
else:
r['worksheets'] = [x.basic() for x in g.notebook.worksheet_list_for_public(g.username, sort=sort, search=search, reverse=reverse)]
except ValueError as E:
# for example, the sort key was not valid
print "Error displaying worksheet listing: ", E
return current_app.message(_("Error displaying worksheet listing."))
#if pub and (not g.username or g.username == tuple([])):
# r['username'] = 'pub'
r['accounts'] = g.notebook.user_manager().get_accounts()
r['sage_version'] = SAGE_VERSION
# r['pub'] = pub
return encode_response(r)
开发者ID:rljacobson,项目名称:Guru-NB,代码行数:51,代码来源:worksheet_listing.py
示例15: worksheet_new_text_cell_after
def worksheet_new_text_cell_after(worksheet):
"""Add a new text cell after a given cell."""
r = {}
r['id'] = id = get_cell_id()
input = unicode_str(request.values.get('input', ''))
cell = worksheet.new_text_cell_after(id, input=input)
worksheet.increase_state_number()
r['new_id'] = cell.id()
r['new_html'] = cell.html(editing=True)
# XXX: Does editing correspond to TinyMCE? If so, we should try
# to centralize that code.
return encode_response(r)
开发者ID:SnarkBoojum,项目名称:sagenb,代码行数:14,代码来源:worksheet.py
示例16: worksheet_properties
def worksheet_properties(self, worksheet):
"""
Send worksheet properties as a JSON object
"""
r = worksheet.basic()
if worksheet.has_published_version():
hostname = request.headers.get('host', self.notebook.interface + ':' + str(self.notebook.port))
r['published_url'] = 'http%s://%s/home/%s' % ('' if not self.notebook.secure else 's',
hostname,
worksheet.published_version().filename())
return encode_response(r)
开发者ID:rljacobson,项目名称:Guru-NB,代码行数:15,代码来源:WorksheetController.py
示例17: worksheet_cell_update
def worksheet_cell_update(worksheet):
import time
from sagenb.notebook.misc import encode_response
r = {}
r['id'] = id = get_cell_id()
# update the computation one "step".
worksheet.check_comp()
# now get latest status on our cell
r['status'], cell = worksheet.check_cell(id)
if r['status'] == 'd':
r['new_input'] = cell.changed_input_text()
r['output_html'] = cell.output_html()
# Update the log.
t = time.strftime('%Y-%m-%d at %H:%M',
time.localtime(time.time()))
H = "Worksheet '%s' (%s)\n" % (worksheet.name(), t)
H += cell.edit_text(ncols=g.notebook.HISTORY_NCOLS, prompts=False,
max_out=g.notebook.HISTORY_MAX_OUTPUT)
g.notebook.add_to_user_history(H, g.username)
else:
r['new_input'] = ''
r['output_html'] = ''
if cell.interrupted():
r['interrupted'] = 'true'
else:
r['interrupted'] = 'false'
if 'Unhandled SIGSEGV' in cell.output_text(raw=True).split('\n'):
r['interrupted'] = 'restart'
print 'Segmentation fault detected in output!'
r['output'] = cell.output_text(html=True) + ' '
r['output_wrapped'] = cell.output_text(g.notebook.conf()['word_wrap_cols'],
html=True) + ' '
r['introspect_html'] = cell.introspect_html()
# Compute 'em, if we got 'em.
worksheet.start_next_comp()
return encode_response(r)
开发者ID:philbrks,项目名称:sagenb,代码行数:47,代码来源:worksheet.py
示例18: worksheet_delete_cell
def worksheet_delete_cell(worksheet):
"""
Deletes a worksheet cell, unless there's only one compute cell
left. This allows functions which evaluate relative to existing
cells, e.g., inserting a new cell, to continue to work.
"""
r = {}
r['id'] = id = get_cell_id()
if len(worksheet.compute_cell_id_list()) <= 1:
r['command'] = 'ignore'
else:
prev_id = worksheet.delete_cell_with_id(id)
r['command'] = 'delete'
r['prev_id'] = worksheet.delete_cell_with_id(id)
r['cell_id_list'] = worksheet.cell_id_list()
return encode_response(r)
开发者ID:SnarkBoojum,项目名称:sagenb,代码行数:17,代码来源:worksheet.py
示例19: worksheet_properties
def worksheet_properties(worksheet):
"""
Send worksheet properties as a JSON object
"""
from sagenb.notebook.misc import encode_response
r = worksheet.basic()
if worksheet.has_published_version():
hostname = request.headers.get("host", g.notebook.interface + ":" + str(g.notebook.port))
r["published_url"] = "http%s://%s/home/%s" % (
"" if not g.notebook.secure else "s",
hostname,
worksheet.published_version().filename(),
)
return encode_response(r)
开发者ID:lukas-lansky,项目名称:sagenb,代码行数:18,代码来源:worksheet.py
示例20: worksheet_cell_update
def worksheet_cell_update(worksheet):
import time
r = {}
r["id"] = id = get_cell_id()
# update the computation one "step".
worksheet.check_comp()
# now get latest status on our cell
r["status"], cell = worksheet.check_cell(id)
if r["status"] == "d":
r["new_input"] = cell.changed_input_text()
r["output_html"] = cell.output_html()
# Update the log.
t = time.strftime("%Y-%m-%d at %H:%M", time.localtime(time.time()))
H = "Worksheet '%s' (%s)\n" % (worksheet.name(), t)
H += cell.edit_text(ncols=g.notebook.HISTORY_NCOLS, prompts=False, max_out=g.notebook.HISTORY_MAX_OUTPUT)
g.notebook.add_to_user_history(H, g.username)
else:
r["new_input"] = ""
r["output_html"] = ""
r["interrupted"] = cell.interrupted()
if "Unhandled SIGSEGV" in cell.output_text(raw=True).split("\n"):
r["interrupted"] = "restart"
print "Segmentation fault detected in output!"
r["output"] = cell.output_text(html=True)
r["output_wrapped"] = cell.output_text(g.notebook.conf()["word_wrap_cols"])
r["introspect_output"] = cell.introspect_output()
# Compute 'em, if we got 'em.
worksheet.start_next_comp()
return encode_response(r)
开发者ID:lukas-lansky,项目名称:sagenb,代码行数:37,代码来源:worksheet.py
注:本文中的sagenb.notebook.misc.encode_response函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论