OLD | NEW |
(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 from appengine_wrappers import db |
| 6 from appengine_wrappers import BlobReferenceProperty |
| 7 |
| 8 BLOB_REFERENCE_BLOBSTORE = 'BlobReferenceBlobstore' |
| 9 |
| 10 class _Model(db.Model): |
| 11 key_ = db.StringProperty() |
| 12 value = BlobReferenceProperty() |
| 13 |
| 14 class BlobReferenceStore(object): |
| 15 """A wrapper around the datastore API that can store blob keys. |
| 16 """ |
| 17 def __init__(self, branch): |
| 18 self._branch = branch |
| 19 |
| 20 def _Query(self, namespace, key): |
| 21 return _Model.gql('WHERE key_ = :1', self._MakeKey(namespace, key)).get() |
| 22 |
| 23 def _MakeKey(self, namespace, key): |
| 24 return '.'.join([self._branch, namespace, key]) |
| 25 |
| 26 def Set(self, namespace, key, value): |
| 27 _Model(key_=self._MakeKey(namespace, key), value=value).put() |
| 28 |
| 29 def Get(self, namespace, key): |
| 30 result = self._Query(namespace, key) |
| 31 if not result: |
| 32 return None |
| 33 return result.value |
| 34 |
| 35 def Delete(self, namespace, key): |
| 36 result = self._Query(namespace, key) |
| 37 if not result: |
| 38 return None |
| 39 blob_key = result.value |
| 40 result.delete() |
| 41 return blob_key |
OLD | NEW |