Skip to content

Commit 081f93a

Browse files
daspecsterlukesneeringer
authored andcommitted
Fix encryption example, remove document policy example. (googleapis#3221)
1 parent 3e929db commit 081f93a

File tree

2 files changed

+3
-40
lines changed

2 files changed

+3
-40
lines changed

docs/storage_snippets.py

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -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-
257226
def _line_no(func):
258227
code = getattr(func, '__code__', None) or getattr(func, 'func_code')
259228
return code.co_firstlineno

storage/google/cloud/storage/bucket.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -859,12 +859,6 @@ def generate_upload_policy(
859859
`policy documents`_ to allow visitors to a website to upload files to
860860
Google Cloud Storage without giving them direct write access.
861861
862-
For example:
863-
864-
.. literalinclude:: storage_snippets.py
865-
:start-after: [START policy_document]
866-
:end-before: [END policy_document]
867-
868862
.. _policy documents:
869863
https://cloud.google.com/storage/docs/xml-api\
870864
/post-object#policydocument

0 commit comments

Comments
 (0)