source: fedd/federation/config_parser.py @ bc24428

version-1.30
Last change on this file since bc24428 was 5d3f239, checked in by Ted Faber <faber@…>, 16 years ago

change package name to avoid conflicts with fedd on install

  • Property mode set to 100755
File size: 1.1 KB
RevLine 
[0a20ef8]1#!/usr/local/bin/python
2
3from ConfigParser import *
4
[ec4fb42]5class config_parser(SafeConfigParser):
[0a20ef8]6    """
7    A SafeConfig parser with a more forgiving get attribute
8    """
9
10    def safe_get(self, sect, opt, method, default=None):
11        """
12        If the option is present, return it, otherwise the default.
13        """
14        if self.has_option(sect, opt): return method(self, sect, opt)
15        else: return default
16
17    def get(self, sect, opt, default=None):
18        """
19        This returns the requested option or a given default.
20
21        It's more like getattr than get.
22        """
23
24        return self.safe_get(sect, opt, SafeConfigParser.get, default)
25
26    def getint(self, sect, opt, default=0):
27        """
28        Returns the selected option as an int or a default.
29        """
30
31        return self.safe_get(sect, opt, SafeConfigParser.getint, default)
32
33    def getfloat(self, sect, opt, default=0.0):
34        """
35        Returns the selected option as an int or a default.
36        """
37
38        return self.safe_get(sect, opt, SafeConfigParser.getfloat, default)
39
40    def getboolean(self, sect, opt, default=False):
41        """
42        Returns the selected option as a boolean or a default.
43        """
44
45        return self.safe_get(sect, opt, SafeConfigParser.getboolean, default)
Note: See TracBrowser for help on using the repository browser.