<s> import os <EOL> import sys <EOL> import ConfigParser <EOL> import ssl <EOL> def ssl_settings ( host , config_file , env = os . environ ) : <EOL> """<STR_LIT>""" <EOL> configs = ConfigParser . SafeConfigParser ( ) <EOL> configs . read ( config_file ) <EOL> def get_option ( section , option ) : <EOL> try : <EOL> return configs . get ( section , option ) <EOL> except ConfigParser . Error : <EOL> return None <EOL> ssl_validate = env . get ( '<STR_LIT>' ) <EOL> if ssl_validate is None : <EOL> ssl_validate = get_option ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> ssl_validate = ssl_validate is None or ssl_validate . lower ( ) != '<STR_LIT:false>' <EOL> ssl_certfile = env . get ( '<STR_LIT>' ) <EOL> if ssl_certfile is None : <EOL> ssl_certfile = get_option ( '<STR_LIT>' , host ) <EOL> if ssl_certfile is None : <EOL> ssl_certfile = get_option ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if ssl_validate and ssl_certfile is None : <EOL> sys . exit ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % ( config_file , ) ) <EOL> if not ssl_certfile is None : <EOL> ssl_certfile = os . path . expanduser ( ssl_certfile ) <EOL> userkey = get_option ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if userkey : <EOL> userkey = os . path . expanduser ( userkey ) <EOL> usercert = get_option ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if usercert : <EOL> usercert = os . path . expanduser ( usercert ) <EOL> return dict ( ca_certs = ssl_certfile , <EOL> cert_reqs = ssl . CERT_REQUIRED if ssl_validate else ssl . CERT_NONE , <EOL> ssl_version = ssl . PROTOCOL_TLSv1 , <EOL> keyfile = userkey , certfile = usercert ) </s>
