<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import , division , print_function , unicode_literals <EOL> import os <EOL> from pies . functools import lru_cache <EOL> from pies . overrides import * <EOL> try : <EOL> import configparser <EOL> except ImportError : <EOL> import ConfigParser as configparser <EOL> MAX_CONFIG_SEARCH_DEPTH = <NUM_LIT> <EOL> default = { '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' ] , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False } <EOL> @ lru_cache ( ) <EOL> def from_path ( path ) : <EOL> computed_settings = default . copy ( ) <EOL> _update_settings_with_config ( path , '<STR_LIT>' , '<STR_LIT>' , ( '<STR_LIT:*>' , '<STR_LIT>' , '<STR_LIT>' ) , computed_settings ) <EOL> _update_settings_with_config ( path , '<STR_LIT>' , '<STR_LIT>' , ( '<STR_LIT>' , ) , computed_settings ) <EOL> _update_settings_with_config ( path , '<STR_LIT>' , None , ( '<STR_LIT>' , ) , computed_settings ) <EOL> return computed_settings <EOL> def _update_settings_with_config ( path , name , default , sections , computed_settings ) : <EOL> editor_config_file = default and os . path . expanduser ( default ) <EOL> tries = <NUM_LIT:0> <EOL> current_directory = path <EOL> while current_directory and tries < MAX_CONFIG_SEARCH_DEPTH : <EOL> potential_path = os . path . join ( current_directory , native_str ( name ) ) <EOL> if os . path . exists ( potential_path ) : <EOL> editor_config_file = potential_path <EOL> break <EOL> current_directory = os . path . split ( current_directory ) [ <NUM_LIT:0> ] <EOL> tries += <NUM_LIT:1> <EOL> if editor_config_file and os . path . exists ( editor_config_file ) : <EOL> _update_with_config_file ( computed_settings , editor_config_file , sections ) <EOL> def _update_with_config_file ( computed_settings , file_path , sections ) : <EOL> settings = _get_config_data ( file_path , sections ) <EOL> if not settings : <EOL> return <EOL> for key , value in settings . items ( ) : <EOL> access_key = key . replace ( '<STR_LIT>' , '<STR_LIT>' ) . lower ( ) <EOL> if key . startswith ( '<STR_LIT>' ) : <EOL> existing_value_type = list <EOL> else : <EOL> existing_value_type = type ( default . get ( access_key , '<STR_LIT>' ) ) <EOL> if existing_value_type in ( list , tuple ) : <EOL> existing_data = set ( computed_settings . get ( access_key , default . get ( access_key ) ) or ( ) ) <EOL> if key . startswith ( '<STR_LIT>' ) : <EOL> computed_settings [ access_key ] = list ( existing_data . difference ( value . split ( "<STR_LIT:U+002C>" ) ) ) <EOL> else : <EOL> computed_settings [ access_key ] = list ( existing_data . union ( value . split ( "<STR_LIT:U+002C>" ) ) ) <EOL> elif existing_value_type == bool and value . lower ( ) . strip ( ) == "<STR_LIT:false>" : <EOL> computed_settings [ access_key ] = False <EOL> else : <EOL> computed_settings [ access_key ] = existing_value_type ( value ) <EOL> @ lru_cache ( ) <EOL> def _get_config_data ( file_path , sections ) : <EOL> with open ( file_path ) as config_file : <EOL> if file_path . endswith ( "<STR_LIT>" ) : <EOL> line = "<STR_LIT:\n>" <EOL> last_position = config_file . tell ( ) <EOL> while line : <EOL> line = config_file . readline ( ) <EOL> if "<STR_LIT:[>" in line : <EOL> config_file . seek ( last_position ) <EOL> break <EOL> last_position = config_file . tell ( ) <EOL> config = configparser . SafeConfigParser ( ) <EOL> config . readfp ( config_file ) <EOL> settings = dict ( ) <EOL> for section in sections : <EOL> if config . has_section ( section ) : <EOL> settings . update ( dict ( config . items ( section ) ) ) <EOL> return settings <EOL> return None </s>
