20

Google App Engine に最適な小さなプロジェクトがあります。実装は、ZIP ファイルを生成して返す機能にかかっています。

私が知る限り、App Engine の分散型の性質により、従来の意味で ZIP ファイルを「メモリ内」に作成することはできませんでした。基本的に、単一の要求/応答サイクルで生成および送信する必要があります。

Python zip モジュールは App Engine 環境にも存在しますか?

4

3 に答える 3

33

zipfileは appengine で入手でき、次のように作り直されたを示します。

from contextlib import closing
from zipfile import ZipFile, ZIP_DEFLATED

from google.appengine.ext import webapp
from google.appengine.api import urlfetch

def addResource(zfile, url, fname):
    # get the contents      
    contents = urlfetch.fetch(url).content
    # write the contents to the zip file
    zfile.writestr(fname, contents)

class OutZipfile(webapp.RequestHandler):
    def get(self):
        # Set up headers for browser to correctly recognize ZIP file
        self.response.headers['Content-Type'] ='application/zip'
        self.response.headers['Content-Disposition'] = \
            'attachment; filename="outfile.zip"'    

        # compress files and emit them directly to HTTP response stream
        with closing(ZipFile(self.response.out, "w", ZIP_DEFLATED)) as outfile:
            # repeat this for every URL that should be added to the zipfile
            addResource(outfile, 
                'https://www.google.com/intl/en/policies/privacy/', 
                'privacy.html')
            addResource(outfile, 
                'https://www.google.com/intl/en/policies/terms/', 
                'terms.html')
于 2009-02-24T22:06:10.397 に答える
2

Google App Engine とはから:

純粋な Python で実装され、サポートされていない標準ライブラリ モジュールを必要としない限り、他のサードパーティ ライブラリをアプリケーションと共にアップロードできます。

したがって、デフォルトで存在しない場合でも、(潜在的に) 自分で含めることができます。( Python zip ライブラリが「サポートされていない標準ライブラリ モジュール」を必要とするかどうかがわからないため、可能性があると言います。

于 2009-02-24T22:02:14.307 に答える