2
# vim:fileencoding=utf-8
3
from __future__ import (unicode_literals, division, absolute_import,
7
__copyright__ = '2014, Kovid Goyal <kovid at kovidgoyal.net>'
11
from calibre.ebooks.oeb.polish.container import OPF_NAMESPACES
12
from calibre.utils.localization import canonicalize_lang
14
def get_book_language(container):
15
for lang in container.opf_xpath('//dc:language'):
18
code = canonicalize_lang(raw.split(',')[0].strip())
22
def set_guide_item(container, item_type, title, name, frag=None):
23
ref_tag = '{%s}reference' % OPF_NAMESPACES['opf']
26
href = container.name_to_href(name, container.opf_name)
30
guides = container.opf_xpath('//opf:guide')
31
if not guides and href:
32
g = container.opf.makeelement('{%s}guide' % OPF_NAMESPACES['opf'], nsmap={'opf':OPF_NAMESPACES['opf']})
33
container.insert_into_xml(container.opf, g)
38
for child in guide.iterchildren(etree.Element):
39
if child.tag == ref_tag and child.get('type', '').lower() == item_type.lower():
41
if not matches and href:
42
r = guide.makeelement(ref_tag, type=item_type, nsmap={'opf':OPF_NAMESPACES['opf']})
43
container.insert_into_xml(guide, r)
47
m.set('title', title), m.set('href', href), m.set('type', item_type)
49
container.remove_from_xml(m)
50
container.dirty(container.opf_name)