summary refs log tree commit diff stats
path: root/ranger
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2010-05-22 16:38:24 +0200
committerhut <hut@lavabit.com>2010-05-22 16:38:24 +0200
commit7f906f5f9cf77bd24ac6294c964a3fdb85988033 (patch)
tree579358bb587dffab44f3440f173c0b5dbb79344e /ranger
parentb357f51526a9a4ab276f4376f16f48af670f0664 (diff)
downloadranger-7f906f5f9cf77bd24ac6294c964a3fdb85988033.tar.gz
Added ranger.ext.lazy_property
Diffstat (limited to 'ranger')
-rw-r--r--ranger/ext/lazy_property.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/ranger/ext/lazy_property.py b/ranger/ext/lazy_property.py
new file mode 100644
index 00000000..6f894179
--- /dev/null
+++ b/ranger/ext/lazy_property.py
@@ -0,0 +1,25 @@
+# From http://blog.pythonisito.com/2008/08/lazy-descriptors.html
+
+class lazy_property(object):
+	"""
+	A @property-like decorator with lazy evaluation
+
+	Example:
+	class Foo:
+		@lazy_property
+			def bar(self):
+				result = [...]
+				return result
+	"""
+
+	def __init__(self, method):
+		self._method = method
+		self.__name__ = method.__name__
+		self.__doc__ = method.__doc__
+
+	def __get__(self, obj, cls=None):
+		if obj is None:  # to fix issues with pydoc
+			return None
+		result = self._method(obj)
+		obj.__dict__[self.__name__] = result
+		return result
29028631 ^
f8f6f7f9 ^





















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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85