hch
2019-02-27 f473d3c18a3aa6c4c0cd98f9396e488676424f4c
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
#!/usr/bin/python
# -*- coding: GBK -*-
#
##@package
#
# @todo: 
#
# @author: Alee
# @date 2018-6-5 ÏÂÎç08:20:53
# @version 1.0
#
# @note: 
#
#---------------------------------------------------------------------
import ConfigParser
 
 
class ReadConfig():
    def __init__(self, filePath):
        self.__config = ConfigParser.ConfigParser()
        self.__config.read(filePath)
 
    def GetValue(self, section, option, default=None, isThrowException=False):
        try:
            return self.__config.get(section, option);
        except Exception, err:
            if not isThrowException:
                return default;
            raise Exception, "Error:ÅäÖÃÎÊÌâ,%s"%err;
 
    get = GetValue;
 
    def GetInt(self, section, option, default = 0, isThrowException=False):
        try:
            return self.__config.getint(section, option);
        except Exception, err:
            if not isThrowException:
                return default;
            raise Exception, "Error:ÅäÖÃÎÊÌâ,%s"%err;
 
    getint = GetInt;
 
    def GetBoolean(self, section, option, default = False):
        try:
            return self.__config.getboolean(section, option);
        except ValueError:
            default = str(default).lower();
            if default not in self.__config._boolean_states:
                return False;
            else:
                return self.__config._boolean_states[default];
 
    getboolean = GetBoolean;
 
    def HasSection(self, section):
        return self.__config.has_section(section)
 
    def HasOption(self, section, option):
        return self.__config.has_option(section, option)
    
 
#===============================================================================
# ## ¶ÁÈ¡EvalµÄÖµ
# def GetEvalConfig(path):
#    with open(path, "r") as file:
#        content = file.read()
#        try:
#            value = eval(content)
#        except:
#            value = None
#    
#    return value
#===============================================================================