Пример #1
0
def complete_names(names_data, data_conn):
    if not names_cache:
        mime_map, spine_names = get_data(data_conn, 'names_data')
        names_cache[None] = all_names = frozenset(
            Name(name, mt, spine_names) for name, mt in iteritems(mime_map))
        names_cache['text_link'] = frozenset(n for n in all_names
                                             if n.in_spine)
        names_cache['stylesheet'] = frozenset(n for n in all_names
                                              if n.mime_type in OEB_STYLES)
        names_cache['image'] = frozenset(n for n in all_names
                                         if n.mime_type.startswith('image/'))
        names_cache['font'] = frozenset(n for n in all_names
                                        if n.mime_type in OEB_FONTS)
        names_cache[
            'css_resource'] = names_cache['image'] | names_cache['font']
        names_cache['descriptions'] = d = {}
        for x, desc in iteritems({
                'text_link': _('Text'),
                'stylesheet': _('Stylesheet'),
                'image': _('Image'),
                'font': _('Font')
        }):
            for n in names_cache[x]:
                d[n] = desc
    names_type, base, root = names_data
    quote = (lambda x: x
             ) if base.lower().endswith('.css') else prepare_string_for_xml
    names = names_cache.get(names_type, names_cache[None])
    nmap = {name: name_to_href(name, root, base, quote) for name in names}
    items = tuple(sorted(frozenset(itervalues(nmap)), key=numeric_sort_key))
    d = names_cache['descriptions'].get
    descriptions = {href: d(name) for name, href in iteritems(nmap)}
    return items, descriptions, {}
Пример #2
0
def complete_names(names_data, data_conn):
    if not names_cache:
        mime_map, spine_names = get_data(data_conn, 'names_data')
        names_cache[None] = frozenset(Name(name, mt, spine_names) for name, mt in mime_map.iteritems())
        names_cache['text_link'] = frozenset(n for n in names_cache if n.in_spine)
        names_cache['stylesheet'] = frozenset(n for n in names_cache if n.mime_type in OEB_STYLES)
        names_cache['image'] = frozenset(n for n in names_cache if n.mime_type.startswith('image/'))
        names_cache['font'] = frozenset(n for n in names_cache if n.mime_type in OEB_FONTS)
    names_type, base, root = names_data
    names = names_cache.get(names_type, names_cache[None])
    ans = frozenset(name_to_href(name, root, base) for name in names)
    return ans, {}
Пример #3
0
def complete_names(names_data, data_conn):
    if not names_cache:
        mime_map, spine_names = get_data(data_conn, 'names_data')
        names_cache[None] = frozenset(
            Name(name, mt, spine_names) for name, mt in mime_map.iteritems())
        names_cache['text_link'] = frozenset(n for n in names_cache
                                             if n.in_spine)
        names_cache['stylesheet'] = frozenset(n for n in names_cache
                                              if n.mime_type in OEB_STYLES)
        names_cache['image'] = frozenset(n for n in names_cache
                                         if n.mime_type.startswith('image/'))
        names_cache['font'] = frozenset(n for n in names_cache
                                        if n.mime_type in OEB_FONTS)
    names_type, base, root = names_data
    names = names_cache.get(names_type, names_cache[None])
    ans = frozenset(name_to_href(name, root, base) for name in names)
    return ans, {}
Пример #4
0
def complete_names(names_data, data_conn):
    if not names_cache:
        mime_map, spine_names = get_data(data_conn, 'names_data')
        names_cache[None] = all_names = frozenset(Name(name, mt, spine_names) for name, mt in mime_map.iteritems())
        names_cache['text_link'] = frozenset(n for n in all_names if n.in_spine)
        names_cache['stylesheet'] = frozenset(n for n in all_names if n.mime_type in OEB_STYLES)
        names_cache['image'] = frozenset(n for n in all_names if n.mime_type.startswith('image/'))
        names_cache['font'] = frozenset(n for n in all_names if n.mime_type in OEB_FONTS)
        names_cache['css_resource'] = names_cache['image'] | names_cache['font']
        names_cache['descriptions'] = d = {}
        for x, desc in {'text_link':_('Text'), 'stylesheet':_('Stylesheet'), 'image':_('Image'), 'font':_('Font')}.iteritems():
            for n in names_cache[x]:
                d[n] = desc
    names_type, base, root = names_data
    quote = (lambda x:x) if base.lower().endswith('.css') else prepare_string_for_xml
    names = names_cache.get(names_type, names_cache[None])
    nmap = {name:name_to_href(name, root, base, quote) for name in names}
    items = frozenset(nmap.itervalues())
    d = names_cache['descriptions'].get
    descriptions = {href:d(name) for name, href in nmap.iteritems()}
    return items, descriptions, {}