/usr/lib/python3/dist-packages/partd/encode.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 | from .core import Interface
from .file import File
from toolz import valmap
from .utils import frame, framesplit
class Encode(Interface):
def __init__(self, encode, decode, join, partd=None):
if not partd or isinstance(partd, str):
partd = File(partd)
self.partd = partd
self.encode = encode
self.decode = decode
self.join = join
Interface.__init__(self)
def __getstate__(self):
return self.__dict__
__setstate__ = Interface.__setstate__
def append(self, data, **kwargs):
data = valmap(self.encode, data)
data = valmap(frame, data)
self.partd.append(data, **kwargs)
def _get(self, keys, **kwargs):
raw = self.partd._get(keys, **kwargs)
return [self.join([self.decode(frame) for frame in framesplit(chunk)])
for chunk in raw]
def delete(self, keys, **kwargs):
return self.partd.delete(keys, **kwargs)
def _iset(self, key, value, **kwargs):
return self.partd.iset(key, frame(self.encode(value)), **kwargs)
def drop(self):
return self.partd.drop()
@property
def lock(self):
return self.partd.lock
def __exit__(self, *args):
self.drop()
self.partd.__exit__(*args)
|