~ubuntu-branches/ubuntu/karmic/calibre/karmic-updates

« back to all changes in this revision

Viewing changes to src/calibre/ebooks/metadata/opf2.py

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2009-04-05 18:42:16 UTC
  • mfrom: (1.1.7 sid)
  • Revision ID: james.westby@ubuntu.com-20090405184216-cyb0x4edrwjcaw33
Tags: 0.5.9+dfsg-1
* New upstream release. (Closes: #525339)
* manpages-installation.patch: Encode generated manpages as UTF-8, to avoid
  UnicodeDecodeErrors when writing them out to files.
* debian/control: Demote calibre dependency of calibre-bin to Recommends:,
  which is sufficient and avoids a circular dependency. (Closes: #522059)
* debian/control: Drop build dependency help2man, current version does not
  need it any more.
* debian/control: Drop versioned build dependency on python-mechanize,
  current sid version is enough.
* debian/rules: Copy "setup.py install" command from cdbs'
  python-distutils.mk, since the current version broke this. This is a
  hackish workaround until #525436 gets fixed.
* debian/rules: Drop using $(wildcard ), use `ls`; the former does not work
  any more.

Show diffs side-by-side

added added

removed removed

Lines of Context:
258
258
            if i.id == id:
259
259
                return i.path
260
260
 
 
261
    def type_for_id(self, id):
 
262
        for i in self:
 
263
            if i.id == id:
 
264
                return i.mime_type
 
265
 
261
266
class Spine(ResourceCollection):
262
267
 
263
268
    class Item(Resource):
444
449
        if not hasattr(stream, 'read'):
445
450
            stream = open(stream, 'rb')
446
451
        self.basedir  = self.base_dir = basedir
 
452
        self.path_to_html_toc = self.html_toc_fragment = None
447
453
        raw, self.encoding = xml_to_unicode(stream.read(), strip_encoding_pats=True, resolve_entities=True)
448
454
        raw = raw[raw.find('<'):]
449
455
        self.root     = etree.fromstring(raw, self.PARSER)
486
492
 
487
493
            if toc is None: return
488
494
            self.toc = TOC(base_path=self.base_dir)
489
 
            if toc.lower() in ('ncx', 'ncxtoc'):
 
495
            is_ncx = getattr(self, 'manifest', None) is not None and \
 
496
                     self.manifest.type_for_id(toc) is not None and \
 
497
                     'dtbncx' in self.manifest.type_for_id(toc)
 
498
            if is_ncx or toc.lower() in ('ncx', 'ncxtoc'):
490
499
                path = self.manifest.path_for_id(toc)
491
500
                if path:
492
501
                    self.toc.read_ncx_toc(path)
495
504
                    if f:
496
505
                        self.toc.read_ncx_toc(f[0])
497
506
            else:
 
507
                self.path_to_html_toc, self.html_toc_fragment = \
 
508
                    toc.partition('#')[0], toc.partition('#')[-1]
498
509
                self.toc.read_html_toc(toc)
499
510
        except:
500
511
            pass
501
512
 
502
 
 
503
 
 
504
513
    def get_text(self, elem):
505
514
        return u''.join(self.CONTENT(elem) or self.TEXT(elem))
506
515
 
625
634
                attrib = {'{%s}role'%self.NAMESPACES['opf']: 'aut'}
626
635
                elem = self.create_metadata_element('creator', attrib=attrib)
627
636
                self.set_text(elem, author.strip())
628
 
            
 
637
 
629
638
        return property(fget=fget, fset=fset)
630
639
 
631
640
    @apply