Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / common / extensions / docs / server2 / datastore_models.py
blobc05a0b9151857cde76b48e5bf29534ec13f686a8
1 # Copyright 2013 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.
5 import cPickle
6 import traceback
8 from appengine_wrappers import db
10 # A collection of the data store models used throughout the server.
11 # These values are global within datastore.
13 class PersistentObjectStoreItem(db.Model):
14 pickled_value = db.BlobProperty()
16 @classmethod
17 def CreateKey(cls, namespace, key):
18 path = '%s/%s' % (namespace, key)
19 try:
20 return db.Key.from_path(cls.__name__, path)
21 except Exception:
22 # Probably AppEngine's BadValueError for the name being too long, but
23 # it's not documented which errors can actually be thrown here, so catch
24 # 'em all.
25 raise ValueError(
26 'Exception thrown when trying to create db.Key from path %s: %s' % (
27 path, traceback.format_exc()))
29 @classmethod
30 def CreateItem(cls, namespace, key, value):
31 return PersistentObjectStoreItem(key=cls.CreateKey(namespace, key),
32 pickled_value=cPickle.dumps(value))
34 def GetValue(self):
35 return cPickle.loads(self.pickled_value)