/usr/lib/python3/dist-packages/reprotest/utils.py is in reprotest 0.7.7.
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 | # Licensed under the GPL: https://www.gnu.org/licenses/gpl-3.0.en.html
# For details: reprotest/debian/copyright
import collections
import functools
class AttributeFunctor(collections.namedtuple('_AttributeFunctor', 'x f')):
"""Functor for applying functions to attributes of namedtuples."""
def __getattr__(self, name):
return lambda *args: self.x._replace(**{
name: self.f(getattr(self.x, name), *args)
})
class AttributeReplacer(object):
"""Proxy for setting attributes deeply on trees of namedtuples."""
__slots__ = ['top', 'attrs']
def __init__(self, top, attrs):
self.top = top
self.attrs = attrs
def rgetattr(self, attrs):
return functools.reduce(getattr, attrs, self.top)
def __getattr__(self, name):
attr = self.rgetattr(self.attrs + [name])
return self.__class__(self.top, self.attrs + [name])
def __call__(self, *args, **kwargs):
f = self.rgetattr(self.attrs)
if not callable(f):
raise TypeError("not callable: %s of %s" % (self.attrs, self.top))
result = f(*args, **kwargs)
parents = [(self.rgetattr(self.attrs[:i]), self.attrs[i])
for i in range(len(self.attrs))]
return functools.reduce(
lambda v, p: p[0]._replace(**{p[1]: v}),
reversed(parents[:-1]), result)
|