Пример #1
0
 def test_title(self):  # {{{
     def rt(root):
         return read_title(root, read_prefixes(root), read_refines(root))
     def st(root, title, title_sort=None):
         set_title(root, read_prefixes(root), read_refines(root), title, title_sort)
         return rt(root)
     root = self.get_opf('''<dc:title/><dc:title id='t'>xxx</dc:title>''')
     self.ae(rt(root), 'xxx')
     self.ae(st(root, 'abc', 'cba'), 'abc')
     self.ae(read_title_sort(root, read_prefixes(root), read_refines(root)), 'cba')
     root = self.get_opf('''<dc:title>yyy</dc:title><dc:title id='t'>x  xx
         </dc:title><meta refines='#t' property='title-type'>main</meta><meta name="calibre:title_sort" content="sorted"/>''')
     self.ae(rt(root), 'x xx')
     self.ae(read_title_sort(root, read_prefixes(root), read_refines(root)), 'sorted')
     self.ae(st(root, 'abc'), 'abc')
Пример #2
0
    def test_title(self):  # {{{
        def rt(root):
            return read_title(root, read_prefixes(root), read_refines(root))

        def st(root, title, title_sort=None):
            set_title(root, read_prefixes(root), read_refines(root), title, title_sort)
            return rt(root)
        root = self.get_opf('''<dc:title/><dc:title id='t'>xxx</dc:title>''')
        self.ae(rt(root), 'xxx')
        self.ae(st(root, 'abc', 'cba'), 'abc')
        self.ae(read_title_sort(root, read_prefixes(root), read_refines(root)), 'cba')
        root = self.get_opf('''<dc:title>yyy</dc:title><dc:title id='t'>x  xx
            </dc:title><meta refines='#t' property='title-type'>main</meta><meta name="calibre:title_sort" content="sorted"/>''')
        self.ae(rt(root), 'x xx')
        self.ae(read_title_sort(root, read_prefixes(root), read_refines(root)), 'sorted')
        self.ae(st(root, 'abc'), 'abc')
Пример #3
0
    def test_dates(self):  # {{{
        from calibre.utils.date import utcnow

        def rl(root):
            p, r = read_prefixes(root), read_refines(root)
            return read_pubdate(root, p, r), read_timestamp(root, p, r)

        def st(root, pd, ts):
            p, r = read_prefixes(root), read_refines(root)
            set_pubdate(root, p, r, pd)
            set_timestamp(root, p, r, ts)
            return rl(root)

        def ae(root, y1=None, y2=None):
            x1, x2 = rl(root)
            for x, y in ((x1, y1), (x2, y2)):
                if y is None:
                    self.assertIsNone(x)
                else:
                    self.ae(y, getattr(x, 'year', None))
        root = self.get_opf('''<dc:date>1999-3-2</dc:date><meta property="calibre:timestamp" scheme="dcterms:W3CDTF">2001</meta>''')
        ae(root, 1999, 2001)
        n = utcnow()
        q = n.replace(microsecond=0)
        self.ae(st(root, n, n), (n, q))
        root = self.get_opf('''<dc:date>1999-3-2</dc:date><meta name="calibre:timestamp" content="2001-1-1"/>''')
        ae(root, 1999, 2001)
        root = self.get_opf('''<meta property="dcterms:modified">2003</meta>''')
        self.ae(read_last_modified(root, read_prefixes(root), read_refines(root)).year, 2003)
Пример #4
0
    def test_dates(self):  # {{{
        from calibre.utils.date import utcnow

        def rl(root):
            p, r = read_prefixes(root), read_refines(root)
            return read_pubdate(root, p, r), read_timestamp(root, p, r)

        def st(root, pd, ts):
            p, r = read_prefixes(root), read_refines(root)
            set_pubdate(root, p, r, pd)
            set_timestamp(root, p, r, ts)
            return rl(root)

        def ae(root, y1=None, y2=None):
            x1, x2 = rl(root)
            for x, y in ((x1, y1), (x2, y2)):
                if y is None:
                    self.assertIsNone(x)
                else:
                    self.ae(y, getattr(x, 'year', None))
        root = self.get_opf('''<dc:date>1999-3-2</dc:date><meta property="calibre:timestamp" scheme="dcterms:W3CDTF">2001</meta>''')
        ae(root, 1999, 2001)
        n = utcnow()
        q = n.replace(microsecond=0)
        self.ae(st(root, n, n), (n, q))
        root = self.get_opf('''<dc:date>1999-3-2</dc:date><meta name="calibre:timestamp" content="2001-1-1"/>''')
        ae(root, 1999, 2001)
        root = self.get_opf('''<meta property="dcterms:modified">2003</meta>''')
        self.ae(read_last_modified(root, read_prefixes(root), read_refines(root)).year, 2003)
