MCPcopy
hub / github.com/pimutils/vdirsyncer / MemoryStorage

Class MemoryStorage

vdirsyncer/storage/memory.py:12–73  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10
11
12class MemoryStorage(Storage):
13
14 storage_name = 'memory'
15
16 '''
17 Saves data in RAM, only useful for testing.
18 '''
19
20 def __init__(self, fileext='', **kwargs):
21 if kwargs.get('collection') is not None:
22 raise exceptions.UserError('MemoryStorage does not support '
23 'collections.')
24 self.items = {} # href => (etag, item)
25 self.metadata = {}
26 self.fileext = fileext
27 super().__init__(**kwargs)
28
29 def _get_href(self, item):
30 return item.ident + self.fileext
31
32 def list(self):
33 for href, (etag, _item) in self.items.items():
34 yield href, etag
35
36 def get(self, href):
37 etag, item = self.items[href]
38 return item, etag
39
40 def has(self, href):
41 return href in self.items
42
43 def upload(self, item):
44 href = self._get_href(item)
45 if href in self.items:
46 raise exceptions.AlreadyExistingError(existing_href=href)
47 etag = _random_string()
48 self.items[href] = (etag, item)
49 return href, etag
50
51 def update(self, href, item, etag):
52 if href not in self.items:
53 raise exceptions.NotFoundError(href)
54 actual_etag, _ = self.items[href]
55 if etag != actual_etag:
56 raise exceptions.WrongEtagError(etag, actual_etag)
57
58 new_etag = _random_string()
59 self.items[href] = (new_etag, item)
60 return new_etag
61
62 def delete(self, href, etag):
63 if not self.has(href):
64 raise exceptions.NotFoundError(href)
65 if etag != self.items[href][0]:
66 raise exceptions.WrongEtagError(etag)
67 del self.items[href]
68
69 def get_meta(self, key):

Callers 15

test_irrelevant_statusFunction · 0.90
test_basicFunction · 0.90
conflict_stateFunction · 0.90
test_conflict_x_winsFunction · 0.90
_get_storageFunction · 0.90
test_repair_uidsFunction · 0.90
test_repair_unsafe_uidsFunction · 0.90
test_irrelevant_statusFunction · 0.90
test_missing_statusFunction · 0.90

Calls

no outgoing calls

Tested by 15

test_irrelevant_statusFunction · 0.72
test_basicFunction · 0.72
conflict_stateFunction · 0.72
test_conflict_x_winsFunction · 0.72
_get_storageFunction · 0.72
test_repair_uidsFunction · 0.72
test_repair_unsafe_uidsFunction · 0.72
test_irrelevant_statusFunction · 0.72
test_missing_statusFunction · 0.72