diff --git a/ebooklib/epub.py b/ebooklib/epub.py index faa516f..95d39f0 100644 --- a/ebooklib/epub.py +++ b/ebooklib/epub.py @@ -129,7 +129,7 @@ def __init__(self, uid=None, file_name='', media_type='', content=six.b(''), man - manifest: Manifest for this item (optional) """ self.id = uid - self.file_name = file_name + self._file_name = file_name self.media_type = media_type self.content = content self.is_linear = True @@ -155,6 +155,24 @@ def get_name(self): """ return self.file_name + @property + def file_name(self): + # To support Python 2 Unicode path, file_name should be decoded. + # And because file_name is a public member previously, + # so decoding lies here instead of construction. + if isinstance(self._file_name, bytes): + return self._file_name.decode("utf-8") + else: + return self._file_name + + @file_name.setter + def file_name(self, value): + self._file_name = value + + @file_name.deleter + def file_name(self): + del self._file_name + def get_type(self): """ Guess type according to the file extension. Might not be the best way how to do it, but it works for now.