diff --git a/src/calibre/ebooks/azw4/reader.py b/src/calibre/ebooks/azw4/reader.py index 1446cd6a7f..6726e7b32d 100644 --- a/src/calibre/ebooks/azw4/reader.py +++ b/src/calibre/ebooks/azw4/reader.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +from __future__ import absolute_import, division, print_function, unicode_literals ''' Read content from azw4 file. diff --git a/src/calibre/ebooks/chm/__init__.py b/src/calibre/ebooks/chm/__init__.py index 72c19ade11..3a23b123d8 100644 --- a/src/calibre/ebooks/chm/__init__.py +++ b/src/calibre/ebooks/chm/__init__.py @@ -1,4 +1,6 @@ #!/usr/bin/env python2 +from __future__ import absolute_import, division, print_function, unicode_literals + __license__ = 'GPL v3' __copyright__ = '2008, Kovid Goyal kovid@kovidgoyal.net' __docformat__ = 'restructuredtext en' diff --git a/src/calibre/ebooks/chm/metadata.py b/src/calibre/ebooks/chm/metadata.py index a822428fde..0a1ad627b3 100644 --- a/src/calibre/ebooks/chm/metadata.py +++ b/src/calibre/ebooks/chm/metadata.py @@ -1,6 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai -from __future__ import with_statement +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' @@ -18,11 +18,11 @@ from polyglot.builtins import iterkeys def _clean(s): - return s.replace(u'\u00a0', u' ') + return s.replace('\u00a0', ' ') def _detag(tag): - ans = u"" + ans = "" if tag is None: return ans for elem in tag: @@ -77,10 +77,10 @@ def _get_comments(soup): pages = (_metadata_from_span(soup, 'pages') or _metadata_from_table(soup, 'pages')) try: # date span can have copyright symbols in it... - date = date.replace(u'\u00a9', '').strip() + date = date.replace('\u00a9', '').strip() # and pages often comes as '(\d+ pages)' pages = re.search(r'\d+', pages).group(0) - return u'Published %s, %s pages.' % (date, pages) + return 'Published %s, %s pages.' % (date, pages) except: pass return None diff --git a/src/calibre/ebooks/chm/reader.py b/src/calibre/ebooks/chm/reader.py index b3f60ec868..a8be20c360 100644 --- a/src/calibre/ebooks/chm/reader.py +++ b/src/calibre/ebooks/chm/reader.py @@ -1,4 +1,5 @@ -from __future__ import with_statement +from __future__ import absolute_import, division, print_function, unicode_literals + ''' CHM File decoding support ''' __license__ = 'GPL v3' __copyright__ = '2008, Kovid Goyal ,' \ diff --git a/src/calibre/ebooks/comic/__init__.py b/src/calibre/ebooks/comic/__init__.py index b7738cb2dc..9a7f3dadda 100644 --- a/src/calibre/ebooks/comic/__init__.py +++ b/src/calibre/ebooks/comic/__init__.py @@ -1,4 +1,6 @@ #!/usr/bin/env python2 +from __future__ import absolute_import, division, print_function, unicode_literals + __license__ = 'GPL v3' __copyright__ = '2008, Kovid Goyal kovid@kovidgoyal.net' __docformat__ = 'restructuredtext en' diff --git a/src/calibre/ebooks/comic/input.py b/src/calibre/ebooks/comic/input.py index 25ff18572f..8512b30b97 100644 --- a/src/calibre/ebooks/comic/input.py +++ b/src/calibre/ebooks/comic/input.py @@ -1,4 +1,5 @@ -from __future__ import with_statement +from __future__ import absolute_import, division, print_function, unicode_literals + __license__ = 'GPL v3' __copyright__ = '2008, Kovid Goyal kovid@kovidgoyal.net' __docformat__ = 'restructuredtext en' @@ -105,7 +106,7 @@ class PageProcessor(list): # {{{ if self.opts.landscape: self.rotate = True else: - half = int(width/2) + half = width // 2 split1 = crop_image(img, 0, 0, half, height) split2 = crop_image(img, half, 0, width - half, height) self.pages = [split2, split1] if self.opts.right2left else [split1, split2] @@ -144,13 +145,13 @@ class PageProcessor(list): # {{{ if aspect <= (float(SCRWIDTH) / float(SCRHEIGHT)): newsizey = SCRHEIGHT newsizex = int(newsizey * aspect) - deltax = (SCRWIDTH - newsizex) / 2 + deltax = (SCRWIDTH - newsizex) // 2 deltay = 0 else: newsizex = SCRWIDTH - newsizey = int(newsizex / aspect) + newsizey = int(newsizex // aspect) deltax = 0 - deltay = (SCRHEIGHT - newsizey) / 2 + deltay = (SCRHEIGHT - newsizey) // 2 if newsizex < MAX_SCREEN_SIZE and newsizey < MAX_SCREEN_SIZE: # Too large and resizing fails, so better # to leave it as original size @@ -163,17 +164,17 @@ class PageProcessor(list): # {{{ # Get dimensions of the landscape mode screen # Add 25px back to height for the battery bar. wscreenx = SCRHEIGHT + 25 - wscreeny = int(wscreenx / screen_aspect) + wscreeny = int(wscreenx // screen_aspect) if aspect <= screen_aspect: newsizey = wscreeny newsizex = int(newsizey * aspect) - deltax = (wscreenx - newsizex) / 2 + deltax = (wscreenx - newsizex) // 2 deltay = 0 else: newsizex = wscreenx - newsizey = int(newsizex / aspect) + newsizey = int(newsizex // aspect) deltax = 0 - deltay = (wscreeny - newsizey) / 2 + deltay = (wscreeny - newsizey) // 2 if newsizex < MAX_SCREEN_SIZE and newsizey < MAX_SCREEN_SIZE: # Too large and resizing fails, so better # to leave it as original size diff --git a/src/calibre/ebooks/compression/__init__.py b/src/calibre/ebooks/compression/__init__.py index 9e2aad729c..c2b701674a 100644 --- a/src/calibre/ebooks/compression/__init__.py +++ b/src/calibre/ebooks/compression/__init__.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL 3' __copyright__ = '2009, John Schember ' diff --git a/src/calibre/ebooks/compression/palmdoc.py b/src/calibre/ebooks/compression/palmdoc.py index 1027303133..931a2feda4 100644 --- a/src/calibre/ebooks/compression/palmdoc.py +++ b/src/calibre/ebooks/compression/palmdoc.py @@ -1,7 +1,7 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import absolute_import, division, print_function, unicode_literals -from __future__ import print_function __license__ = 'GPL v3' __copyright__ = '2008, Kovid Goyal ' @@ -22,7 +22,7 @@ def decompress_doc(data): def compress_doc(data): if not data: - return u'' + return '' return cPalmdoc.compress(data) diff --git a/src/calibre/ebooks/conversion/cli.py b/src/calibre/ebooks/conversion/cli.py index b8ee11aba5..ce706aea73 100644 --- a/src/calibre/ebooks/conversion/cli.py +++ b/src/calibre/ebooks/conversion/cli.py @@ -1,4 +1,5 @@ -from __future__ import with_statement +from __future__ import absolute_import, division, print_function, unicode_literals + __license__ = 'GPL 3' __copyright__ = '2009, Kovid Goyal ' __docformat__ = 'restructuredtext en' @@ -352,7 +353,7 @@ def read_sr_patterns(path, log=None): try: re.compile(line) except: - msg = u'Invalid regular expression: %r from file: %r'%( + msg = 'Invalid regular expression: %r from file: %r'%( line, path) if log is not None: log.error(msg) diff --git a/src/calibre/ebooks/conversion/config.py b/src/calibre/ebooks/conversion/config.py index 2d9c708cbe..8ec90b9481 100644 --- a/src/calibre/ebooks/conversion/config.py +++ b/src/calibre/ebooks/conversion/config.py @@ -1,6 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai -from __future__ import with_statement +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2009, Kovid Goyal ' diff --git a/src/calibre/ebooks/conversion/utils.py b/src/calibre/ebooks/conversion/utils.py index e7f3b99dbb..85a42f13aa 100644 --- a/src/calibre/ebooks/conversion/utils.py +++ b/src/calibre/ebooks/conversion/utils.py @@ -1,5 +1,6 @@ #!/usr/bin/env python2 # vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' @@ -329,7 +330,7 @@ class HeuristicProcessor(object): words_per_chptr = wordcount if words_per_chptr > 0 and self.html_preprocess_sections > 0: - words_per_chptr = wordcount / self.html_preprocess_sections + words_per_chptr = wordcount // self.html_preprocess_sections self.log.debug("Total wordcount is: "+ unicode_type(wordcount)+", Average words per section is: "+ unicode_type(words_per_chptr)+", Marked up "+unicode_type(self.html_preprocess_sections)+" chapters") return html @@ -361,13 +362,13 @@ class HeuristicProcessor(object): # define the pieces of the regex # (?)?\\s*()?" blanklines = "\\s*(?P<(p|span|div)[^>]*>\\s*(<(p|span|div)[^>]*>\\s*\\s*)\\s*){0,3}\\s*" line_opening = "<(p|div)[^>]*>\\s*(?P<(span|[iub])[^>]*>)?\\s*" - txt_line_wrap = u"((\u0020|\u0009)*\n){1,4}" + txt_line_wrap = "((\u0020|\u0009)*\n){1,4}" if format == 'txt': unwrap_regex = lookahead+txt_line_wrap @@ -378,9 +379,9 @@ class HeuristicProcessor(object): em_en_unwrap_regex = em_en_lookahead+line_ending+blanklines+line_opening shy_unwrap_regex = soft_hyphen+line_ending+blanklines+line_opening - unwrap = re.compile(u"%s" % unwrap_regex, re.UNICODE) - em_en_unwrap = re.compile(u"%s" % em_en_unwrap_regex, re.UNICODE) - shy_unwrap = re.compile(u"%s" % shy_unwrap_regex, re.UNICODE) + unwrap = re.compile("%s" % unwrap_regex, re.UNICODE) + em_en_unwrap = re.compile("%s" % em_en_unwrap_regex, re.UNICODE) + shy_unwrap = re.compile("%s" % shy_unwrap_regex, re.UNICODE) if format == 'txt': content = unwrap.sub(' ', content) @@ -599,7 +600,7 @@ class HeuristicProcessor(object): ' expression, using default') else: replacement_break = re.sub('(?i)(width=\\d+\\%?|width:\\s*\\d+(\\%|px|pt|em)?;?)', '', replacement_break) - divpercent = (100 - width) / 2 + divpercent = (100 - width) // 2 hr_open = re.sub('45', unicode_type(divpercent), hr_open) scene_break = hr_open+replacement_break+'' else: @@ -865,5 +866,5 @@ class HeuristicProcessor(object): if self.deleted_nbsps: # put back non-breaking spaces in empty paragraphs so they render correctly - html = self.anyblank.sub('\n'+r'\g'+u'\u00a0'+r'\g', html) + html = self.anyblank.sub('\n'+r'\g'+'\u00a0'+r'\g', html) return html