Codebase list sugar-read-activity / 8c1272d
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
1 changed file(s) with 10 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
2626
2727
2828 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
3135 self._zobject = None
3236 self._opfpath = None
3337 self._ncxpath = None
106110 Method to crudely check to verify that what we
107111 are dealing with is a epub file or not
108112 '''
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
111116
112 self._zobject = zipfile.ZipFile(self._filepath)
117 self._zobject = zipfile.ZipFile(self._file)
113118
114119 if not 'mimetype' in self._zobject.namelist():
115120 return False