def insert_interpreter(page, elem, uid): """inserts an interpreter (and the js code to initialise an interpreter)""" vlam = elem.attrib["title"] interp_kind = select_type(vlam, config[page.username]["override_default_interpreter"], elem) # When a security mode is set to "display ...", we only parse the # page, but no Python execution from is allowed from that page. # If that is the case, we won't include javascript either, to make # thus making the source easier to read. show = True if not ("display" in config[page.username]["page_security_level"](page.url) or interp_kind == None): include_interpreter(interp_kind, page, uid) log_id = util.extract_log_id(vlam) if log_id: t = "interpreter" config[page.username]["logging_uids"][uid] = (log_id, t) else: log_id = False show = False # then we can go ahead and add html markup, extracting the Python # code to be executed in the process - we will not need this code; # this could change in a future version where we could add a button to # have the code automatically "injected" and executed by the # interpreter, thus saving some typing by the user. python_code = util.extract_code(elem) if util.is_interpreter_session(python_code): elem.attrib["title"] = "pycon" python_code = util.extract_code_from_interpreter(python_code) else: elem.attrib["title"] = "python" dummy, show_vlam = plugin["services"].style(page, elem, None, vlam) elem.attrib["title"] = vlam if log_id: config[page.username]["log"][log_id] = [tostring(elem)] util.wrap_in_div(elem, uid, vlam, "interpreter", show_vlam) if config[page.username]["popups"] and interp_kind is not None and not page.includes("interpreter_helper"): page.add_include("interpreter_helper") # insert popup helper img = Element( "img", src="/images/help.png", style="height:32px;", title="cluetip Hello %s! " % page.username + titles[interp_kind], rel=help_files[interp_kind], ) elem.append(img) plugin["services"].insert_cluetip(page, img, uid) plugin["services"].insert_io_subwidget(page, elem, uid, interp_kind=interp_kind, sample_code=python_code, show=show) plugin["services"].insert_tooltip(page, elem, uid) return
def insert_bare_editor(page, elem, uid): """inserts a 'bare' editor, python code, but no execution buttons. Common code to both insert_editor() and insert_alternate_python(). """ vlam = elem.attrib["title"] log_id = util.extract_log_id(vlam) if log_id: t = 'editor' config[page.username]['logging_uids'][uid] = (log_id, t) # When a security mode is set to "display ...", we only parse the # page, but no Python execution from is allowed from that page. # If that is the case, we won't include javascript either, # thus making the source easier to read. if 'display' not in config[page.username]['page_security_level'](page.url): if not page.includes("exec_included"): page.add_include("exec_included") page.add_js_code(exec_jscode) # then we can go ahead and add html markup, extracting the Python # code to be executed in the process python_code = util.extract_code(elem) if util.is_interpreter_session(python_code): elem.attrib['title'] = "pycon" python_code = util.extract_code_from_interpreter(python_code) else: elem.attrib['title'] = "python" dummy, show_vlam = plugin['services'].style(page, elem, None, vlam) elem.attrib['title'] = vlam if log_id: config[page.username]['log'][log_id] = [tostring(elem)] util.wrap_in_div(elem, uid, vlam, "editor", show_vlam) if config[page.username]['popups']: # insert popup helper img = Element("img", src="/images/help.png", style="height:32px;", title="cluetip Hello %s! " % page.username + "This is an Editor; click for more", rel="/docs/popups/editor.html") elem.append(img) plugin['services'].insert_cluetip(page, img, uid) if (("no_copy" in vlam) and not ("no_pre" in vlam)) or (not python_code): python_code = "\n" plugin['services'].insert_editor_subwidget(page, elem, uid, python_code) return vlam
def insert_bare_editor(page, elem, uid): """inserts a 'bare' editor, python code, but no execution buttons. Common code to both insert_editor() and insert_alternate_python(). """ vlam = elem.attrib["title"] log_id = util.extract_log_id(vlam) if log_id: t = 'editor' config[page.username]['logging_uids'][uid] = (log_id, t) # When a security mode is set to "display ...", we only parse the # page, but no Python execution from is allowed from that page. # If that is the case, we won't include javascript either, # thus making the source easier to read. if 'display' not in config[page.username]['page_security_level'](page.url): if not page.includes("exec_included"): page.add_include("exec_included") page.add_js_code(exec_jscode) # then we can go ahead and add html markup, extracting the Python # code to be executed in the process python_code = util.extract_code(elem) if util.is_interpreter_session(python_code): elem.attrib['title'] = "pycon" python_code = util.extract_code_from_interpreter(python_code) else: elem.attrib['title'] = "python" dummy, show_vlam = plugin['services'].style(page, elem, None, vlam) elem.attrib['title'] = vlam if log_id: config[page.username]['log'][log_id] = [tostring(elem)] util.wrap_in_div(elem, uid, vlam, "editor", show_vlam) if config[page.username]['popups']: # insert popup helper img = Element("img", src="/images/help.png", style="height:32px;", title = "cluetip Hello %s! "%page.username + "This is an Editor; click for more", rel = "/docs/popups/editor.html") elem.append(img) plugin['services'].insert_cluetip(page, img, uid) if (("no_copy" in vlam) and not ("no_pre" in vlam)) or (not python_code): python_code = "\n" plugin['services'].insert_editor_subwidget(page, elem, uid, python_code) return vlam
def pdb_widget_callback(page, elem, uid): """Handles embedding suitable code into the page in order to display and run pdb""" # When a security mode is set to "display ...", we only parse the # page, but no Python execution from is allowed from that page. # If that is the case, we won't include javascript either, to make # thus making the source easier to read. if 'display' not in config[page.username]['page_security_level'](page.url): if not page.includes("pdb_included"): page.add_include("pdb_included") #element tree always escape < to < and break my js code , so... page.insert_js_file("/pdb_js%s.js"%plugin['session_random_id']) if not page.includes("pdb_css_code"): page.add_include("pdb_css_code") page.add_css_code(pdb_css) # next, we style the code, also extracting it in a useful form ... vlam = elem.attrib["title"] python_code = util.extract_code(elem) if util.is_interpreter_session(python_code): elem.attrib['title'] = "pycon" python_code = util.extract_code_from_interpreter(python_code) else: elem.attrib['title'] = "python" code, show_vlam = plugin['services'].style(page, elem, None, vlam) elem.attrib['title'] = vlam util.wrap_in_div(elem, uid, vlam, "pdb", show_vlam) plugin['services'].insert_editor_subwidget(page, elem, uid, python_code) t = SubElement(elem, "h4", style="background-color:white;color:darkblue;") t.text = _("Local Namespace") local_ns_div = SubElement(elem, "div") local_ns_div.attrib["id"] = "local_ns_%s"%uid #some spacing: SubElement(elem, "br") btn = SubElement(elem, "button") btn.text = _("Start PDB") btn.attrib["onclick"] = "init_pdb('%s');" %(uid) btn.attrib["id"] = "btn_start_pdb_%s" % uid btn = SubElement(elem, "button") btn.text = _("Next Step") btn.attrib["id"] = "btn_next_step_%s" % uid btn.attrib["disabled"] = "disabled" btn = SubElement(elem, "button") btn.text = _("Step Into") btn.attrib["id"] = "btn_step_into_%s" % uid btn.attrib["disabled"] = "disabled" btn = SubElement(elem, "button") btn.text = _("Return") btn.attrib["id"] = "btn_return_%s" % uid btn.attrib["disabled"] = "disabled" btn = SubElement(elem, "button") btn.text = _("Next Multiple Steps") btn.attrib["id"] = "btn_next_many_steps_%s" % uid btn.attrib["disabled"] = "disabled" input1 = SubElement(elem, 'input', id='input_many_'+uid, size='4', value='1') t = SubElement(elem, "h4", style="background-color:white;color:darkblue;") t.text = _("Output") # finally, an output subwidget: plugin['services'].insert_io_subwidget(page, elem, uid) #register before_ouput hook plugin['services'].register_io_hook('before_output', pdb_filter, uid) #create pdb file cache for uid pdb_py_files[uid] = {}
def insert_interpreter(page, elem, uid): """inserts an interpreter (and the js code to initialise an interpreter)""" vlam = elem.attrib["title"] interp_kind = select_type( vlam, config[page.username]['override_default_interpreter'], elem) # When a security mode is set to "display ...", we only parse the # page, but no Python execution from is allowed from that page. # If that is the case, we won't include javascript either, to make # thus making the source easier to read. show = True if not ('display' in config[page.username]['page_security_level'](page.url) or interp_kind == None): include_interpreter(interp_kind, page, uid) log_id = util.extract_log_id(vlam) if log_id: t = 'interpreter' config[page.username]['logging_uids'][uid] = (log_id, t) else: log_id = False show = False # then we can go ahead and add html markup, extracting the Python # code to be executed in the process - we will not need this code; # this could change in a future version where we could add a button to # have the code automatically "injected" and executed by the # interpreter, thus saving some typing by the user. python_code = util.extract_code(elem) if util.is_interpreter_session(python_code): elem.attrib['title'] = "pycon" python_code = util.extract_code_from_interpreter(python_code) else: elem.attrib['title'] = "python" dummy, show_vlam = plugin['services'].style(page, elem, None, vlam) elem.attrib['title'] = vlam if log_id: config[page.username]['log'][log_id] = [tostring(elem)] util.wrap_in_div(elem, uid, vlam, "interpreter", show_vlam) if config[page.username][ 'popups'] and interp_kind is not None and not page.includes( "interpreter_helper"): page.add_include("interpreter_helper") # insert popup helper img = Element("img", src="/images/help.png", style="height:32px;", title="cluetip Hello %s! " % page.username + titles[interp_kind], rel=help_files[interp_kind]) elem.append(img) plugin['services'].insert_cluetip(page, img, uid) plugin['services'].insert_io_subwidget(page, elem, uid, interp_kind=interp_kind, sample_code=python_code, show=show) plugin['services'].insert_tooltip(page, elem, uid) return
def pdb_widget_callback(page, elem, uid): """Handles embedding suitable code into the page in order to display and run pdb""" # When a security mode is set to "display ...", we only parse the # page, but no Python execution from is allowed from that page. # If that is the case, we won't include javascript either, to make # thus making the source easier to read. if 'display' not in config[page.username]['page_security_level'](page.url): if not page.includes("pdb_included"): page.add_include("pdb_included") #element tree always escape < to < and break my js code , so... page.insert_js_file("/pdb_js%s.js" % plugin['session_random_id']) if not page.includes("pdb_css_code"): page.add_include("pdb_css_code") page.add_css_code(pdb_css) # next, we style the code, also extracting it in a useful form ... vlam = elem.attrib["title"] python_code = util.extract_code(elem) if util.is_interpreter_session(python_code): elem.attrib['title'] = "pycon" python_code = util.extract_code_from_interpreter(python_code) else: elem.attrib['title'] = "python" code, show_vlam = plugin['services'].style(page, elem, None, vlam) elem.attrib['title'] = vlam util.wrap_in_div(elem, uid, vlam, "pdb", show_vlam) plugin['services'].insert_editor_subwidget(page, elem, uid, python_code) t = SubElement(elem, "h4", style="background-color:white;color:darkblue;") t.text = _("Local Namespace") local_ns_div = SubElement(elem, "div") local_ns_div.attrib["id"] = "local_ns_%s" % uid #some spacing: SubElement(elem, "br") btn = SubElement(elem, "button") btn.text = _("Start PDB") btn.attrib["onclick"] = "init_pdb('%s');" % (uid) btn.attrib["id"] = "btn_start_pdb_%s" % uid btn = SubElement(elem, "button") btn.text = _("Next Step") btn.attrib["id"] = "btn_next_step_%s" % uid btn.attrib["disabled"] = "disabled" btn = SubElement(elem, "button") btn.text = _("Step Into") btn.attrib["id"] = "btn_step_into_%s" % uid btn.attrib["disabled"] = "disabled" btn = SubElement(elem, "button") btn.text = _("Return") btn.attrib["id"] = "btn_return_%s" % uid btn.attrib["disabled"] = "disabled" btn = SubElement(elem, "button") btn.text = _("Next Multiple Steps") btn.attrib["id"] = "btn_next_many_steps_%s" % uid btn.attrib["disabled"] = "disabled" input1 = SubElement(elem, 'input', id='input_many_' + uid, size='4', value='1') t = SubElement(elem, "h4", style="background-color:white;color:darkblue;") t.text = _("Output") # finally, an output subwidget: plugin['services'].insert_io_subwidget(page, elem, uid) #register before_ouput hook plugin['services'].register_io_hook('before_output', pdb_filter, uid) #create pdb file cache for uid pdb_py_files[uid] = {}