Пример #5
0
 def test_raster_cover(self):  # {{{
     def rt(root):
         return read_raster_cover(root, read_prefixes(root), read_refines(root))
     root = self.get_opf('<meta name="cover" content="cover"/>', '<item id="cover" media-type="image/jpeg" href="x.jpg"/>')
     self.ae('x.jpg', rt(root))
     root = self.get_opf('<meta name="cover" content="cover"/>',
                         '<item id="cover" media-type="image/jpeg" href="x.jpg"/><item media-type="image/jpeg" href="y.jpg" properties="cover-image"/>')
     self.ae('y.jpg', rt(root))
     ensure_is_only_raster_cover(root, read_prefixes(root), read_refines(root), 'x.jpg')
     self.ae('x.jpg', rt(root))
     self.ae(['x.jpg'], root.xpath('//*[@properties="cover-image"]/@href'))
     self.assertFalse(root.xpath('//*[@name]'))
Пример #6
0
 def test_raster_cover(self):  # {{{
     def rt(root):
         return read_raster_cover(root, read_prefixes(root), read_refines(root))
     root = self.get_opf('<meta name="cover" content="cover"/>', '<item id="cover" media-type="image/jpeg" href="x.jpg"/>')
     self.ae('x.jpg', rt(root))
     root = self.get_opf('<meta name="cover" content="cover"/>',
                         '<item id="cover" media-type="image/jpeg" href="x.jpg"/><item media-type="image/jpeg" href="y.jpg" properties="cover-image"/>')
     self.ae('y.jpg', rt(root))
     ensure_is_only_raster_cover(root, read_prefixes(root), read_refines(root), 'x.jpg')
     self.ae('x.jpg', rt(root))
     self.ae(['x.jpg'], root.xpath('//*[@properties="cover-image"]/@href'))
     self.assertFalse(root.xpath('//*[@name]'))
Пример #7
0
def upgrade_metadata(root):
    data = Data()
    data.prefixes = read_prefixes(root)
    data.refines = read_refines(root)

    upgrade_identifiers(root, data)
    upgrade_title(root, data)
    upgrade_languages(root, data)
    upgrade_authors(root, data)
    upgrade_timestamp(root, data)
    upgrade_date(root, data)
    upgrade_rating(root, data)
    upgrade_series(root, data)
    upgrade_custom(root, data)
    upgrade_meta(root, data)

    remove_invalid_attrs_in_dc_metadata(root, data)
    pretty_print_opf(root)
Пример #8
0
def upgrade_metadata(root):
    data = Data()
    data.prefixes = read_prefixes(root)
    data.refines = read_refines(root)

    upgrade_identifiers(root, data)
    upgrade_title(root, data)
    upgrade_languages(root, data)
    upgrade_authors(root, data)
    upgrade_timestamp(root, data)
    upgrade_date(root, data)
    upgrade_rating(root, data)
    upgrade_series(root, data)
    upgrade_custom(root, data)
    upgrade_meta(root, data)
    upgrade_cover(root, data)

    remove_invalid_attrs_in_dc_metadata(root, data)
    set_last_modified(root, data.prefixes, data.refines)
    pretty_print_opf(root)
Пример #9
0
 def rt(root):
     return read_comments(root, read_prefixes(root), read_refines(root))
Пример #10
0
 def rl(root):
     return read_pubdate(root, read_prefixes(root), read_refines(root)), read_timestamp(root, read_prefixes(root), read_refines(root))
Пример #11
0
 def rl(root):
     return read_book_producers(root, read_prefixes(root), read_refines(root))
Пример #12
0
 def su(root, val):
     set_user_metadata(root, read_prefixes(root), read_refines(root), val)
     return ru(root)
Пример #13
0
 def st(root, val):
     set_tags(root, read_prefixes(root), read_refines(root), val)
     return rt(root)
Пример #14
0
 def st(root, val, i):
     set_series(root, read_prefixes(root), read_refines(root), val, i)
     return rt(root)
Пример #15
0
 def rl(root):
     return read_book_producers(root, read_prefixes(root),
                                read_refines(root))
Пример #16
0
 def st(root, producers):
     set_book_producers(root, read_prefixes(root), read_refines(root),
                        producers)
     return rl(root)
Пример #17
0
 def rl(root):
     return read_authors(root, read_prefixes(root), read_refines(root))
Пример #18
0
 def st(root, authors):
     set_authors(root, read_prefixes(root), read_refines(root), authors)
     return rl(root)
Пример #19
0
 def st(root, languages):
     set_languages(root, read_prefixes(root), read_refines(root),
                   languages)
     return rl(root)
Пример #20
0
 def rl(root):
     return read_languages(root, read_prefixes(root),
                           read_refines(root))
Пример #21
0
 def st(root, title, title_sort=None):
     set_title(root, read_prefixes(root), read_refines(root), title,
               title_sort)
     return rt(root)
Пример #22
0
 def rt(root):
     return read_publisher(root, read_prefixes(root), read_refines(root))
