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. 4 5 from appengine_wrappers import db 6 import cPickle 7 8 # A collection of the data store models used throughout the server. 9 # These values are global within datastore. 10 11 class PersistentObjectStoreItem(db.Model): 12 pickled_value = db.BlobProperty() 13 14 @classmethod 15 def CreateKey(cls, namespace, key): 16 return db.Key.from_path(cls.__name__, '%s/%s' % (namespace, key)) 17 18 @classmethod 19 def CreateItem(cls, namespace, key, value): 20 return PersistentObjectStoreItem(key=cls.CreateKey(namespace, key), 21 pickled_value=cPickle.dumps(value)) 22 23 def GetValue(self): 24 return cPickle.loads(self.pickled_value) 25