From 92313c9e9d37733feb79d1b1c825178f48d6c69c Mon Sep 17 00:00:00 2001 From: Stanislav Laznicka Date: May 02 2017 15:33:25 +0000 Subject: Remove the cachedproperty class The cachedproperty class was used in one special use-case where it only caused issues. Let's get rid of it. https://pagure.io/freeipa/issue/6878 Reviewed-By: Martin Basti Reviewed-By: Christian Heimes --- diff --git a/ipalib/util.py b/ipalib/util.py index e9d4105..8973a19 100644 --- a/ipalib/util.py +++ b/ipalib/util.py @@ -34,7 +34,6 @@ import dns import encodings import sys import ssl -from weakref import WeakKeyDictionary import netaddr from dns import resolver, rdatatype @@ -492,39 +491,6 @@ def remove_sshpubkey_from_output_list_post(context, entries): delattr(context, 'ipasshpubkey_added') -class cachedproperty(object): - """ - A property-like attribute that caches the return value of a method call. - - When the attribute is first read, the method is called and its return - value is saved and returned. On subsequent reads, the saved value is - returned. - - Typical usage: - class C(object): - @cachedproperty - def attr(self): - return 'value' - """ - __slots__ = ('getter', 'store') - - def __init__(self, getter): - self.getter = getter - self.store = WeakKeyDictionary() - - def __get__(self, obj, cls): - if obj is None: - return None - if obj not in self.store: - self.store[obj] = self.getter(obj) - return self.store[obj] - - def __set__(self, obj, value): - raise AttributeError("can't set attribute") - - def __delete__(self, obj): - raise AttributeError("can't delete attribute") - # regexp matching signed floating point number (group 1) followed by # optional whitespace followed by time unit, e.g. day, hour (group 7) time_duration_re = re.compile(r'([-+]?((\d+)|(\d+\.\d+)|(\.\d+)|(\d+\.)))\s*([a-z]+)', re.IGNORECASE)