Пример #1
0
def query(dictionary, word):
    global config, dict_cache

    enable_cache = config['cache']['enable'] if config else True
    if enable_cache:
        cache_expire = (config['cache']['expire'] if config else 24) * 3600
        now = time.time()

        # dict_cache.set('last lookup time', now, float('inf'))
        # time.sleep(1)
        # if dict_cache.get('last lookup time') != now:
        #     return

        clean_time = dict_cache.get('last clean time')
        if clean_time is None or now - clean_time > cache_expire:
            dict_cache.set('last clean time', now, float('inf'))
            dict_cache.clean_expired()

        cache_name = '{}@{}'.format(word, dictionary)
        cache = dict_cache.get(cache_name)
        if cache:
            return cache

    options = config['options'] if config else {}
    dict_name = cndict.get_full_name(dictionary)
    options = options.get(dict_name, {})

    result = cndict.lookup(dictionary, word, **options)
    if result:
        result = [item.decode('utf-8') for item in result]
        if enable_cache:
            dict_cache.set(cache_name, result, cache_expire)
        return result
Пример #2
0
def query(dictionary, word):
    global config, dict_cache

    enable_cache = config['cache']['enable'] if config else True
    if enable_cache:
        cache_expire = (config['cache']['expire'] if config else 24) * 3600
        now = time.time()

        # dict_cache.set('last lookup time', now, float('inf'))
        # time.sleep(1)
        # if dict_cache.get('last lookup time') != now:
        #     return

        clean_time = dict_cache.get('last clean time')
        if clean_time is None or now - clean_time > cache_expire:
            dict_cache.set('last clean time', now, float('inf'))
            dict_cache.clean_expired()

        cache_name = '{}@{}'.format(word, dictionary)
        cache = dict_cache.get(cache_name)
        if cache:
            return cache

    options = config['options'] if config else {}
    dict_name = cndict.get_full_name(dictionary)
    options = options.get(dict_name, {})

    result = cndict.lookup(dictionary, word, **options)
    if result:
        result = [item.decode('utf-8') for item in result]
        if enable_cache:
            dict_cache.set(cache_name, result, cache_expire)
        return result
Пример #3
0
 def set_keymap(self, value):
     keymap = value
     for conn, child in self.__branches.values():
         modifier = self.__modifier_map[conn['modifiers']]
         if modifier in keymap:
             child['config']['script'] = re.sub(r'(?<=[@|>] )\w+(?=")', keymap[modifier],
                                                child['config']['script'])
             if modifier != 'none':
                 dict_name = cndict.get_full_name(keymap[modifier])
                 conn['modifiersubtext'] = re.sub(r'(?<=in )\w+(?= dict)', dict_name,
                                                  conn['modifiersubtext'])
Пример #4
0
 def set_keymap(self, value):
     keymap = value
     for conn, child in self.__branches.values():
         modifier = self.__modifier_map[conn['modifiers']]
         if modifier in keymap:
             child['config']['script'] = re.sub(r'(?<=[@|>] )\w+(?=")', keymap[modifier],
                                                child['config']['script'])
             if modifier != 'none':
                 dict_name = cndict.get_full_name(keymap[modifier])
                 conn['modifiersubtext'] = re.sub(r'(?<=in )\w+(?= dict)', dict_name,
                                                  conn['modifiersubtext'])