Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(142)

Side by Side Diff: chrome/common/extensions/docs/server2/appengine_blobstore.py

Issue 10825067: Extensions Docs Server: Apps samples page (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: less is_apps and fixes Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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 blob_reference_store as datastore
6 from blob_reference_store import BlobReferenceStore
7 from appengine_wrappers import blobstore
8 from appengine_wrappers import files
9
10 BLOBSTORE_GITHUB = 'BlobstoreGithub'
11
12 class AppEngineBlobstore(object):
13 """A wrapper around the blobstore API, which stores the blob keys in
14 datastore.
15 """
16 def __init__(self):
17 self._datastore = BlobReferenceStore('blobstore')
18
19 def Set(self, key, blob, namespace):
20 """Add a blob to the blobstore. |version| is used as part of the key so
21 multiple blobs with the same name can be differentiated.
22 """
23 key = namespace + '.' + key
24 filename = files.blobstore.create()
25 with files.open(filename, 'a') as f:
26 f.write(blob)
27 files.finalize(filename)
28 blob_key = files.blobstore.get_blob_key(filename)
29 self._datastore.Set(datastore.BLOB_REFERENCE_BLOBSTORE, key, blob_key)
30
31 def Get(self, key, namespace):
32 """Get a blob with version |version|.
33 """
34 key = namespace + '.' + key
35 blob_key = self._datastore.Get(datastore.BLOB_REFERENCE_BLOBSTORE, key)
36 if blob_key is None:
37 return None
38 blob_reader = blobstore.BlobReader(blob_key)
39 return blob_reader.read()
40
41 def Delete(self, key, namespace):
42 """Delete the blob with version |version| if it is found.
43 """
44 key = namespace + '.' + key
45 blob_key = self._datastore.Delete(datastore.BLOB_REFERENCE_BLOBSTORE, key)
46 if blob_key is None:
47 return
48 blob_key.delete()
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698