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..cffd0a5488925638263759f7c9224da88cff1824 |
--- /dev/null |
+++ b/chrome/common/extensions/docs/server2/appengine_blobstore.py |
@@ -0,0 +1,48 @@ |
+# 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 blob_reference_store as datastore |
+from blob_reference_store import BlobReferenceStore |
+from appengine_wrappers import blobstore |
+from appengine_wrappers import files |
+ |
+BLOBSTORE_GITHUB = 'BlobstoreGithub' |
+ |
+class AppEngineBlobstore(object): |
+ """A wrapper around the blobstore API, which stores the blob keys in |
+ datastore. |
+ """ |
+ def __init__(self): |
+ self._datastore = BlobReferenceStore('blobstore') |
+ |
+ def Set(self, key, blob, namespace): |
+ """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 = namespace + '.' + key |
+ 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(datastore.BLOBREFERENCE_BLOBSTORE, key, blob_key) |
+ |
+ def Get(self, key, namespace): |
+ """Get a blob with version |version|. |
+ """ |
+ key = namespace + '.' + key |
+ blob_key = self._datastore.Get(datastore.BLOBREFERENCE_BLOBSTORE, key) |
+ if blob_key is None: |
+ return None |
+ blob_reader = blobstore.BlobReader(blob_key) |
+ return blob_reader.read() |
+ |
+ def Delete(self, key, namespace): |
+ """Delete the blob with version |version| if it is found. |
+ """ |
+ key = namespace + '.' + key |
+ blob_key = self._datastore.Get(datastore.BLOBREFERENCE_BLOBSTORE, key) |
not at google - send to devlin
2012/08/10 06:02:18
The way I read this, it's clearing the item from b
cduvall
2012/08/10 21:17:47
Done.
|
+ if blob_key is None: |
+ return |
+ blob_key.delete() |