GoogleCloudPlatform/gcloud-python — pull request #352 by tseaver (2014-11-07 01:07:26+00:00)
Title: Fix #351: batch updates via context manager

See #351.

Add 'batch' property to '_PropertyMixin'.
- Defers / aggregates repeated calls to '_patch_properties' within the scope of a 'with foo.batch:' block.
- Issues a single '_patch_properties' call with the aggregated dict, IFF the block exits without an exception.
- If an exception is raised from the `with` block, all changes are discarded.

E.g:

with key.batch:
key.content_type = 'image/jpeg'
key.content_disposition = 'attachment; filename="photo.jpg"'

results in a single `PATCH` request, with payload:

{'contentType': 'image/jpeg', 'contentDisposition': 'attachment; filename="photo.jpg"'}