Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Python 2 Unicode path #237

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion ebooklib/epub.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down