def _CreateStyleFromConfigParser(config):
 section = ('yapf' if config.has_section('yapf') else 'style')
 if config.has_option('style', 'based_on_style'):
  based_on = config.get('style', 'based_on_style').lower()
  base_style = _STYLE_NAME_TO_FACTORY[based_on]()
 elif config.has_option('yapf', 'based_on_style'):
  based_on = config.get('yapf', 'based_on_style').lower()
  base_style = _STYLE_NAME_TO_FACTORY[based_on]()
 else:
  base_style = _GLOBAL_STYLE_FACTORY()
 for (option, value) in config.items(section):
  if (option.lower() == 'based_on_style'):
   continue
  option = option.upper()
  if (option not in _STYLE_OPTION_VALUE_CONVERTER):
   raise StyleConfigError('Unknown style option "{0}"'.format(option))
  try:
   base_style[option] = _STYLE_OPTION_VALUE_CONVERTER[option](value)
  except ValueError:
   raise StyleConfigError("'{}' is not a valid setting for {}.".format(value, option))
 return base_style

def _CreateStyleFromConfigParser ( config ) : section = ( 'yapf' if config . has_section ( 'yapf' ) else 'style' ) if config . has_option ( 'style' , 'based_on_style' ) : based_on = config . get ( 'style' , 'based_on_style' ) . lower ( ) base_style = _STYLE_NAME_TO_FACTORY [ based_on ] ( ) elif config . has_option ( 'yapf' , 'based_on_style' ) : based_on = config . get ( 'yapf' , 'based_on_style' ) . lower ( ) base_style = _STYLE_NAME_TO_FACTORY [ based_on ] ( ) else : base_style = _GLOBAL_STYLE_FACTORY ( ) for ( option , value ) in config . items ( section ) : if ( option . lower ( ) == 'based_on_style' ) : continue option = option . upper ( ) if ( option not in _STYLE_OPTION_VALUE_CONVERTER ) : raise StyleConfigError ( 'Unknown style option "{0}"' . format ( option ) ) try : base_style [ option ] = _STYLE_OPTION_VALUE_CONVERTER [ option ] ( value ) except ValueError : raise StyleConfigError ( "'{}' is not a valid setting for {}." . format ( value , option ) ) return base_style
create a style dict from a configuration file .