<s> import os <EOL> import ssl <EOL> import yaml <EOL> import asyncio <EOL> import logging <EOL> from . client import ClientProtocol <EOL> from . roles import Role <EOL> from . utility import CaseInsensitiveList <EOL> def load_extended_roles ( ctx , k , roles , roles_extending ) : <EOL> for kk , vv in roles_extending . get ( k , { } ) . items ( ) : <EOL> roles [ kk ] = Role ( ctx , kk , roles = roles , ** vv ) <EOL> roles = load_extended_roles ( ctx , kk , roles , roles_extending ) <EOL> return roles <EOL> class ConfigHandler ( object ) : <EOL> config_st = { } <EOL> ctx = None <EOL> listener_protos = { <EOL> '<STR_LIT>' : ClientProtocol , <EOL> } <EOL> def __init__ ( self , config_name , ctx ) : <EOL> self . config_name = config_name <EOL> self . ctx = ctx <EOL> self . config_st = yaml . load ( open ( config_name , '<STR_LIT:r>' ) ) <EOL> def process ( self ) : <EOL> for k , v in self . config_st . items ( ) : <EOL> setattr ( self , k , v ) <EOL> for k , v in self . config_st [ '<STR_LIT>' ] . items ( ) : <EOL> setattr ( self , k , v ) <EOL> for l in self . listeners : <EOL> proto = l . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . ctx . logger . info ( '<STR_LIT>' . format ( l [ '<STR_LIT:host>' ] , l [ '<STR_LIT:port>' ] , proto , '<STR_LIT>' if l [ '<STR_LIT>' ] else '<STR_LIT>' ) ) <EOL> if l [ '<STR_LIT>' ] : <EOL> context = ssl . SSLContext ( ssl . PROTOCOL_SSLv23 ) <EOL> try : <EOL> context . set_ciphers ( "<STR_LIT>" ) <EOL> except ssl . SSLError : <EOL> print ( "<STR_LIT>" ) <EOL> break <EOL> keyfile = os . path . expanduser ( l . get ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> if not keyfile : <EOL> print ( '<STR_LIT>' . format ( l [ '<STR_LIT:host>' ] , l [ '<STR_LIT:port>' ] , proto ) ) <EOL> continue <EOL> certfile = os . path . expanduser ( l . get ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> if not certfile : <EOL> print ( '<STR_LIT>' . format ( l [ '<STR_LIT:host>' ] , l [ '<STR_LIT:port>' ] , proto ) ) <EOL> continue <EOL> if ssl . HAS_ECDH : <EOL> context . set_ecdh_curve ( '<STR_LIT>' ) <EOL> context . options |= ssl . OP_SINGLE_ECDH_USE <EOL> if '<STR_LIT>' in l : <EOL> DHparams = os . path . expanduser ( l . get ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> if DHparams : <EOL> context . load_dh_params ( DHparams ) <EOL> context . options |= ssl . OP_SINGLE_DH_USE <EOL> context . load_cert_chain ( certfile , keyfile = keyfile ) <EOL> context . options |= ssl . OP_NO_SSLv2 <EOL> context . options |= ssl . OP_NO_SSLv3 <EOL> context . options |= ssl . OP_NO_COMPRESSION <EOL> context . options |= ssl . OP_CIPHER_SERVER_PREFERENCE <EOL> context . options |= <NUM_LIT> <EOL> print ( '<STR_LIT>' ) <EOL> else : <EOL> context = None <EOL> lstn = self . ctx . eventloop . create_server ( self . listener_protos [ proto ] , l [ '<STR_LIT:host>' ] , l [ '<STR_LIT:port>' ] , ssl = context ) <EOL> self . ctx . listeners . append ( lstn ) <EOL> if self . metadata . get ( '<STR_LIT>' , None ) is not None : <EOL> try : <EOL> self . metadata [ '<STR_LIT>' ] = int ( self . metadata [ '<STR_LIT>' ] ) <EOL> except : <EOL> print ( '<STR_LIT>' ) <EOL> print ( '<STR_LIT>' ) <EOL> self . metadata [ '<STR_LIT>' ] = <NUM_LIT:20> <EOL> if self . metadata . get ( '<STR_LIT>' , [ ] ) is None : <EOL> self . metadata [ '<STR_LIT>' ] = [ ] <EOL> self . metadata [ '<STR_LIT>' ] = CaseInsensitiveList ( self . metadata [ '<STR_LIT>' ] ) <EOL> roles = { } <EOL> roles_extending = { <EOL> None : { } , <EOL> } <EOL> for k , v in self . roles . items ( ) : <EOL> extends = v . get ( '<STR_LIT>' , None ) <EOL> if extends not in roles_extending : <EOL> roles_extending [ extends ] = { } <EOL> roles_extending [ extends ] [ k ] = v <EOL> base_roles = roles_extending [ None ] <EOL> for k , v in base_roles . items ( ) : <EOL> roles [ k ] = Role ( self . ctx , k , roles = roles , ** v ) <EOL> roles = load_extended_roles ( self . ctx , k , roles , roles_extending ) <EOL> self . ctx . roles = roles </s>
