def _get_tmpl_raw(tmpl_target, rev, path, project_name, request): project = CodeDoubanProject.get_by_name(project_name) if rev is None: rev = project.default_branch try: blob = project.repo.get_file(rev, path.decode('utf-8')) except IOError: raise TraversalError() if not blob: raise TraversalError("No content found") resp = request.response if is_image(path): if path.endswith('svg'): resp.set_header("Content-Type", "image/svg+xml") else: resp.set_header("Content-Type", "image/jpeg") resp.set_header('Expires', 'Sun, 1 Jan 2006 01:00:00 GMT') resp.set_header('Pragma', 'no-cache') resp.set_header('Cache-Control', 'must-revalidate, no-cache, private') return blob.data if path.endswith('.pdf'): resp.set_header("Content-Type", "application/pdf") return blob.data if is_binary(path): resp.set_header("Content-Type", "application/octet-stream") resp.set_header("Content-Disposition", "attachment;filename=%s" % path.split('/')[-1]) resp.set_header("Content-Transfer-Encoding", "binary") return blob.data resp.set_header("Content-Type", "text/plain;charset=utf-8") return blob.data.encode('utf8')
def _get_tmpl_raw(tmpl_target, rev, path, project_name, request): project = CodeDoubanProject.get_by_name(project_name) if rev is None: rev = project.default_branch try: blob = project.repo.get_file(rev, path.decode("utf-8")) except IOError: raise TraversalError() if not blob: raise TraversalError("No content found") resp = request.response if is_image(path): if path.endswith("svg"): resp.set_header("Content-Type", "image/svg+xml") else: resp.set_header("Content-Type", "image/jpeg") resp.set_header("Expires", "Sun, 1 Jan 2006 01:00:00 GMT") resp.set_header("Pragma", "no-cache") resp.set_header("Cache-Control", "must-revalidate, no-cache, private") return blob.data if path.endswith(".pdf"): resp.set_header("Content-Type", "application/pdf") return blob.data if is_binary(path): resp.set_header("Content-Type", "application/octet-stream") resp.set_header("Content-Disposition", "attachment;filename=%s" % path.split("/")[-1]) resp.set_header("Content-Transfer-Encoding", "binary") return blob.data resp.set_header("Content-Type", "text/plain;charset=utf-8") return blob.data.encode("utf8")
def image(self): return is_image(self.old_file_path)