1# Copyright 2015 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"""A wrapper for stored_object that separates internal and external.""" 6 7from dashboard import datastore_hooks 8from dashboard import stored_object 9 10 11def Get(key): 12 """Gets either the external or internal copy of an object.""" 13 namespaced_key = _NamespaceKey(key) 14 return stored_object.Get(namespaced_key) 15 16 17def GetExternal(key): 18 """Gets the external copy of a stored object.""" 19 namespaced_key = _NamespaceKey(key, datastore_hooks.EXTERNAL) 20 return stored_object.Get(namespaced_key) 21 22 23def Set(key, value): 24 """Sets the the value of a stored object, either external or internal.""" 25 namespaced_key = _NamespaceKey(key) 26 stored_object.Set(namespaced_key, value) 27 28 29def SetExternal(key, value): 30 """Sets the external copy of a stored object.""" 31 namespaced_key = _NamespaceKey(key, datastore_hooks.EXTERNAL) 32 stored_object.Set(namespaced_key, value) 33 34 35def Delete(key): 36 """Deletes both the internal and external copy of a stored object.""" 37 internal_key = _NamespaceKey(key, namespace=datastore_hooks.INTERNAL) 38 external_key = _NamespaceKey(key, namespace=datastore_hooks.EXTERNAL) 39 stored_object.Delete(internal_key) 40 stored_object.Delete(external_key) 41 42 43def _NamespaceKey(key, namespace=None): 44 """Prepends a namespace string to a key string.""" 45 if not namespace: 46 namespace = datastore_hooks.GetNamespace() 47 return '%s__%s' % (namespace, key) 48