falcon python来重新设置文件

时间:2017-04-05 11:43:24

标签: python-2.7 falcon

class Newuser(object):
    def on_get(self,req,resp):
        """
        :param req: With request reads Original.exe and append the data with "echo.CUSTDATA:uuid.uuid4()"
        :param resp: with response user will be able to download packed Setup.exe
        :return: Setup.exe with CUSTDATA:uuid.uuid4() at the end of the file.
        """
        print("requests")

        import uuid
        uui = uuid.uuid4()
        self.storage.add_user_uuid(uui,"000")
        with open("original.exe",'r') as f:
            Original_exe = f.read()
            Original_exe+=('echo.CUSTDATA:{}'.format(str(uui)))
        with open("Setup.exe",'w') as g:
            g.write(Original_exe)
        #resp.set_header("Content-Disposition", "attachment; filename=\"%s\"" % Original_exe)
        resp.data = "Setup.exe"

现在我在同一个文件夹上有这个original.exe,我只想用uuid更新它,这很好并且正常工作,当有人提出请求时,如何使这个可供下载。新的猎鹰

1 个答案:

答案 0 :(得分:1)

我明白了,谢谢

   with open("original.exe",'r') as f:
        Original_exe = f.read()
        Original_exe+=('echo.CUSTDATA:{}'.format(str(uui)))
    Original = "Setup.exe"
    resp.set_header("Content-Disposition", "attachment; filename=\"%s\"" % Original)
    resp.data = Original_exe
    resp.status = falcon.HTTP_200

如果有人需要它