Package list sugar-read-activity / d263827
Epub - Port to Python 3 James Cameron 2 years ago
5 changed file(s) with 21 addition(s) and 21 deletion(s). Raw diff Collapse all Expand all
44
55 # import speech
66
7 from cStringIO import StringIO
7 from io import StringIO
88
99 _logger = logging.getLogger('read-activity')
1010
5050
5151 def update_metadata(self, activity):
5252 self.metadata = activity.metadata
53 self.metadata['Read_zoom'] = self.get_zoom()
53 self.metadata['Read_zoom'] = str(self.get_zoom())
5454
5555 def zoom_to_width(self):
5656 pass
1414 # along with this program; if not, write to the Free Software
1515 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1616
17 from epub import _Epub as Epub
18 from epubview import _View as EpubView
19 from jobs import _JobFind as JobFind
17 from .epub import _Epub as Epub
18 from .epubview import _View as EpubView
19 from .jobs import _JobFind as JobFind
2121 import shutil
2222 import logging
2323
24 import navmap
25 import epubinfo
24 from . import navmap
25 from . import epubinfo
2626
2727
2828 class _Epub(object):
3939 self._tempdir = tempfile.mkdtemp()
4040
4141 if not self._verify():
42 print 'Warning: This does not seem to be a valid epub file'
42 print('Warning: This does not seem to be a valid epub file')
4343
4444 self._get_opf()
4545 self._get_ncx()
110110 Method to crudely check to verify that what we
111111 are dealing with is a epub file or not
112112 '''
113 if isinstance(self._file, basestring):
113 if isinstance(self._file, str):
114114 if not os.path.exists(self._file):
115115 return False
116116
123123 mimetype = mtypefile.readline()
124124
125125 # Some files seem to have trailing characters
126 if not mimetype.startswith('application/epub+zip'):
126 if not mimetype.startswith(b'application/epub+zip'):
127127 return False
128128
129129 return True
2222 from gi.repository import GObject
2323 from gi.repository import Gdk
2424 from gi.repository import WebKit2
25 import widgets
25 from . import widgets
2626
2727 import logging
2828 import os.path
2929 import math
3030 import shutil
3131
32 from jobs import _JobPaginator as _Paginator
32 from .jobs import _JobPaginator as _Paginator
3333
3434 LOADING_HTML = '''
3535 <html style="height: 100%; margin: 0; padding: 0; width: 100%;">
483483 j = 0
484484 word_begin = 0
485485 word_end = 0
486 ignore_chars = [' ', '\n', u'\r', '_', '[', '{', ']', '}', '|',
486 ignore_chars = [' ', '\n', '\r', '_', '[', '{', ']', '}', '|',
487487 '<', '>', '*', '+', '/', '\\']
488488 ignore_set = set(ignore_chars)
489489 self.word_tuples = []
498498 i = j
499499 word_tuple = (word_begin, word_end,
500500 page_text[word_begin: word_end])
501 if word_tuple[2] != u'\r':
501 if word_tuple[2] != '\r':
502502 self.word_tuples.append(word_tuple)
503503 i = i + 1
504504
624624 else:
625625 self._load_page(int(value))
626626 else:
627 print 'Warning: unknown scrolltype %s with value %f' \
628 % (str(scrolltype), value)
627 print('Warning: unknown scrolltype %s with value %f' \
628 % (str(scrolltype), value))
629629
630630 # FIXME: This should not be needed here
631631 self._scrollbar.set_value(self._loaded_page)
2222 from gi.repository import Gtk
2323 from gi.repository import Gdk
2424 from gi.repository import WebKit2
25 import widgets
25 from . import widgets
2626 import math
2727 import os.path
2828 import xml.etree.ElementTree as etree
29 import htmlentitydefs as html_entities
29 import html.entities as html_entities
3030
3131 import threading
3232
6868
6969 def _searchfile(self, fileobj):
7070 parser = etree.XMLParser(html=1)
71 for name, codepoint in html_entities.name2codepoint.iteritems():
72 parser.entity[name] = unichr(codepoint)
71 for name, codepoint in html_entities.name2codepoint.items():
72 parser.entity[name] = chr(codepoint)
7373 tree = etree.parse(fileobj, parser=parser)
7474 root = tree.getroot()
7575
229229 '''
230230 Returns the pageno which begins in filename
231231 '''
232 for key in self._pagemap.keys():
232 for key in list(self._pagemap.keys()):
233233 if self._pagemap[key][0].replace('file://', '') == filename:
234234 return key
235235