def load_config(): patch_configparser() import re from configparser import ConfigParser _LOGLv = { 0: logging.WARNING, 1: logging.INFO, 2: logging.TEST, 3: logging.DEBUG } CONFIG_FILENAME = os.path.join(config_dir, 'Config.ini') CONFIG_USER_FILENAME = re.sub(r'\.ini$', '.user.ini', CONFIG_FILENAME) CONFIG_AUTO_FILENAME = os.path.join(config_dir, 'ActionFilter.ini') CONFIG = ConfigParser(inline_comment_prefixes=('#', ';')) CONFIG._optcre = re.compile( r'(?P<option>[^=\s]+)\s*(?P<vi>=?)\s*(?P<value>.*)') CONFIG.read([CONFIG_FILENAME, CONFIG_USER_FILENAME]) LISTEN_IP = CONFIG.get('listen', 'ip') if LISTEN_IP == '0.0.0.0': LISTEN_IP = '127.0.0.1' elif LISTEN_IP == '::': LISTEN_IP = '::1' elif LISTEN_IP == '': LINK_PROFILE = CONFIG.get('link', 'profile') if LINK_PROFILE not in ('ipv4', 'ipv6', 'ipv46'): LINK_PROFILE = 'ipv4' LISTEN_IP = '127.0.0.1' if '4' in LINK_PROFILE else '::1' LISTEN_GAE_PORT = CONFIG.getint('listen', 'gae_port', fallback=8086) LISTEN_AUTO_PORT = CONFIG.getint('listen', 'auto_port', fallback=8087) LISTEN_GAE = '%s:%d' % (LISTEN_IP, LISTEN_GAE_PORT) LISTEN_AUTO = '%s:%d' % (LISTEN_IP, LISTEN_AUTO_PORT) LOG_PRINT = CONFIG.getboolean('log', 'print', fallback=True) LOG_LEVEL = _LOGLv[min(CONFIG.getint('log', 'level', fallback=1), 3)] log_config = {'level': LOG_LEVEL} if not LOG_PRINT: log_config['stream'] = logging.NULL_STREAM logging.basicConfig(**log_config) return LISTEN_GAE, LISTEN_AUTO
def load_config(): patch_configparser() import re from configparser import ConfigParser _LOGLv = { 0: logging.WARNING, 1: logging.INFO, 2: logging.TEST, 3: logging.DEBUG } CONFIG = ConfigParser(dict_type=dict, inline_comment_prefixes=('#', ';')) CONFIG._optcre = re.compile( r'(?P<option>[^=\s]+)\s*(?P<vi>=?)\s*(?P<value>.*)') CONFIG.read([config_filename, config_user_filename]) LISTEN_IP = CONFIG.get('listen', 'ip') if LISTEN_IP == '0.0.0.0': LISTEN_IP = '127.0.0.1' elif LISTEN_IP == '::': LISTEN_IP = '::1' elif LISTEN_IP == '': LINK_PROFILE = CONFIG.get('link', 'profile') if LINK_PROFILE not in ('ipv4', 'ipv6', 'ipv46'): LINK_PROFILE = 'ipv4' LISTEN_IP = '127.0.0.1' if '4' in LINK_PROFILE else '::1' LISTEN_AUTOPORT = CONFIG.getint('listen', 'autoport', fallback=8087) LISTEN_ACTPORT = CONFIG.getint('listen', 'actport', fallback=8086) LISTEN_ACTTYPE = CONFIG.get('listen', 'act', fallback='cfw').upper() LISTEN_AUTO = '%s:%d' % (LISTEN_IP, LISTEN_AUTOPORT) LISTEN_ACT = '%s:%d' % (LISTEN_IP, LISTEN_ACTPORT) LOG_PRINT = CONFIG.getboolean('log', 'print', fallback=True) LOG_LEVEL = _LOGLv[min(CONFIG.getint('log', 'level', fallback=1), 3)] log_config = {'level': LOG_LEVEL} if not LOG_PRINT: log_config['stream'] = logging.NULL_STREAM logging.basicConfig(**log_config) return LISTEN_AUTO, LISTEN_ACT, LISTEN_ACTTYPE