def get_content(cls, abspath: str, start: int = None, end: int = None) -> Generator[bytes, None, None]: if abspath != "": return StaticFileHandler.get_content(abspath, start, end) return
def get_content(cls, abspath, start=None, end=None): if cls.is_html_path(abspath): html = open(abspath, 'r').read() html = html.replace('</body>', cls.SCRIPT_AND_END_OF_BODY) return html else: return StaticFileHandler.get_content(abspath, start, end)
def get_upload_content(filename): upload_path = get_upload_path() filepath = os.path.join(upload_path, filename) filepath = validate_absolute_path(filepath) return StaticFileHandler.get_content(filepath)
def get_content(cls, abspath, start=None, end=None): gc.collect() # 在mp4内容的时候,如果刷新网页会导致10053错误,并且内存不能回收,这里粗暴处理一下 if cls.is_html_path(abspath): html = open(abspath, 'r').read() html = html.replace('</body>', cls.SCRIPT_AND_END_OF_BODY) return html else: return StaticFileHandler.get_content(abspath, start, end)
def get_content(cls, abspath, start=None, end=None): gc.collect() # 在mp4内容的时候,如果刷新网页会导致10053错误,并且内存不能回收,这里粗暴处理一下 _, ext = os.path.splitext(abspath) if ext in SPECIAL_EXTENSIONS: content = open(abspath, 'r').read() if ext in HTML_EXTENSIONS: return process_html(content) elif ext in CSS_EXTENSIONS: return process_css(content) return StaticFileHandler.get_content(abspath, start, end)
def create_static_file_handler(self, name, path): self.set_header("Content-Type", "application/octet-stream") self.set_header("Content-Disposition", "attachment; filename={}".format(name)) content = StaticFileHandler.get_content(path) if isinstance(content, bytes): content = [content] for chunk in content: try: self.write(chunk) yield self.flush() except iostream.StreamClosedError: self.write_error(500, desc="download file failed, retry") return self.set_status(200) return self.finish()