Ejemplo n.º 1
0
Archivo: server.py Proyecto: p/midge
 def _retire_session(self, session_id):
     try:
         del self.session_ids[session_id]
         logger.debug("Retiring session: %s" % session_id)
         self.application.expired_session(session_id)
     except KeyError:
         pass
Ejemplo n.º 2
0
Archivo: server.py Proyecto: p/midge
 def do_POST(self):
     self._sessions.acquire_lock()
     try:
         proposed_session_id = self._extract_session_id()
         session_id = self._sessions.get_valid_session_id(
             proposed_session_id)
         content_length = self.headers.dict.get("content-length", None)
         if content_length is not None:
             raw_post_data = self.rfile.read(int(content_length))
             path, values = lib.split_url(self.path)
             logger.debug(
                 "http post %s for session: %s" % (path, session_id))
             location = self._locations.get(path)
             if location:
                 try:
                     wfile = cStringIO.StringIO()
                     post_data = self._decode_raw_post_data(raw_post_data)
                     location.handle_post(session_id, values,
                                          post_data, wfile)
                     self._send_standard_header(session_id, location.mime_type)
                     self.wfile.write(wfile.getvalue())
                 except RedirectException, e:
                     self._send_redirect(e.path)
                 except Exception:
                     self._send_exception()
Ejemplo n.º 3
0
Archivo: server.py Proyecto: p/midge
 def _send_redirect(self, path):
     logger.debug("Redirect to: %s" % path)
     self.send_response(HttpCodes.SeeOther)
     self.send_header("Content-type", "text/html")
     self.send_header("Server", self.SERVER_NAME)
     self.send_header("Location", path)
     self.end_headers()
Ejemplo n.º 4
0
Archivo: server.py Proyecto: p/midge
 def _generate_session_id(self):
     session_id = str(random.randint(0, sys.maxint))
     while session_id in self.session_ids:
         session_id = str(random.randint(0, sys.maxint))
     logger.debug("Generating new session: %s" % session_id)
     self._refresh_session(session_id)
     self.application.new_session(session_id)
     return session_id
Ejemplo n.º 5
0
Archivo: server.py Proyecto: p/midge
 def do_GET(self):
     self._sessions.acquire_lock()
     try:
         proposed_session_id = self._extract_session_id()
         session_id = self._sessions.get_valid_session_id(
             proposed_session_id)
         path, values = lib.split_url(self.path)
         host = self.client_address[0]
         logger.debug("http get %s from host %s (session %s)" % (path,
                                                                 host,
                                                                 session_id))
         location = self._locations.get(path)
         if location:
             try:
                 wfile = cStringIO.StringIO()
                 location.handle_get(session_id, values, wfile)
                 self._send_standard_header(session_id, location.mime_type)
                 self.wfile.write(wfile.getvalue())
             except RedirectException, e:
                 self._send_redirect(e.path)
             except Exception:
                 self._send_exception()