Modify epub to open file objects
Epub class could be created with a path to a file,
now can be either a path to a file (a string) or a file-like object.
This change was added in the Pathagar project.
Not used here yet, but is useful keep the library updated
Gonzalo Odiard
9 years ago
26 | 26 | |
27 | 27 | |
28 | 28 | class _Epub(object): |
29 | def __init__(self, filepath): | |
30 | self._filepath = filepath | |
29 | ||
30 | def __init__(self, _file): | |
31 | """ | |
32 | _file: can be either a path to a file (a string) or a file-like object. | |
33 | """ | |
34 | self._file = _file | |
31 | 35 | self._zobject = None |
32 | 36 | self._opfpath = None |
33 | 37 | self._ncxpath = None |
106 | 110 | Method to crudely check to verify that what we |
107 | 111 | are dealing with is a epub file or not |
108 | 112 | ''' |
109 | if not os.path.exists(self._filepath): | |
110 | return False | |
113 | if isinstance(self._file, basestring): | |
114 | if not os.path.exists(self._file): | |
115 | return False | |
111 | 116 | |
112 | self._zobject = zipfile.ZipFile(self._filepath) | |
117 | self._zobject = zipfile.ZipFile(self._file) | |
113 | 118 | |
114 | 119 | if not 'mimetype' in self._zobject.namelist(): |
115 | 120 | return False |