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

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

Issue 15087006: Docserver: there is only one. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: epic rebase Created 7 years, 5 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
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 from appengine_wrappers import db 5 from appengine_wrappers import db
6 from appengine_wrappers import BlobReferenceProperty 6 from appengine_wrappers import BlobReferenceProperty
7 7
8 BLOB_REFERENCE_BLOBSTORE = 'BlobReferenceBlobstore' 8 BLOB_REFERENCE_BLOBSTORE = 'BlobReferenceBlobstore'
9 9
10 class _Model(db.Model): 10 class _Model(db.Model):
11 key_ = db.StringProperty() 11 key_ = db.StringProperty()
12 value = BlobReferenceProperty() 12 value = BlobReferenceProperty()
13 13
14 class BlobReferenceStore(object): 14 class BlobReferenceStore(object):
15 """A wrapper around the datastore API that can store blob keys. 15 """A wrapper around the datastore API that can store blob keys.
16 """ 16 """
17 def __init__(self, branch):
18 self._branch = branch
19
20 def _Query(self, namespace, key): 17 def _Query(self, namespace, key):
21 return _Model.gql('WHERE key_ = :1', self._MakeKey(namespace, key)).get() 18 return _Model.gql('WHERE key_ = :1', self._MakeKey(namespace, key)).get()
22 19
23 def _MakeKey(self, namespace, key): 20 def _MakeKey(self, namespace, key):
24 return '.'.join([self._branch, namespace, key]) 21 return '.'.join((namespace, key))
25 22
26 def Set(self, namespace, key, value): 23 def Set(self, namespace, key, value):
27 _Model(key_=self._MakeKey(namespace, key), value=value).put() 24 _Model(key_=self._MakeKey(namespace, key), value=value).put()
28 25
29 def Get(self, namespace, key): 26 def Get(self, namespace, key):
30 result = self._Query(namespace, key) 27 result = self._Query(namespace, key)
31 if not result: 28 if not result:
32 return None 29 return None
33 return result.value 30 return result.value
34 31
35 def Delete(self, namespace, key): 32 def Delete(self, namespace, key):
36 result = self._Query(namespace, key) 33 result = self._Query(namespace, key)
37 if not result: 34 if not result:
38 return None 35 return None
39 blob_key = result.value 36 blob_key = result.value
40 result.delete() 37 result.delete()
41 return blob_key 38 return blob_key
OLDNEW
« no previous file with comments | « chrome/common/extensions/docs/server2/appengine_blobstore.py ('k') | chrome/common/extensions/docs/server2/branch_utility.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698