Exemplo n.º 1
0
 def error(self, status=500, allowredirect = True, close = True, showerror = None, headers = []):
     if showerror is None:
         showerror = self.showerrorinfo
     if self._sendHeaders:
         if showerror:
             typ, exc, tb = sys.exc_info()
             if exc:
                 for m in self.write('<span style="white-space:pre-wrap">\n', buffering = False):
                     yield m
                 for m in self.writelines((self.nl2br(self.escape(v)) for v in traceback.format_exception(typ, exc, tb)), buffering = False):
                     yield m
                 for m in self.write('</span>\n', close, False):
                     yield m
     elif allowredirect and status in self.protocol.errorrewrite:
         for m in self.rewrite(self.protocol.errorrewrite[status], b'GET'):
             yield m
     elif allowredirect and status in self.protocol.errorredirect:
         for m in self.redirect(self.protocol.errorredirect[status]):
             yield m
     else:
         self.startResponse(status, headers)
         typ, exc, tb = sys.exc_info()
         if showerror and exc:
             for m in self.write('<span style="white-space:pre-wrap">\n', buffering = False):
                 yield m
             for m in self.writelines((self.nl2br(self.escape(v)) for v in traceback.format_exception(typ, exc, tb)), buffering = False):
                 yield m
             for m in self.write('</span>\n', close, False):
                 yield m
         else:
             for m in self.write(b'<h1>' + _createstatus(status) + b'</h1>', close, False):
                 yield m
Exemplo n.º 2
0
 def basicauthfail(self, realm=b'all'):
     """
     Return 401 for authentication failure. This will end the handler.
     """
     if not isinstance(realm, bytes):
         realm = realm.encode('ascii')
     self.start_response(
         401, [(b'WWW-Authenticate', b'Basic realm="' + realm + b'"')])
     self.exit(b'<h1>' + _createstatus(401) + b'</h1>')
Exemplo n.º 3
0
 def basicauthfail(self, realm=b'all'):
     if not isinstance(realm, bytes):
         realm = realm.encode('ascii')
     self.startResponse(
         401, [(b'WWW-Authenticate', b'Basic realm="' + realm + b'"')])
     self.exit(b'<h1>' + _createstatus(401) + b'</h1>')