@@ -26,16 +26,19 @@ class Config(RawConfigParser):
2626 'NONE' : None ,
2727 }
2828
29- def __init__ (self , configuration_file , defaults = None ):
29+ def __init__ (self , configuration_file = None , defaults = None ):
3030
3131 defaults = defaults or {}
3232
33+ self .configuration_path = None
34+
3335 RawConfigParser .__init__ (self )
34- f = codecs .open (configuration_file , 'r' , encoding = 'utf-8' )
35- self .read_file (f )
36- f .close ()
36+ if configuration_file is not None :
37+ f = codecs .open (configuration_file , 'r' , encoding = 'utf-8' )
38+ self .read_file (f )
39+ f .close ()
3740
38- self .configuration_path = os .path .dirname (configuration_file )
41+ self .configuration_path = os .path .dirname (configuration_file )
3942
4043 ''' set defaults '''
4144 self .hostname = 'localhost'
@@ -48,8 +51,8 @@ def __init__(self, configuration_file, defaults=None):
4851 self .cleansession = False
4952 self .protocol = 3
5053
51- self .logformat = '%(asctime)-15s %(levelname)-8s [%(name)-25s ] %(message)s'
52- self .logfile = None
54+ self .logformat = '%(asctime)-15s %(levelname)-8s [%(name)-26s ] %(message)s'
55+ self .logfile = "stream://sys.stderr"
5356 self .loglevel = 'DEBUG'
5457
5558 self .functions = None
@@ -170,7 +173,7 @@ def config(self, section):
170173 Cannot use config.items() because I want each value to be
171174 retrieved with g() as above '''
172175
173- d = None
176+ d = {}
174177 if self .has_section (section ):
175178 d = dict ((key , self .g (section , key ))
176179 for (key ) in self .options (section ) if key not in ['targets' , 'module' ])
@@ -183,7 +186,7 @@ def load_configuration(configfile=None, name='mqttwarn'):
183186 configfile = os .getenv (name .upper () + 'INI' , name + '.ini' )
184187
185188 if not os .path .exists (configfile ):
186- raise ValueError ('Configuration file "{}" does not exist' .format (configfile ))
189+ raise FileNotFoundError ('Configuration file "{}" does not exist' .format (configfile ))
187190
188191 defaults = {
189192 'clientid' : name ,
0 commit comments