Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 import appengine_datastore as datastore | |
| 6 from appengine_datastore import AppEngineDatastore | |
| 7 from appengine_wrappers import blobstore | |
| 8 from appengine_wrappers import files | |
| 9 | |
| 10 class AppEngineBlobstore(object): | |
| 11 """A wrapper around the blobstore API, which stores the blob keys in | |
| 12 datastore. | |
| 13 """ | |
| 14 def __init__(self): | |
| 15 self._datastore = AppEngineDatastore('blobstore') | |
| 16 | |
| 17 def Set(self, key, blob, version): | |
|
not at google - send to devlin
2012/08/09 07:52:36
yeah, I don't really see the need to store multipl
cduvall
2012/08/09 19:20:08
See comment my reply to your other version comment
| |
| 18 """Add a blob to the blobstore. |version| is used as part of the key so | |
| 19 multiple blobs with the same name can be differentiated. | |
| 20 """ | |
| 21 key = key + '.' + str(version) | |
| 22 filename = files.blobstore.create() | |
| 23 with files.open(filename, 'a') as f: | |
| 24 f.write(blob) | |
| 25 files.finalize(filename) | |
| 26 blob_key = files.blobstore.get_blob_key(filename) | |
| 27 self._datastore.Set(key, blob_key, datastore.DATASTORE_BLOBSTORE) | |
| 28 | |
| 29 def Get(self, key, version): | |
| 30 """Get a blob with version |version|. | |
| 31 """ | |
| 32 key = key + '.' + str(version) | |
| 33 blob_key = self._datastore.Get(key, datastore.DATASTORE_BLOBSTORE) | |
| 34 if blob_key is None: | |
| 35 return None | |
| 36 blob_reader = blobstore.BlobReader(blob_key) | |
| 37 return blob_reader.read() | |
| 38 | |
| 39 def Delete(self, key, version): | |
| 40 """Delete the blob with version |version| if it is found. | |
| 41 """ | |
| 42 key = key + '.' + str(version) | |
| 43 blob_key = self._datastore.Get(key, datastore.DATASTORE_BLOBSTORE) | |
| 44 if blob_key is None: | |
| 45 return | |
| 46 blobstore.delete(blob_key) | |
| OLD | NEW |