mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-04-27 14:57:41 +00:00
Copy cached_property from python-webuntis
This commit is contained in:
parent
c2a50d76a4
commit
3cd216687e
1 changed files with 10 additions and 15 deletions
|
|
@ -142,22 +142,17 @@ def checkfile(path, create=False):
|
||||||
|
|
||||||
|
|
||||||
class cached_property(object):
|
class cached_property(object):
|
||||||
|
'''A read-only @property that is only evaluated once. Only usable on class
|
||||||
|
instances' methods.
|
||||||
'''
|
'''
|
||||||
Copied from Werkzeug.
|
def __init__(self, fget, doc=None):
|
||||||
Copyright 2007-2014 Armin Ronacher
|
self.__name__ = fget.__name__
|
||||||
'''
|
|
||||||
|
|
||||||
def __init__(self, func, name=None, doc=None):
|
|
||||||
self.__name__ = name or func.__name__
|
|
||||||
self.__module__ = func.__module__
|
self.__module__ = func.__module__
|
||||||
self.__doc__ = doc or func.__doc__
|
self.__doc__ = doc or fget.__doc__
|
||||||
self.func = func
|
self.fget = fget
|
||||||
|
|
||||||
def __get__(self, obj, type=None):
|
def __get__(self, obj, cls):
|
||||||
if obj is None:
|
if obj is None: # pragma: no cover
|
||||||
return self
|
return self
|
||||||
value = obj.__dict__.get(self.__name__, _missing)
|
obj.__dict__[self.__name__] = result = self.fget(obj)
|
||||||
if value is _missing:
|
return result
|
||||||
value = self.func(obj)
|
|
||||||
obj.__dict__[self.__name__] = value
|
|
||||||
return value
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue