<s> import ConfigParser <EOL> import os <EOL> from gnippy . errors import ConfigFileNotFoundException , IncompleteConfigurationException <EOL> def get_default_config_file_path ( ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> os . path . expanduser ( '<STR_LIT>' ) <EOL> expanduser = os . path . expanduser <EOL> except ( AttributeError , ImportError ) : <EOL> expanduser = ( lambda x : x ) <EOL> return os . path . join ( expanduser ( "<STR_LIT>" ) , "<STR_LIT>" ) <EOL> def get_config ( config_file_path = None ) : <EOL> """<STR_LIT>""" <EOL> if not os . path . isfile ( config_file_path ) : <EOL> raise ConfigFileNotFoundException ( "<STR_LIT>" % config_file_path ) <EOL> result = { } <EOL> parser = ConfigParser . SafeConfigParser ( ) <EOL> parser . read ( config_file_path ) <EOL> options = { <EOL> "<STR_LIT>" : ( '<STR_LIT:username>' , '<STR_LIT:password>' ) , <EOL> "<STR_LIT>" : ( "<STR_LIT:url>" , ) <EOL> } <EOL> for section in options : <EOL> keys = options [ section ] <EOL> values = { } <EOL> for key in keys : <EOL> try : <EOL> values [ key ] = parser . get ( section , key ) <EOL> except ConfigParser . NoOptionError : <EOL> values [ key ] = None <EOL> except ConfigParser . NoSectionError : <EOL> values [ key ] = None <EOL> result [ section ] = values <EOL> return result <EOL> def resolve ( kwarg_dict ) : <EOL> """<STR_LIT>""" <EOL> conf = { } <EOL> if "<STR_LIT>" in kwarg_dict : <EOL> conf [ '<STR_LIT>' ] = kwarg_dict [ '<STR_LIT>' ] <EOL> if "<STR_LIT:url>" in kwarg_dict : <EOL> conf [ '<STR_LIT:url>' ] = kwarg_dict [ '<STR_LIT:url>' ] <EOL> if "<STR_LIT>" not in conf or "<STR_LIT:url>" not in conf : <EOL> if "<STR_LIT>" in kwarg_dict : <EOL> file_conf = get_config ( config_file_path = kwarg_dict [ '<STR_LIT>' ] ) <EOL> else : <EOL> file_conf = get_config ( config_file_path = get_default_config_file_path ( ) ) <EOL> if "<STR_LIT>" not in conf : <EOL> creds = file_conf [ '<STR_LIT>' ] <EOL> if creds [ '<STR_LIT:username>' ] and creds [ '<STR_LIT:password>' ] : <EOL> conf [ '<STR_LIT>' ] = ( creds [ '<STR_LIT:username>' ] , creds [ '<STR_LIT:password>' ] ) <EOL> else : <EOL> raise IncompleteConfigurationException ( "<STR_LIT>" + "<STR_LIT>" ) <EOL> if "<STR_LIT:url>" not in conf : <EOL> if file_conf [ '<STR_LIT>' ] [ '<STR_LIT:url>' ] : <EOL> conf [ '<STR_LIT:url>' ] = file_conf [ '<STR_LIT>' ] [ '<STR_LIT:url>' ] <EOL> else : <EOL> raise IncompleteConfigurationException ( "<STR_LIT>" ) <EOL> return conf </s>
