Package _setup :: Module util
[hide private]
[frames] | no frames]

Source Code for Module _setup.util

 1  # -*- coding: ascii -*- 
 2  # 
 3  # Copyright 2007, 2008, 2009, 2010 
 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__ = u"Andr\xe9 Malo" 
25  __docformat__ = "restructuredtext en" 
26   
27  from distutils import util as _util 
28  try: 
29      # pylint: disable = W0611 
30      from ConfigParser import SafeConfigParser 
31  except ImportError: 
32      import ConfigParser as _config_parser 
33 - class SafeConfigParser(_config_parser.ConfigParser):
34 """ Safe config parser """
35 - def _interpolate(self, section, option, rawval, vars):
36 # pylint: disable = W0622 37 return rawval
38
39 - def items(self, section):
40 # pylint: disable = W0221 41 return [(key, self.get(section, key)) 42 for key in self.options(section) 43 ]
44 45
46 -def humanbool(name, value):
47 """ 48 Determine human boolean value 49 50 :Parameters: 51 `name` : ``str`` 52 The config key (used for error message) 53 54 `value` : ``str`` 55 The config value 56 57 :Return: The boolean value 58 :Rtype: ``bool`` 59 60 :Exceptions: 61 - `ValueError` : The value could not be recognized 62 """ 63 try: 64 return _util.strtobool(str(value).strip().lower() or 'no') 65 except ValueError: 66 raise ValueError("Unrecognized config value: %s = %s" % (name, value))
67