OLD | NEW |
| (Empty) |
1 # -*- coding: ascii -*- | |
2 # | |
3 # Copyright 2007, 2008, 2009, 2010, 2011 | |
4 # Andr\xe9 Malo or his licensors, as applicable | |
5 # | |
6 # Licensed under the Apache License, Version 2.0 (the "License"); | |
7 # you may not use this file except in compliance with the License. | |
8 # You may obtain a copy of the License at | |
9 # | |
10 # http://www.apache.org/licenses/LICENSE-2.0 | |
11 # | |
12 # Unless required by applicable law or agreed to in writing, software | |
13 # distributed under the License is distributed on an "AS IS" BASIS, | |
14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
15 # See the License for the specific language governing permissions and | |
16 # limitations under the License. | |
17 """ | |
18 ================= | |
19 Setup utilities | |
20 ================= | |
21 | |
22 Setup utilities. | |
23 """ | |
24 __author__ = "Andr\xe9 Malo" | |
25 __docformat__ = "restructuredtext en" | |
26 | |
27 from distutils import util as _util | |
28 try: | |
29 from configparser import SafeConfigParser | |
30 except ImportError: | |
31 import configparser as _config_parser | |
32 class SafeConfigParser(_config_parser.ConfigParser): | |
33 """ Safe config parser """ | |
34 def _interpolate(self, section, option, rawval, vars): | |
35 return rawval | |
36 | |
37 def items(self, section): | |
38 return [(key, self.get(section, key)) | |
39 for key in self.options(section) | |
40 ] | |
41 | |
42 | |
43 def humanbool(name, value): | |
44 """ | |
45 Determine human boolean value | |
46 | |
47 :Parameters: | |
48 `name` : ``str`` | |
49 The config key (used for error message) | |
50 | |
51 `value` : ``str`` | |
52 The config value | |
53 | |
54 :Return: The boolean value | |
55 :Rtype: ``bool`` | |
56 | |
57 :Exceptions: | |
58 - `ValueError` : The value could not be recognized | |
59 """ | |
60 try: | |
61 return _util.strtobool(str(value).strip().lower() or 'no') | |
62 except ValueError: | |
63 raise ValueError("Unrecognized config value: %s = %s" % (name, value)) | |
OLD | NEW |