home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2010 November / maximum-cd-2010-11.iso / DiscContents / calibre-0.7.13.msi / file_959 (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2010-08-06  |  1.5 KB  |  55 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. __license__ = 'GPL v3'
  5. __copyright__ = '2008, Ashish Kulkarni <kulkarni.ashish@gmail.com>'
  6. import sys
  7. from calibre.ebooks.metadata import MetaInformation, string_to_authors
  8. MAGIC = [
  9.     '\x00\x01BOOKDOUG',
  10.     '\x00\x02BOOKDOUG']
  11.  
  12. def get_metadata(stream):
  13.     title = 'Unknown'
  14.     mi = MetaInformation(title, [
  15.         'Unknown'])
  16.     stream.seek(0)
  17.     
  18.     try:
  19.         if stream.read(10) not in MAGIC:
  20.             print >>sys.stderr, u"Couldn't read IMP header from file"
  21.             return mi
  22.         
  23.         def cString(skip = (0,)):
  24.             result = ''
  25.             while None:
  26.                 data = stream.read(1)
  27.                 if data == '\x00':
  28.                     if not skip:
  29.                         return result
  30.                     skip -= 1
  31.                     (result, data) = ('', '')
  32.                 
  33.                 result += data
  34.                 continue
  35.                 return None
  36.  
  37.         stream.read(38)
  38.         (_, category, title, author) = (cString(), cString(), cString(1), cString(2))
  39.         if title:
  40.             mi.title = title
  41.         
  42.         if author:
  43.             mi.authors = string_to_authors(author)
  44.             mi.author = author
  45.         
  46.         if category:
  47.             mi.category = category
  48.     except Exception:
  49.         err = None
  50.         msg = u"Couldn't read metadata from imp: %s with error %s" % (mi.title, unicode(err))
  51.         print >>sys.stderr, msg.encode('utf8')
  52.  
  53.     return mi
  54.  
  55.