def read_opf_metadata (filename, metadata=None): if metadata is None: metadata = Metadata(OPF2) read_file_metadata(filename, metadata) with closing(open(filename, 'r')) as stream: metadata.opf = parse_opf_xml(stream.read()) return metadata
def read_pdb_metadata(filename, metadata=None): if metadata is None: metadata = Metadata(None) read_file_metadata(filename, metadata) with closing(open(filename, "rb")) as stream: metadata.pdb = _parse_pdb_header(stream) return metadata
def read_epub_metadata (filename, metadata=None): if metadata is None: metadata = Metadata(EPUB2) read_file_metadata(filename, metadata) reader = zip_reader(filename) try: container = _parse_container_xml(reader(CONTAINER_PATH)) except KeyError: raise EPubException('missing OCF container.xml') try: metadata.opf = parse_opf_xml(reader(container[OPF2.mimetype])) except KeyError: raise EPubException('missing OPF package file') return metadata