def handle(self): # self.set_readers() self.NOW = datetime.now() try: while True: line = self.c.fd.readline() if not line: break log.debug(line) self.r.handle(line) if self.r.done is True: break if self.r.uri == "/liasis-status": self.status() return if self.r.uri == "/": for p in DIR_INDEX: if os.path.exists(p): self.tfile = p self.rc = 200 break elif os.path.exists(os.path.join(os.getcwd(), self.r.uri[1:])): self.rc = 200 self.tfile = self.r.uri[1:] if self.r.modified_since is not None and self.modified_date( ) > datetime.strptime(self.r.modified_since, IN_FORMAT): self.rc = 304 else: os.chdir(LIASIS_DIR) self.tfile = os.path.join(os.getcwd(), self.tfile) # self.reader = "no_compress" # if self.r.accepts_compression is True: # if self.r.compression_algs[0] in self.reader_funct.keys(): # self.compression = self.r.compression_algs[0] # self.reader = self.compression self.headers() # for piece in self.reader_funct[self.reader](open(self.tfile, "r")): for piece in self.read_chunks(open(self.tfile, "r")): self.c.write(piece) return except Exception as e: log.debug(e)
def handle(self): # self.set_readers() self.NOW = datetime.now() try: while True: line = self.c.fd.readline() if not line: break log.debug(line) self.r.handle(line) if self.r.done is True: break if self.r.uri == "/liasis-status": self.status() return if self.r.uri == "/": for p in DIR_INDEX: if os.path.exists(p): self.tfile = p self.rc = 200 break elif os.path.exists(os.path.join(os.getcwd(), self.r.uri[1:])): self.rc = 200 self.tfile = self.r.uri[1:] if self.r.modified_since is not None and self.modified_date() > datetime.strptime(self.r.modified_since, IN_FORMAT): self.rc = 304 else: os.chdir(LIASIS_DIR) self.tfile = os.path.join(os.getcwd(), self.tfile) # self.reader = "no_compress" # if self.r.accepts_compression is True: # if self.r.compression_algs[0] in self.reader_funct.keys(): # self.compression = self.r.compression_algs[0] # self.reader = self.compression self.headers() # for piece in self.reader_funct[self.reader](open(self.tfile, "r")): for piece in self.read_chunks(open(self.tfile, "r")): self.c.write(piece) return except Exception as e: log.debug(e)
def write_header(self, header): log.debug("%s: %s\r\n" % (os.getpid(), header)) self.write("%s\r\n" % header)