Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(596)

Side by Side Diff: chrome/common/extensions/docs/server2/persistent_object_store_fake.py

Issue 1151283007: Docserver overhaul: Gitiles away from me. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove inform_users template to fix presubmit failure (it's now a redirect) Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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 import cPickle
6 import logging
7
8 from future import Future
9 from object_store import ObjectStore
10
11
12 class PersistentObjectStoreFake(ObjectStore):
13 '''Stores or retrieves data in memory. Not really persistent.
14 '''
15 # Static storage shared across all fake object stores.
16 DATA = {}
17
18 def __init__(self, namespace):
19 if namespace not in PersistentObjectStoreFake.DATA:
20 PersistentObjectStoreFake.DATA[namespace] = {}
21 self._data = PersistentObjectStoreFake.DATA[namespace]
22
23 def SetMulti(self, mapping):
24 self._data.update(mapping)
25 return Future(value=True)
26
27 def GetMulti(self, keys):
28 result = dict((key, self._data[key]) for key in keys if key in self._data)
29 return Future(value=result)
30
31 def DelMulti(self, keys):
32 for key in keys:
33 del self._data[key]
34
35 @classmethod
36 def LoadFromFile(cls, filename):
37 with open(filename, 'r') as f:
38 cls.DATA = cPickle.load(f)
39 for k, v in cls.DATA.iteritems():
40 cls.DATA[k] = cPickle.loads(v)
41 logging.info('Loaded %s keys from %s.' % (len(cls.DATA), filename))
42
43 @classmethod
44 def SaveToFile(cls, filename):
45 data = dict((k, cPickle.dumps(v)) for k, v, in cls.DATA.iteritems())
46 with open(filename, 'w') as f:
47 cPickle.dump(data, f)
48 logging.info('Saved %s keys to %s.' % (len(cls.DATA), filename))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698