/usr/lib/python3/dist-packages/ptk/utils.py is in python3-ptk 1.3.1-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 | # -*- coding: UTF-8 -*-
# (c) Jérôme Laheurte 2015
# See LICENSE.txt
"""
Miscellaneous utilities.
"""
import functools
def memoize(func):
"""
Memoization of an arbitrary function
"""
cache = dict()
@functools.wraps(func)
def _wrapper(*args):
if args not in cache:
cache[args] = func(*args)
return cache[args]
return _wrapper
class Singleton(type):
"""
Singleton metaclass
"""
def __new__(metacls, name, bases, attrs):
# pylint: disable=C0103
cls = type.__new__(metacls, name, bases, attrs)
cls.__eq__ = lambda self, other: other is self
cls.__lt__ = lambda self, other: not other is self
cls.__copy__ = lambda self: self
cls.__deepcopy__ = lambda self, memo: self
cls.__repr__ = lambda self: self.__reprval__
cls.__len__ = lambda self: len(self.__reprval__)
cls.__hash__ = lambda self: hash(id(self))
return functools.total_ordering(cls)()
def callbackByName(funcName):
def _wrapper(instance, *args, **kwargs):
return getattr(instance, funcName)(*args, **kwargs)
return _wrapper
|