Index: chrome/common/extensions/docs/server2/appengine_blobstore.py |
diff --git a/chrome/common/extensions/docs/server2/appengine_blobstore.py b/chrome/common/extensions/docs/server2/appengine_blobstore.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..a89efb6a1f66b9b6714e84010fdae3f7487221b4 |
--- /dev/null |
+++ b/chrome/common/extensions/docs/server2/appengine_blobstore.py |
@@ -0,0 +1,46 @@ |
+# Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+ |
+import appengine_datastore as datastore |
+from appengine_datastore import AppEngineDatastore |
+from appengine_wrappers import blobstore |
+from appengine_wrappers import files |
+ |
+class AppEngineBlobstore(object): |
+ """A wrapper around the blobstore API, which stores the blob keys in |
+ datastore. |
+ """ |
+ def __init__(self): |
+ self._datastore = AppEngineDatastore('blobstore') |
+ |
+ 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
|
+ """Add a blob to the blobstore. |version| is used as part of the key so |
+ multiple blobs with the same name can be differentiated. |
+ """ |
+ key = key + '.' + str(version) |
+ filename = files.blobstore.create() |
+ with files.open(filename, 'a') as f: |
+ f.write(blob) |
+ files.finalize(filename) |
+ blob_key = files.blobstore.get_blob_key(filename) |
+ self._datastore.Set(key, blob_key, datastore.DATASTORE_BLOBSTORE) |
+ |
+ def Get(self, key, version): |
+ """Get a blob with version |version|. |
+ """ |
+ key = key + '.' + str(version) |
+ blob_key = self._datastore.Get(key, datastore.DATASTORE_BLOBSTORE) |
+ if blob_key is None: |
+ return None |
+ blob_reader = blobstore.BlobReader(blob_key) |
+ return blob_reader.read() |
+ |
+ def Delete(self, key, version): |
+ """Delete the blob with version |version| if it is found. |
+ """ |
+ key = key + '.' + str(version) |
+ blob_key = self._datastore.Get(key, datastore.DATASTORE_BLOBSTORE) |
+ if blob_key is None: |
+ return |
+ blobstore.delete(blob_key) |