<s> import logging <EOL> import os <EOL> from six . moves . configparser import SafeConfigParser <EOL> FILE_PATH = os . path . dirname ( os . path . abspath ( __file__ ) ) <EOL> CONFIG_FILE = [ <EOL> os . path . join ( os . path . expanduser ( '<STR_LIT>' ) , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> os . path . join ( os . sep , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) , <EOL> os . path . normpath ( os . path . join ( FILE_PATH , '<STR_LIT>' ) ) , <EOL> os . path . normpath ( os . path . join ( FILE_PATH , '<STR_LIT>' ) ) ] <EOL> class ConfigHelper ( object ) : <EOL> NONE_VALUE = '<STR_LIT:None>' <EOL> DEFAULT_HOST = "<STR_LIT:127.0.0.1>" <EOL> DEFAULT_PORT = <NUM_LIT> <EOL> DEFAULT_CERTFILE = os . path . normpath ( os . path . join ( <EOL> FILE_PATH , '<STR_LIT>' ) ) <EOL> DEFAULT_KEYFILE = os . path . normpath ( os . path . join ( <EOL> FILE_PATH , '<STR_LIT>' ) ) <EOL> DEFAULT_CA_CERTS = os . path . normpath ( os . path . join ( <EOL> FILE_PATH , '<STR_LIT>' ) ) <EOL> DEFAULT_SSL_VERSION = '<STR_LIT>' <EOL> DEFAULT_USERNAME = None <EOL> DEFAULT_PASSWORD = None <EOL> DEFAULT_TIMEOUT = <NUM_LIT:30> <EOL> def __init__ ( self ) : <EOL> self . logger = logging . getLogger ( __name__ ) <EOL> self . conf = SafeConfigParser ( ) <EOL> if self . conf . read ( CONFIG_FILE ) : <EOL> self . logger . debug ( "<STR_LIT>" . format ( CONFIG_FILE ) ) <EOL> else : <EOL> self . logger . warning ( <EOL> "<STR_LIT>" . format ( CONFIG_FILE ) ) <EOL> def get_valid_value ( self , direct_value , config_section , <EOL> config_option_name , default_value ) : <EOL> """<STR_LIT>""" <EOL> ARG_MSG = "<STR_LIT>" <EOL> CONF_MSG = "<STR_LIT>" <EOL> DEFAULT_MSG = "<STR_LIT>" <EOL> if direct_value : <EOL> return_value = direct_value <EOL> self . logger . debug ( ARG_MSG . format ( direct_value , config_option_name ) ) <EOL> else : <EOL> try : <EOL> return_value = self . conf . get ( config_section , <EOL> config_option_name ) <EOL> self . logger . debug ( CONF_MSG . format ( return_value , <EOL> CONFIG_FILE , <EOL> config_option_name ) ) <EOL> except : <EOL> return_value = default_value <EOL> self . logger . debug ( DEFAULT_MSG . format ( default_value , <EOL> config_option_name ) ) <EOL> if return_value == self . NONE_VALUE : <EOL> return None <EOL> else : <EOL> return return_value </s>
