예제 #1
0
 def run_cgi(self):
     """ Execute the CGI command. Wrap an innner call in an error
         handler so all errors can be caught.
     """
     try:
         self.inner_run_cgi()
     except client.NotFound:
         self.send_error(404, self.path)
     except client.Unauthorised as message:
         self.send_error(403, '%s (%s)' % (self.path, message))
     except:
         exc, val, tb = sys.exc_info()
         if hasattr(socket, 'timeout') and isinstance(val, socket.timeout):
             self.log_error('timeout')
         else:
             # it'd be nice to be able to detect if these are going to have
             # any effect...
             self.send_response(400)
             self.send_header('Content-Type', 'text/html')
             self.end_headers()
             if self.DEBUG_MODE:
                 try:
                     reload(cgitb)
                     self.wfile.write(s2b(cgitb.breaker()))
                     self.wfile.write(s2b(cgitb.html()))
                 except:
                     s = StringIO()
                     traceback.print_exc(None, s)
                     self.wfile.write(b"<pre>")
                     self.wfile.write(s2b(cgi.escape(s.getvalue())))
                     self.wfile.write(b"</pre>\n")
             else:
                 # user feedback
                 self.wfile.write(s2b(cgitb.breaker()))
                 ts = time.ctime()
                 self.wfile.write(
                     s2b('''<p>%s: An error occurred. Please check
                 the server log for more information.</p>''' % ts))
                 # out to the logfile
                 print('EXCEPTION AT', ts)
                 traceback.print_exc()
예제 #2
0
     self.send_error(403, '%s (%s)'%(self.path, message))
 except:
     exc, val, tb = sys.exc_info()
     if hasattr(socket, 'timeout') and isinstance(val, socket.timeout):
         self.log_error('timeout')
     else:
         # it'd be nice to be able to detect if these are going to have
         # any effect...
         self.send_response(400)
         self.send_header('Content-Type', 'text/html')
         self.end_headers()
         if self.DEBUG_MODE:
             try:
                 reload(cgitb)
                 self.wfile.write(cgitb.breaker())
                 self.wfile.write(cgitb.html())
             except:
                 s = StringIO.StringIO()
                 traceback.print_exc(None, s)
                 self.wfile.write("<pre>")
                 self.wfile.write(cgi.escape(s.getvalue()))
                 self.wfile.write("</pre>\n")
         else:
             # user feedback
             self.wfile.write(cgitb.breaker())
             ts = time.ctime()
             self.wfile.write('''<p>%s: An error occurred. Please check
             the server log for more information.</p>'''%ts)
             # out to the logfile
             print 'EXCEPTION AT', ts
             traceback.print_exc()
예제 #3
0
     self.send_error(403, '%s (%s)' % (self.path, message))
 except:
     exc, val, tb = sys.exc_info()
     if hasattr(socket, 'timeout') and isinstance(val, socket.timeout):
         self.log_error('timeout')
     else:
         # it'd be nice to be able to detect if these are going to have
         # any effect...
         self.send_response(400)
         self.send_header('Content-Type', 'text/html')
         self.end_headers()
         if self.DEBUG_MODE:
             try:
                 reload(cgitb)
                 self.wfile.write(cgitb.breaker())
                 self.wfile.write(cgitb.html())
             except:
                 s = StringIO.StringIO()
                 traceback.print_exc(None, s)
                 self.wfile.write("<pre>")
                 self.wfile.write(cgi.escape(s.getvalue()))
                 self.wfile.write("</pre>\n")
         else:
             # user feedback
             self.wfile.write(cgitb.breaker())
             ts = time.ctime()
             self.wfile.write('''<p>%s: An error occurred. Please check
             the server log for more infomation.</p>''' % ts)
             # out to the logfile
             print 'EXCEPTION AT', ts
             traceback.print_exc()
예제 #4
0
파일: client.py 프로젝트: sgala/roundup
            self.response_code = 404
            self.template = '404'
            try:
                cl = self.db.getclass(self.classname)
                self.write_html(self.renderContext())
            except KeyError:
                # we can't map the URL to a class we know about
                # reraise the NotFound and let roundup_server
                # handle it
                raise NotFound, e
        except FormError, e:
            self.error_message.append(self._('Form Error: ') + str(e))
            self.write_html(self.renderContext())
        except:
            if self.instance.config.WEB_DEBUG:
                self.write_html(cgitb.html(i18n=self.translator))
            else:
                self.mailer.exception_message()
                return self.write_html(self._(error_message))

    def clean_sessions(self):
        """Age sessions, remove when they haven't been used for a week.

        Do it only once an hour.

        Note: also cleans One Time Keys, and other "session" based stuff.
        """
        sessions = self.db.getSessionManager()
        last_clean = sessions.get('last_clean', 'last_use', 0)

        # time to clean?