@@ -94,6 +94,7 @@ def download_to_file(client, to_delete):
9494 bucket = client .get_bucket ('my-bucket' )
9595 encryption_key = 'c7f32af42e45e85b9848a6a14dd2a8f6'
9696 blob = Blob ('secure-data' , bucket , encryption_key = encryption_key )
97+ blob .upload_from_string ('my secret message.' )
9798 with open ('/tmp/my-secure-file' , 'wb' ) as file_obj :
9899 blob .download_to_file (file_obj )
99100 # [END download_to_file]
@@ -138,7 +139,8 @@ def delete_blob(client, to_delete):
138139 from google .cloud .exceptions import NotFound
139140 client = storage .Client ()
140141 bucket = client .get_bucket ('my-bucket' )
141- assert isinstance (bucket .list_blobs (), list )
142+ blobs = list (bucket .list_blobs ())
143+ assert len (blobs ) > 0
142144 # [<Blob: my-bucket, my-file.txt>]
143145 bucket .delete_blob ('my-file.txt' )
144146 try :
@@ -221,39 +223,6 @@ def list_buckets(client, to_delete):
221223 to_delete .append (bucket )
222224
223225
224- @snippet
225- def policy_document (client , to_delete ):
226- # pylint: disable=unused-argument
227- # [START policy_document]
228- bucket = client .bucket ('my-bucket' )
229- conditions = [
230- ['starts-with' , '$key' , '' ],
231- {'acl' : 'public-read' }]
232-
233- policy = bucket .generate_upload_policy (conditions )
234-
235- # Generate an upload form using the form fields.
236- policy_fields = '' .join (
237- '<input type="hidden" name="{key}" value="{value}">' .format (
238- key = key , value = value )
239- for key , value in policy .items ()
240- )
241-
242- upload_form = (
243- '<form action="http://{bucket_name}.storage.googleapis.com"'
244- ' method="post"enctype="multipart/form-data">'
245- '<input type="text" name="key" value="">'
246- '<input type="hidden" name="bucket" value="{bucket_name}">'
247- '<input type="hidden" name="acl" value="public-read">'
248- '<input name="file" type="file">'
249- '<input type="submit" value="Upload">'
250- '{policy_fields}'
251- '<form>' ).format (bucket_name = bucket .name , policy_fields = policy_fields )
252-
253- print (upload_form )
254- # [END policy_document]
255-
256-
257226def _line_no (func ):
258227 code = getattr (func , '__code__' , None ) or getattr (func , 'func_code' )
259228 return code .co_firstlineno
0 commit comments