Exemplo n.º 1
0
 def run(self):
     self.stream = read_stream.sock_stream(self.conn)
     upgrade = False
     try:
         try:
             for request in request_stream(self,
                                           self.stream).gen_requests():
                 if request.bad:
                     # bad request
                     request.error(400)
                 else:
                     try:
                         handler = self.pick_handler(request)
                         if handler:
                             # XXX with_timeout() ?
                             handler.handle_request(request)
                         else:
                             request.error(404)
                         request.wait_until_done()
                     except (coro.TimeoutError, coro.Interrupted):
                         raise
                     except HTTP_Upgrade:
                         upgrade = True
                         break
                     except Exception:
                         tb = coro.traceback_data()
                         self.server.log('error', repr(request), tb)
                         request.error(500, tb)
         except (OSError, coro.TimeoutError, coro.ClosedError):
             pass
     finally:
         if not upgrade:
             self.conn.close()
Exemplo n.º 2
0
 def run (self):
     self.stream = read_stream.sock_stream (self.conn)
     upgrade = False
     try:
         try:
             for request in request_stream (self, self.stream).gen_requests():
                 if request.bad:
                     # bad request
                     request.error (400)
                 else:
                     try:
                         handler = self.pick_handler (request)
                         if handler:
                             # XXX with_timeout() ?
                             handler.handle_request (request)
                         else:
                             request.error (404)
                         request.wait_until_done()
                     except (coro.TimeoutError, coro.Interrupted):
                         raise
                     except HTTP_Upgrade:
                         upgrade = True
                         break
                     except Exception:
                         tb = coro.traceback_data()
                         self.server.log ('error', repr(request), tb)
                         request.error (500, tb)
         except (OSError, coro.TimeoutError, coro.ClosedError):
             pass
     finally:
         if not upgrade:
             self.conn.close()
Exemplo n.º 3
0
 def handle_request (self, qid, path, params):
     o = self.root
     e = None
     if self.debug:
         LOG ('<-', self.conn.fd, qid, path, params)
     try:
         for p in path:
             o = getattr (o, p)
         result = o (*params)
     except Exception:
         e = (sys.exc_info()[1].__class__.__name__, coro.traceback_data())
         LOG ('exc', e)
         result = None
     if self.debug:
         LOG ('->', self.conn.fd, qid, e, result)
     self.push (encode ([KIND_REPLY, qid, e, result]))
Exemplo n.º 4
0
 def handle_request(self, qid, path, params):
     o = self.root
     e = None
     if self.debug:
         LOG('<-', self.conn.fd, qid, path, params)
     try:
         for p in path:
             o = getattr(o, p)
         result = o(*params)
     except Exception:
         e = (sys.exc_info()[1].__class__.__name__, coro.traceback_data())
         LOG('exc', e)
         result = None
     if self.debug:
         LOG('->', self.conn.fd, qid, e, result)
     self.push(encode([KIND_REPLY, qid, e, result]))
Exemplo n.º 5
0
 def exc(self):
     log('exception', coro.traceback_data())
Exemplo n.º 6
0
 def exc (self):
     log ('exception', coro.traceback_data())