Пример #23
0
 def rl(root):
     return read_pubdate(root, read_prefixes(root),
                         read_refines(root)), read_timestamp(
                             root, read_prefixes(root),
                             read_refines(root))
Пример #24
0
 def rl(root):
     p, r = read_prefixes(root), read_refines(root)
     return read_pubdate(root, p, r), read_timestamp(root, p, r)
Пример #25
0
 def ru(root):
     return read_user_metadata(root, read_prefixes(root),
                               read_refines(root))
Пример #26
0
 def st(root, val):
     set_rating(root, read_prefixes(root), read_refines(root), val)
     return rt(root)
Пример #27
0
 def rl(root):
     return read_languages(root, read_prefixes(root), read_refines(root))
Пример #28
0
 def st(root, name, val):
     f = globals()['set_' + name]
     f(root, read_prefixes(root), read_refines(root), val)
     return rt(root, name)
Пример #29
0
 def rl(root):
     return read_authors(root, read_prefixes(root), read_refines(root))
Пример #30
0
 def st(root, pd, ts):
     set_pubdate(root, read_prefixes(root), read_refines(root), pd)
     set_timestamp(root, read_prefixes(root), read_refines(root), ts)
     return rl(root)
Пример #31
0
 def rl(root):
     p, r = read_prefixes(root), read_refines(root)
     return read_pubdate(root, p, r), read_timestamp(root, p, r)
Пример #32
0
 def su(root, val):
     set_user_metadata(root, read_prefixes(root), read_refines(root),
                       val)
     return ru(root)
Пример #33
0
 def rt(root):
     return read_comments(root, read_prefixes(root), read_refines(root))
Пример #34
0
 def st(root, languages):
     set_languages(root, read_prefixes(root), read_refines(root), languages)
     return rl(root)
Пример #35
0
 def st(root, val):
     set_comments(root, read_prefixes(root), read_refines(root), val)
     return rt(root)
Пример #36
0
 def st(root, authors):
     set_authors(root, read_prefixes(root), read_refines(root), authors)
     return rl(root)
Пример #37
0
 def rt(root):
     return read_publisher(root, read_prefixes(root),
                           read_refines(root))
Пример #38
0
 def st(root, producers):
     set_book_producers(root, read_prefixes(root), read_refines(root), producers)
     return rl(root)
Пример #39
0
 def st(root, val):
     set_publisher(root, read_prefixes(root), read_refines(root), val)
     return rt(root)
Пример #40
0
 def st(root, pd, ts):
     set_pubdate(root, read_prefixes(root), read_refines(root), pd)
     set_timestamp(root, read_prefixes(root), read_refines(root), ts)
     return rl(root)
Пример #41
0
 def rt(root):
     return read_raster_cover(root, read_prefixes(root),
                              read_refines(root))
Пример #42
0
 def st(root, val):
     set_comments(root, read_prefixes(root), read_refines(root), val)
     return rt(root)
Пример #43
0
 def rt(root):
     return read_tags(root, read_prefixes(root), read_refines(root))
Пример #44
0
 def st(root, val):
     set_publisher(root, read_prefixes(root), read_refines(root), val)
     return rt(root)
Пример #45
0
 def st(root, val):
     set_tags(root, read_prefixes(root), read_refines(root), val)
     return rt(root)
Пример #46
0
 def rt(root):
     return read_raster_cover(root, read_prefixes(root), read_refines(root))
Пример #47
0
 def rt(root):
     return read_rating(root, read_prefixes(root), read_refines(root))
Пример #48
0
 def rt(root):
     return read_rating(root, read_prefixes(root), read_refines(root))
Пример #49
0
 def st(root, val):
     set_rating(root, read_prefixes(root), read_refines(root), val)
     return rt(root)
Пример #50
0
 def rt(root):
     return read_series(root, read_prefixes(root), read_refines(root))
Пример #51
0
 def rt(root):
     return read_series(root, read_prefixes(root), read_refines(root))
Пример #52
0
 def rt(root, name):
     f = globals()['read_' + name]
     return f(root, read_prefixes(root), read_refines(root))
Пример #53
0
 def rt(root):
     return read_title(root, read_prefixes(root), read_refines(root))
Пример #54
0
 def ru(root):
     return read_user_metadata(root, read_prefixes(root), read_refines(root))
Пример #55
0
 def st(root, name, val):
     f = globals()['set_' + name]
     f(root, read_prefixes(root), read_refines(root), val)
     return rt(root, name)
Пример #56
0
 def st(root, val, i):
     set_series(root, read_prefixes(root), read_refines(root), val, i)
     return rt(root)
Пример #57
0
 def rt(root):
     return read_title(root, reserved_prefixes, read_refines(root))
Пример #58
0
 def st(root, title, title_sort=None):
     set_title(root, read_prefixes(root), read_refines(root), title, title_sort)
     return rt(root)
Пример #59
0
 def rt(root, name):
     f = globals()['read_' + name]
     return f(root, read_prefixes(root), read_refines(root))