Esempio n. 1
0
def load_search_index():
    topchar = 0x10ffff
    ver = (1, topchar, icu_unicode_version or unicodedata.unidata_version
           )  # Increment this when you make any changes to the index
    name_map = {}
    path = os.path.join(cache_dir(), 'unicode-name-index.pickle')
    if os.path.exists(path):
        with open(path, 'rb') as f:
            name_map = cPickle.load(f)
        if name_map.pop('calibre-nm-version:', None) != ver:
            name_map = {}
    if not name_map:
        name_map = defaultdict(set)
        for x in xrange(1, topchar + 1):
            for word in character_name_from_code(x).split():
                name_map[word.lower()].add(x)
        from calibre.ebooks.html_entities import html5_entities
        for name, char in html5_entities.iteritems():
            try:
                name_map[name.lower()].add(ord(char))
            except TypeError:
                continue
        name_map['nnbsp'].add(0x202F)
        name_map['calibre-nm-version:'] = ver
        cPickle.dump(dict(name_map), open(path, 'wb'), -1)
        del name_map['calibre-nm-version:']
    return name_map
Esempio n. 2
0
def load_search_index():
    topchar = 0x10ffff
    ver = (1, topchar, icu_unicode_version or unicodedata.unidata_version)  # Increment this when you make any changes to the index
    name_map = {}
    path = os.path.join(cache_dir(), 'unicode-name-index.pickle')
    if os.path.exists(path):
        with open(path, 'rb') as f:
            name_map = cPickle.load(f)
        if name_map.pop('calibre-nm-version:', None) != ver:
            name_map = {}
    if not name_map:
        name_map = defaultdict(set)
        for x in xrange(1, topchar + 1):
            for word in character_name_from_code(x).split():
                name_map[word.lower()].add(x)
        from calibre.ebooks.html_entities import html5_entities
        for name, char in html5_entities.iteritems():
            try:
                name_map[name.lower()].add(ord(char))
            except TypeError:
                continue
        name_map['nnbsp'].add(0x202F)
        name_map['calibre-nm-version:'] = ver
        cPickle.dump(dict(name_map), open(path, 'wb'), -1)
        del name_map['calibre-nm-version:']
    return name_map
Esempio n. 3
0
def load_search_index():
    ver = 1  # Increment this when you make any changes to the index
    name_map = {}
    path = os.path.join(cache_dir(), "unicode-name-index.pickle")
    if os.path.exists(path):
        with open(path, "rb") as f:
            name_map = cPickle.load(f)
        if name_map.pop("calibre-nm-version:", -1) != ver:
            name_map = {}
    if not name_map:
        name_map = defaultdict(set)
        from calibre.constants import ispy3

        if not ispy3:
            chr = unichr
        for x in xrange(1, 0x10FFFF + 1):
            for word in unicodedata.name(chr(x), "").split():
                name_map[word.lower()].add(x)
        from calibre.ebooks.html_entities import html5_entities

        for name, char in html5_entities.iteritems():
            try:
                name_map[name.lower()].add(ord(char))
            except TypeError:
                continue
        name_map["nnbsp"].add(0x202F)
        name_map["calibre-nm-version:"] = ver
        cPickle.dump(dict(name_map), open(path, "wb"), -1)
        del name_map["calibre-nm-version:"]
    return name_map
Esempio n. 4
0
def html_entities():
    ans = getattr(html_entities, 'ans', None)
    if ans is None:
        from calibre.ebooks.html_entities import html5_entities
        ans = defaultdict(set)
        for name, char in html5_entities.iteritems():
            try:
                ans[name.lower()].add(ord_string(char)[0])
            except TypeError:
                continue
        ans['nnbsp'].add(0x202F)
        ans = dict(ans)
        html_entities.ans = ans
    return ans
Esempio n. 5
0
def html_entities():
    ans = getattr(html_entities, 'ans', None)
    if ans is None:
        from calibre.ebooks.html_entities import html5_entities
        ans = defaultdict(set)
        for name, char in html5_entities.iteritems():
            try:
                ans[name.lower()].add(ord_string(char)[0])
            except TypeError:
                continue
        ans['nnbsp'].add(0x202F)
        ans = dict(ans)
        html_entities.ans = ans
    return ans