Exemplo n.º 1
0
    def exec_code(self, sourcecode):

        start_time = time.time()

        stdout_redirector = Redirector(self.page_msg)
        globals = {}
        locals = {}

        try:
            code = compile(sourcecode, "<stdin>", "exec", 0, 1)
            if "pylucid_access" in self.request.form:
                exec code
            else:
                exec code in globals, locals
        except:
            etype, value, tb = sys.exc_info()
            tb = tb.tb_next
            msg = ''.join(traceback.format_exception(etype, value, tb))
            sys.stdout.write(msg)

        output = stdout_redirector.get()

        duration = time.time() - start_time

        self.response.write(
            "<fieldset><legend>executed in %.3fsec.:</legend>" % duration
        )
        self.response.write("<pre>")
        self.response.write(output)
        self.response.write("</pre></fieldset>")
Exemplo n.º 2
0
    def exec_code(self, sourcecode):

        start_time = time.time()

        stdout_redirector = Redirector(self.page_msg)
        globals = {}
        locals = {}

        try:
            code = compile(sourcecode, "<stdin>", "exec", 0, 1)
            if "pylucid_access" in self.request.form:
                exec code
            else:
                exec code in globals, locals
        except:
            etype, value, tb = sys.exc_info()
            tb = tb.tb_next
            msg = ''.join(traceback.format_exception(etype, value, tb))
            sys.stdout.write(msg)

        output = stdout_redirector.get()

        duration = time.time() - start_time

        self.response.write(
            "<fieldset><legend>executed in %.3fsec.:</legend>" % duration)
        self.response.write("<pre>")
        self.response.write(output)
        self.response.write("</pre></fieldset>")
Exemplo n.º 3
0
 def __get_help(self, obj):
     out = Redirector(self.page_msg)
     help(obj)
     return cgi.escape(out.get())
Exemplo n.º 4
0
 def __get_help(self, obj):
     out = Redirector(self.page_msg)
     help(obj)
     return cgi.escape(out.get())