<s> import tempfile <EOL> import time <EOL> from wal_e import pipebuf <EOL> from wal_e import storage <EOL> from wal_e . blobstore import get_blobstore <EOL> from wal_e import pipeline <EOL> def uri_put_file ( creds , uri , fp , content_encoding = None ) : <EOL> blobstore = get_blobstore ( storage . StorageLayout ( uri ) ) <EOL> return blobstore . uri_put_file ( creds , uri , fp , <EOL> content_encoding = content_encoding ) <EOL> def do_lzop_put ( creds , url , local_path , gpg_key ) : <EOL> """<STR_LIT>""" <EOL> assert url . endswith ( '<STR_LIT>' ) <EOL> blobstore = get_blobstore ( storage . StorageLayout ( url ) ) <EOL> with tempfile . NamedTemporaryFile ( <EOL> mode = '<STR_LIT>' , bufsize = pipebuf . PIPE_BUF_BYTES ) as tf : <EOL> with pipeline . get_upload_pipeline ( <EOL> open ( local_path , '<STR_LIT:r>' ) , tf , gpg_key = gpg_key ) : <EOL> pass <EOL> tf . flush ( ) <EOL> clock_start = time . time ( ) <EOL> tf . seek ( <NUM_LIT:0> ) <EOL> k = blobstore . uri_put_file ( creds , url , tf ) <EOL> clock_finish = time . time ( ) <EOL> kib_per_second = format_kib_per_second ( <EOL> clock_start , clock_finish , k . size ) <EOL> return kib_per_second <EOL> def do_lzop_get ( creds , url , path , decrypt , do_retry = True ) : <EOL> """<STR_LIT>""" <EOL> blobstore = get_blobstore ( storage . StorageLayout ( url ) ) <EOL> return blobstore . do_lzop_get ( creds , url , path , decrypt , do_retry = do_retry ) <EOL> def format_kib_per_second ( start , finish , amount_in_bytes ) : <EOL> try : <EOL> return '<STR_LIT>' . format ( ( amount_in_bytes / <NUM_LIT> ) / ( finish - start ) ) <EOL> except ZeroDivisionError : <EOL> return '<STR_LIT>' </s>
