summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2010-02-25 16:44:22 +0100
committerhut <hut@lavabit.com>2010-02-25 20:37:11 +0100
commit24cd97b78d90b3b7311381d1c4bab7160d14604f (patch)
treefb26b1f2f704d38c38a3c57c22e87f48aedc48c9
parent7a268c8be8896d3ec71952a6fd261012e39c1c1a (diff)
downloadranger-24cd97b78d90b3b7311381d1c4bab7160d14604f.tar.gz
settings: check the type of options
-rw-r--r--ranger/shared/settings.py46
1 files changed, 35 insertions, 11 deletions
diff --git a/ranger/shared/settings.py b/ranger/shared/settings.py
index 152dfbd1..580c258e 100644
--- a/ranger/shared/settings.py
+++ b/ranger/shared/settings.py
@@ -12,19 +12,27 @@
 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
-ALLOWED_SETTINGS = """
-show_hidden scroll_offset show_cursor
-directories_first sort reverse
-preview_files max_history_size colorscheme
-collapse_preview update_title
-hidden_filter flushinput
-autosave_bookmarks
-max_filesize_for_preview
-""".split()
+from ranger.ext.openstruct import OpenStruct
 
-# -- globalize the settings --
+ALLOWED_SETTINGS = {
+	'show_hidden': bool,
+	'show_cursor': bool,
+	'autosave_bookmarks': bool,
+	'collapse_preview': bool,
+	'sort': str,
+	'reverse': bool,
+	'directories_first': bool,
+	'update_title': bool,
+	'max_filesize_for_preview': (int, type(None)),
+	'max_history_size': (int, type(None)),
+	'scroll_offset': int,
+	'preview_files': bool,
+	'flushinput': bool,
+	'colorscheme': object,
+	'hidden_filter': lambda x: isinstance(x, str) or hasattr(x, 'match'),
+}
 
-from ranger.ext.openstruct import OpenStruct
+# -- globalize the settings --
 class SettingsAware(object):
 	settings = OpenStruct()
 
@@ -45,6 +53,8 @@ class SettingsAware(object):
 		except ImportError:
 			pass
 
+		assert check_option_types(options)
+
 		try:
 			import apps
 		except ImportError:
@@ -81,3 +91,17 @@ class SettingsAware(object):
 
 		SettingsAware.settings.keys = keys
 		SettingsAware.settings.apps = apps
+
+
+def check_option_types(opt):
+	import inspect
+	for name, typ in ALLOWED_SETTINGS.items():
+		optvalue = getattr(opt, name)
+		if inspect.isfunction(typ):
+			assert typ(optvalue), \
+				"The option `" + name + "' has an incorrect type!"
+		else:
+			assert isinstance(optvalue, typ), \
+				"The option `" + name + "' has an incorrect type!"\
+				" Expected " + str(typ) + "!"
+	return True
ious revision' href='/akkartik/mu/blame/html/021arithmetic.cc.html?h=hlt&id=9864bdd0792b697d7b03e692ba7f82cf5669c41c'>^
672e3e50 ^
90560d71 ^

90560d71 ^




65361948 ^



672e3e50 ^




9570363a ^
672e3e50 ^
672e3e50 ^



9570363a ^

65361948 ^
672e3e50 ^
672e3e50 ^

65361948 ^

9570363a ^
65361948 ^


672e3e50 ^


d5d908dd ^
672e3e50 ^
90560d71 ^

9542bb11 ^


90560d71 ^









65361948 ^



672e3e50 ^




9570363a ^
672e3e50 ^
672e3e50 ^



9570363a ^

65361948 ^
672e3e50 ^
672e3e50 ^

65361948 ^

9570363a ^
65361948 ^


672e3e50 ^


d5d908dd ^
672e3e50 ^
90560d71 ^






65361948 ^



672e3e50 ^




9570363a ^
672e3e50 ^
672e3e50 ^



9570363a ^

65361948 ^
672e3e50 ^
672e3e50 ^

65361948 ^

9570363a ^
65361948 ^


672e3e50 ^


d5d908dd ^
672e3e50 ^
90560d71 ^

9542bb11 ^


90560d71 ^









65361948 ^



672e3e50 ^




9570363a ^
672e3e50 ^
672e3e50 ^



9570363a ^

65361948 ^
672e3e50 ^
672e3e50 ^

65361948 ^

9570363a ^
65361948 ^




672e3e50 ^


d5d908dd ^
672e3e50 ^
90560d71 ^
4fe9f5e8 ^
90560d71 ^

9542bb11 ^

90560d71 ^





65361948 ^


672e3e50 ^




9570363a ^
672e3e50 ^
672e3e50 ^
672e3e50 ^



9570363a ^

65361948 ^
672e3e50 ^
672e3e50 ^
672e3e50 ^
65361948 ^



9570363a ^
65361948 ^

c5ffb6e1 ^

90560d71 ^
c5ffb6e1 ^

90560d71 ^
c5ffb6e1 ^

672e3e50 ^



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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266