Chromium Code Reviews| Index: chrome/common/extensions/docs/server2/blob_reference_store.py |
| diff --git a/chrome/common/extensions/docs/server2/blob_reference_store.py b/chrome/common/extensions/docs/server2/blob_reference_store.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..201c13c5835ce2d2f1e64781dc98b3640a3b382d |
| --- /dev/null |
| +++ b/chrome/common/extensions/docs/server2/blob_reference_store.py |
| @@ -0,0 +1,39 @@ |
| +# 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. |
| + |
| +from appengine_wrappers import db |
| +from appengine_wrappers import BlobReferenceProperty |
| + |
| +BLOBREFERENCE_BLOBSTORE = 'BlobReferenceBlobstore' |
|
not at google - send to devlin
2012/08/10 06:02:18
should be BLOB_REFERENCE_BLOBSTORE really...
cduvall
2012/08/10 21:17:47
Done.
|
| + |
| +class _Model(db.Model): |
| + key_ = db.StringProperty() |
| + value = BlobReferenceProperty() |
| + |
| +class BlobReferenceStore(object): |
| + """A wrapper around the datastore API that can store blob keys. |
| + """ |
| + def __init__(self, branch): |
| + self._branch = branch |
| + |
| + def _Query(self, namespace, key): |
| + return _Model.gql('WHERE key_ = :1', self._MakeKey(namespace, key)).get() |
| + |
| + def _MakeKey(self, namespace, key): |
| + return '.'.join([self._branch, namespace, key]) |
| + |
| + def Set(self, namespace, key, value): |
| + _Model(key_=self._MakeKey(namespace, key), value=value).put() |
| + |
| + def Get(self, namespace, key): |
| + result = self._Query(namespace, key) |
| + if not result: |
| + return None |
| + return result.value |
| + |
| + def Delete(self, namespace, key): |
| + result = self._Query(namespace, key) |
| + if not result: |
| + return |
| + result.delete() |