def conf(*args, **kwds): global conf_cache if conf_cache is None and os.path.exists(CONF_FILE): try: conf_cache = util.fdict(CONF_FILE, util.__dict__) except IOError: traceback.print_exc() return conf_cache and conf_cache.get(*args, **kwds)
def read_credentials(): if os.path.exists(CREDENTIALS_FILE): try: raw_creds = util.fdict(CREDENTIALS_FILE) return {name.lower():creds for (name,creds) in raw_creds.iteritems()} except Exception: traceback.print_exc() return {}
USER_AGENT = 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0' USER_AGENT_TEXT = 'Links (2.16; Linux 4.16.3-1-ARCH x86_64; GNU C 8.1; text)' ACCEPT_ENCODING = 'gzip, deflate' TIMEOUT_S = 20 READ_BYTES_MAX = 1024*1024 CMDS_PER_LINE_MAX = 6 GIBG_CACHE_SIZE = 128 BS4_PARSER = 'html5lib' MAX_AURL = 35 MAX_DESC_LEN = 100 CONF_FILE = 'conf/url.py' conf = util.fdict(CONF_FILE) if os.path.exists(CONF_FILE) else {} def get_default_headers(): yield 'User-Agent', USER_AGENT_TEXT yield 'Accept-Encoding', ACCEPT_ENCODING language, encoding = locale.getdefaultlocale() if language != 'C': yield 'Accept-Language', language default_headers = tuple(get_default_headers()) class CustomHTTPRedirectHandler(urllib2.HTTPRedirectHandler): max_repeats = 12 max_redirections = 30 def get_opener(bind_host=None):
from util import LinkSet, table, fdict, bind, after, dice from auth import admin from collections import OrderedDict from itertools import * from functools import * import random import re dungeons = table('conf/dungeons.py', 'dungeon_spec') conf = fdict('conf/general.py') DANGER = 1 MYSTERY = 2 def normalise_name(name): name = name.strip() name = re.sub(r'[\x00-\x1F]', '', name) name = re.sub(r'\s+', ' ', name) return name def hero_names(heroes): names = map(lambda h: h.name, heroes) names = ', '.join(names[:-2] + [' and '.join(names[-2:])]) return names class Game(object): __slots__ = ( 'install', 'uninstall', 'chan', 'hidden_dungeons', 'found_dungeons', 'complete', 'heroes', 'rounds', 'turn', 'attacks')