/usr/lib/python3/dist-packages/partd/dict.py is in python3-partd 0.3.7-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | from .core import Interface
from threading import Lock
class Dict(Interface):
def __init__(self):
self.lock = Lock()
self.data = dict()
Interface.__init__(self)
def __getstate__(self):
return {'data': self.data}
def __setstate__(self, state):
Interface.__setstate__(self, state)
Dict.__init__(self)
self.data = state['data']
def append(self, data, lock=True, **kwargs):
if lock: self.lock.acquire()
try:
for k, v in data.items():
if k not in self.data:
self.data[k] = []
self.data[k].append(v)
finally:
if lock: self.lock.release()
def _get(self, keys, lock=True, **kwargs):
assert isinstance(keys, (list, tuple, set))
if lock:
self.lock.acquire()
try:
result = [b''.join(self.data.get(key, [])) for key in keys]
finally:
if lock:
self.lock.release()
return result
def _iset(self, key, value, lock=True):
""" Idempotent set """
if lock:
self.lock.acquire()
try:
self.data[key] = [value]
finally:
if lock:
self.lock.release()
def _delete(self, keys, lock=True):
if lock:
self.lock.acquire()
try:
for key in keys:
if key in self.data:
del self.data[key]
finally:
if lock:
self.lock.release()
def drop(self):
self._iset_seen.clear()
self.data.clear()
def __exit__(self, *args):
self.drop()
|