def except_handler(etype=None, evalue=None, etb=None): """ Log uncaught exceptions and display a friendly error. """ if not etype or not evalue or not etb: etype, evalue, etb = sys.exc_info() import cgitb out(cgitb.reset()) if logdir is None: out(error_template % """ A problem has occurred, but it probably isn't your fault. """) else: import stat import traceback try: doc = cgitb.html((etype, evalue, etb), 5) except: # just in case something goes wrong doc = ''.join(traceback.format_exception(etype, evalue, etb)) if debug: out(doc) return try: while etb.tb_next != None: etb = etb.tb_next e_file = etb.tb_frame.f_code.co_filename e_line = etb.tb_frame.f_lineno ldir = os.path.join(logdir, os.path.split(e_file)[-1]) if not os.path.exists(ldir): os.umask(0000) os.makedirs(ldir) (fd, path) = tempfile.mkstemp( prefix="%s_" % e_line, suffix='.html', dir=ldir ) fh = os.fdopen(fd, 'w') fh.write(doc) fh.close() os.chmod(path, stat.S_IROTH) out(error_template % """\ A problem has occurred, but it probably isn't your fault. RED has remembered it, and we'll try to fix it soon.""") except: out(error_template % """\ A problem has occurred, but it probably isn't your fault. RED tried to save it, but it couldn't! Oops.<br> Please e-mail the information below to <a href='mailto:[email protected]'>[email protected]</a> and we'll look into it.""") out("<h3>Original Error</h3>") out("<pre>") out(''.join(traceback.format_exception(etype, evalue, etb))) out("</pre>") out("<h3>Write Error</h3>") out("<pre>") etype, value, tb = sys.exc_info() out(''.join(traceback.format_exception(etype, value, tb))) out("</pre>") sys.exit(1) # We're in an uncertain state, so we must die horribly.
def except_handler(etype=None, evalue=None, etb=None): """ Log uncaught exceptions and display a friendly error. """ if not etype or not evalue or not etb: etype, evalue, etb = sys.exc_info() import cgitb out(cgitb.reset()) if logdir is None: out(error_template % """ A problem has occurred, but it probably isn't your fault. """) else: import stat import traceback try: doc = cgitb.html((etype, evalue, etb), 5) except: # just in case something goes wrong doc = ''.join(traceback.format_exception(etype, evalue, etb)) if debug: out(doc) return try: while etb.tb_next != None: etb = etb.tb_next e_file = etb.tb_frame.f_code.co_filename e_line = etb.tb_frame.f_lineno ldir = os.path.join(logdir, os.path.split(e_file)[-1]) if not os.path.exists(ldir): os.umask(0000) os.makedirs(ldir) (fd, path) = tempfile.mkstemp(prefix="%s_" % e_line, suffix='.html', dir=ldir) fh = os.fdopen(fd, 'w') fh.write(doc) fh.close() os.chmod(path, stat.S_IROTH) out(error_template % """\ A problem has occurred, but it probably isn't your fault. RED has remembered it, and we'll try to fix it soon.""") except: out(error_template % """\ A problem has occurred, but it probably isn't your fault. RED tried to save it, but it couldn't! Oops.<br> Please e-mail the information below to <a href='mailto:[email protected]'>[email protected]</a> and we'll look into it.""") out("<h3>Original Error</h3>") out("<pre>") out(''.join(traceback.format_exception(etype, evalue, etb))) out("</pre>") out("<h3>Write Error</h3>") out("<pre>") etype, value, tb = sys.exc_info() out(''.join(traceback.format_exception(etype, value, tb))) out("</pre>") sys.exit(1) # We're in an uncertain state, so we must die horribly.
from cgitb import reset from turtle import * from tkinter import * app = Tk() # app conf app.title("DK PYapp") app.geometry("600x300") # app["bg"] = "grey" app.iconbitmap("icon.ico") Turtle reset() variable = 0 while variable > 12: variable += 1 forward(150) left(150) reset()
def update_event(self, inp=-1): self.set_output_val(0, cgitb.reset())
def except_handler(etype=None, evalue=None, etb=None): # type: ignore """ Log uncaught exceptions and display a friendly error. """ if not etype or not evalue or not etb: etype, evalue, etb = sys.exc_info() import cgitb out(cgitb.reset()) if not config.get("exception_dir", ""): out(error_template % """ A problem has occurred, but it probably isn't your fault. """) else: import stat import traceback if qs: doc = "<h3><code>%s</code></h3>" % qs.decode( "utf-8", "replace") try: doc += cgitb.html((etype, evalue, etb), 5) except: # just in case something goes wrong doc += ("<pre>" + "".join( traceback.format_exception(etype, evalue, etb)) + "</pre>") if config.getboolean("debug"): out(doc) return try: while etb.tb_next is not None: etb = etb.tb_next e_file = etb.tb_frame.f_code.co_filename e_line = etb.tb_frame.f_lineno ldir = os.path.join(config["exception_dir"], os.path.split(e_file)[-1]) if not os.path.exists(ldir): os.umask(0o002) os.makedirs(ldir) (fd, path) = tempfile.mkstemp(prefix="%s_" % e_line, suffix=".html", dir=ldir) fh = os.fdopen(fd, "w") fh.write(doc) fh.close() os.chmod(path, stat.S_IROTH) out(error_template % """\ A problem has occurred, but it probably isn't your fault. REDbot has remembered it, and we'll try to fix it soon.""") except: out(error_template % """\ A problem has occurred, but it probably isn't your fault. REDbot tried to save it, but it couldn't! Oops.<br> Please e-mail the information below to <a href='mailto:[email protected]'>[email protected]</a> and we'll look into it.""") out("<h3>Original Error</h3>") out("<pre>") out("".join(traceback.format_exception(etype, evalue, etb))) out("</pre>") out("<h3>Write Error</h3>") out("<pre>") out("".join(traceback.format_exc())) out("</pre>") sys.exit(1) # We're in an uncertain state, so we must die horribly.
def except_handler(etype, evalue, etb): """ Log uncaught exceptions and display a friendly error. Assumes output to STDOUT (i.e., CGI only). """ import cgitb print cgitb.reset() if logdir is None: print error_template % """ A problem has occurred, but it probably isn't your fault. """ else: import stat import traceback try: doc = cgitb.html((etype, evalue, etb), 5) except: # just in case something goes wrong doc = ''.join(traceback.format_exception(etype, evalue, etb)) try: while etb.tb_next != None: etb = etb.tb_next e_file = etb.tb_frame.f_code.co_filename e_line = etb.tb_frame.f_lineno ldir = os.path.join(logdir, os.path.split(e_file)[-1]) if not os.path.exists(ldir): os.umask(0000) os.makedirs(ldir) (fd, path) = tempfile.mkstemp( prefix="%s_" % e_line, suffix='.html', dir=ldir ) fh = os.fdopen(fd, 'w') fh.write(doc) fh.write("<h2>Outstanding Connections</h2>\n<pre>") for conn in fetch.outstanding_requests: fh.write("*** %s - %s\n" % (conn.uri, hex(id(conn)))) pprint.pprint(conn.__dict__, fh) if conn.client: pprint.pprint(conn.client.__dict__, fh) if conn.client._tcp_conn: pprint.pprint(conn.client._tcp_conn.__dict__, fh) fh.write("</pre>\n") fh.close() os.chmod(path, stat.S_IROTH) print error_template % """ A problem has occurred, but it probably isn't your fault. RED has remembered it, and we'll try to fix it soon.""" except: print error_template % """\ A problem has occurred, but it probably isn't your fault. RED tried to save it, but it couldn't! Oops.<br> Please e-mail the information below to <a href='mailto:[email protected]'>[email protected]</a> and we'll look into it.""" print "<h3>Original Error</h3>" print "<pre>" print ''.join(traceback.format_exception(etype, evalue, etb)) print "</pre>" print "<h3>Write Error</h3>" print "<pre>" etype, value, tb = sys.exc_info() print ''.join(traceback.format_exception(etype, value, tb)) print "</pre>" sys.stdout.flush()