__init__.py 文件源码

python
阅读 16 收藏 0 点赞 0 评论 0

项目:layman 作者: CCSS-CZ 项目源码 文件源码
def getFile(self,fileName):
        """Return file itself
        """

        # TODO: set propper Content/type
        try:
            if fileName.find(".shp") or fileName.find(".tab"):
                (path,fn) = os.path.split(fileName)
                old_path = os.path.abspath(os.path.curdir)
                os.chdir(path)
                fn_noext = os.path.splitext(fn)[0]
                from zipfile import ZipFile
                from io import BytesIO
                filelike = BytesIO()
                zipout = ZipFile(filelike,"w")
                for f in os.listdir(os.path.curdir):
                    if f.find(fn_noext) > -1:
                        zipout.write(f)

                zipout.close()
                web.header('Content-Disposition','attachment; filename="%s.zip"'% fn_noext)
                os.chdir(old_path)
                fn_noext = os.path.splitext(fn)[0]
                return (200, filelike.getvalue())
            else:
                return (200, open(fileName).read())

        except Exception as e:
            message = "LayEd: getFile(): Unable to read from the file named '" + fileName + "'. Exception received: " + str(e)
            raise LaymanError(500, message)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号