mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
py3: more work towards enforce all __future__s everywhere
This commit is contained in:
parent
f915f11a0c
commit
f2e0181926
@ -1,4 +1,5 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||||
|
|
||||||
'''
|
'''
|
||||||
Read content from azw4 file.
|
Read content from azw4 file.
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
#!/usr/bin/env python2
|
#!/usr/bin/env python2
|
||||||
|
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||||
|
|
||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
__copyright__ = '2008, Kovid Goyal kovid@kovidgoyal.net'
|
__copyright__ = '2008, Kovid Goyal kovid@kovidgoyal.net'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env python2
|
#!/usr/bin/env python2
|
||||||
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
|
# 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'
|
__license__ = 'GPL v3'
|
||||||
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||||
@ -18,11 +18,11 @@ from polyglot.builtins import iterkeys
|
|||||||
|
|
||||||
|
|
||||||
def _clean(s):
|
def _clean(s):
|
||||||
return s.replace(u'\u00a0', u' ')
|
return s.replace('\u00a0', ' ')
|
||||||
|
|
||||||
|
|
||||||
def _detag(tag):
|
def _detag(tag):
|
||||||
ans = u""
|
ans = ""
|
||||||
if tag is None:
|
if tag is None:
|
||||||
return ans
|
return ans
|
||||||
for elem in tag:
|
for elem in tag:
|
||||||
@ -77,10 +77,10 @@ def _get_comments(soup):
|
|||||||
pages = (_metadata_from_span(soup, 'pages') or _metadata_from_table(soup, 'pages'))
|
pages = (_metadata_from_span(soup, 'pages') or _metadata_from_table(soup, 'pages'))
|
||||||
try:
|
try:
|
||||||
# date span can have copyright symbols in it...
|
# 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)'
|
# and pages often comes as '(\d+ pages)'
|
||||||
pages = re.search(r'\d+', pages).group(0)
|
pages = re.search(r'\d+', pages).group(0)
|
||||||
return u'Published %s, %s pages.' % (date, pages)
|
return 'Published %s, %s pages.' % (date, pages)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
return None
|
return None
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
from __future__ import with_statement
|
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||||
|
|
||||||
''' CHM File decoding support '''
|
''' CHM File decoding support '''
|
||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>,' \
|
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>,' \
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
#!/usr/bin/env python2
|
#!/usr/bin/env python2
|
||||||
|
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||||
|
|
||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
__copyright__ = '2008, Kovid Goyal kovid@kovidgoyal.net'
|
__copyright__ = '2008, Kovid Goyal kovid@kovidgoyal.net'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
from __future__ import with_statement
|
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||||
|
|
||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
__copyright__ = '2008, Kovid Goyal kovid@kovidgoyal.net'
|
__copyright__ = '2008, Kovid Goyal kovid@kovidgoyal.net'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
@ -105,7 +106,7 @@ class PageProcessor(list): # {{{
|
|||||||
if self.opts.landscape:
|
if self.opts.landscape:
|
||||||
self.rotate = True
|
self.rotate = True
|
||||||
else:
|
else:
|
||||||
half = int(width/2)
|
half = width // 2
|
||||||
split1 = crop_image(img, 0, 0, half, height)
|
split1 = crop_image(img, 0, 0, half, height)
|
||||||
split2 = crop_image(img, half, 0, width - half, height)
|
split2 = crop_image(img, half, 0, width - half, height)
|
||||||
self.pages = [split2, split1] if self.opts.right2left else [split1, split2]
|
self.pages = [split2, split1] if self.opts.right2left else [split1, split2]
|
||||||
@ -144,13 +145,13 @@ class PageProcessor(list): # {{{
|
|||||||
if aspect <= (float(SCRWIDTH) / float(SCRHEIGHT)):
|
if aspect <= (float(SCRWIDTH) / float(SCRHEIGHT)):
|
||||||
newsizey = SCRHEIGHT
|
newsizey = SCRHEIGHT
|
||||||
newsizex = int(newsizey * aspect)
|
newsizex = int(newsizey * aspect)
|
||||||
deltax = (SCRWIDTH - newsizex) / 2
|
deltax = (SCRWIDTH - newsizex) // 2
|
||||||
deltay = 0
|
deltay = 0
|
||||||
else:
|
else:
|
||||||
newsizex = SCRWIDTH
|
newsizex = SCRWIDTH
|
||||||
newsizey = int(newsizex / aspect)
|
newsizey = int(newsizex // aspect)
|
||||||
deltax = 0
|
deltax = 0
|
||||||
deltay = (SCRHEIGHT - newsizey) / 2
|
deltay = (SCRHEIGHT - newsizey) // 2
|
||||||
if newsizex < MAX_SCREEN_SIZE and newsizey < MAX_SCREEN_SIZE:
|
if newsizex < MAX_SCREEN_SIZE and newsizey < MAX_SCREEN_SIZE:
|
||||||
# Too large and resizing fails, so better
|
# Too large and resizing fails, so better
|
||||||
# to leave it as original size
|
# to leave it as original size
|
||||||
@ -163,17 +164,17 @@ class PageProcessor(list): # {{{
|
|||||||
# Get dimensions of the landscape mode screen
|
# Get dimensions of the landscape mode screen
|
||||||
# Add 25px back to height for the battery bar.
|
# Add 25px back to height for the battery bar.
|
||||||
wscreenx = SCRHEIGHT + 25
|
wscreenx = SCRHEIGHT + 25
|
||||||
wscreeny = int(wscreenx / screen_aspect)
|
wscreeny = int(wscreenx // screen_aspect)
|
||||||
if aspect <= screen_aspect:
|
if aspect <= screen_aspect:
|
||||||
newsizey = wscreeny
|
newsizey = wscreeny
|
||||||
newsizex = int(newsizey * aspect)
|
newsizex = int(newsizey * aspect)
|
||||||
deltax = (wscreenx - newsizex) / 2
|
deltax = (wscreenx - newsizex) // 2
|
||||||
deltay = 0
|
deltay = 0
|
||||||
else:
|
else:
|
||||||
newsizex = wscreenx
|
newsizex = wscreenx
|
||||||
newsizey = int(newsizex / aspect)
|
newsizey = int(newsizex // aspect)
|
||||||
deltax = 0
|
deltax = 0
|
||||||
deltay = (wscreeny - newsizey) / 2
|
deltay = (wscreeny - newsizey) // 2
|
||||||
if newsizex < MAX_SCREEN_SIZE and newsizey < MAX_SCREEN_SIZE:
|
if newsizex < MAX_SCREEN_SIZE and newsizey < MAX_SCREEN_SIZE:
|
||||||
# Too large and resizing fails, so better
|
# Too large and resizing fails, so better
|
||||||
# to leave it as original size
|
# to leave it as original size
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||||
|
|
||||||
__license__ = 'GPL 3'
|
__license__ = 'GPL 3'
|
||||||
__copyright__ = '2009, John Schember <john@nachtimwald.com>'
|
__copyright__ = '2009, John Schember <john@nachtimwald.com>'
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env python2
|
#!/usr/bin/env python2
|
||||||
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
|
# 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'
|
__license__ = 'GPL v3'
|
||||||
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||||
|
|
||||||
@ -22,7 +22,7 @@ def decompress_doc(data):
|
|||||||
|
|
||||||
def compress_doc(data):
|
def compress_doc(data):
|
||||||
if not data:
|
if not data:
|
||||||
return u''
|
return ''
|
||||||
return cPalmdoc.compress(data)
|
return cPalmdoc.compress(data)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
from __future__ import with_statement
|
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||||
|
|
||||||
__license__ = 'GPL 3'
|
__license__ = 'GPL 3'
|
||||||
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
@ -352,7 +353,7 @@ def read_sr_patterns(path, log=None):
|
|||||||
try:
|
try:
|
||||||
re.compile(line)
|
re.compile(line)
|
||||||
except:
|
except:
|
||||||
msg = u'Invalid regular expression: %r from file: %r'%(
|
msg = 'Invalid regular expression: %r from file: %r'%(
|
||||||
line, path)
|
line, path)
|
||||||
if log is not None:
|
if log is not None:
|
||||||
log.error(msg)
|
log.error(msg)
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env python2
|
#!/usr/bin/env python2
|
||||||
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
|
# 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'
|
__license__ = 'GPL v3'
|
||||||
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#!/usr/bin/env python2
|
#!/usr/bin/env python2
|
||||||
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
|
# 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'
|
__license__ = 'GPL v3'
|
||||||
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||||
@ -329,7 +330,7 @@ class HeuristicProcessor(object):
|
|||||||
|
|
||||||
words_per_chptr = wordcount
|
words_per_chptr = wordcount
|
||||||
if words_per_chptr > 0 and self.html_preprocess_sections > 0:
|
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: "+
|
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")
|
unicode_type(words_per_chptr)+", Marked up "+unicode_type(self.html_preprocess_sections)+" chapters")
|
||||||
return html
|
return html
|
||||||
@ -361,13 +362,13 @@ class HeuristicProcessor(object):
|
|||||||
|
|
||||||
# define the pieces of the regex
|
# define the pieces of the regex
|
||||||
# (?<!\&\w{4});) is a semicolon not part of an entity
|
# (?<!\&\w{4});) is a semicolon not part of an entity
|
||||||
lookahead = "(?<=.{"+unicode_type(length)+u"}([a-zა-ჰäëïöüàèìòùáćéíĺóŕńśúýâêîôûçąężıãõñæøþðßěľščťžňďřů,:)\\IA\u00DF]|(?<!\\&\\w{4});))"
|
lookahead = "(?<=.{"+unicode_type(length)+"}([a-zა-ჰäëïöüàèìòùáćéíĺóŕńśúýâêîôûçąężıãõñæøþðßěľščťžňďřů,:)\\IA\u00DF]|(?<!\\&\\w{4});))"
|
||||||
em_en_lookahead = "(?<=.{"+unicode_type(length)+u"}[\u2013\u2014])"
|
em_en_lookahead = "(?<=.{"+unicode_type(length)+"}[\u2013\u2014])"
|
||||||
soft_hyphen = u"\xad"
|
soft_hyphen = "\xad"
|
||||||
line_ending = "\\s*(?P<style_close></(span|[iub])>)?\\s*(</(p|div)>)?"
|
line_ending = "\\s*(?P<style_close></(span|[iub])>)?\\s*(</(p|div)>)?"
|
||||||
blanklines = "\\s*(?P<up2threeblanks><(p|span|div)[^>]*>\\s*(<(p|span|div)[^>]*>\\s*</(span|p|div)>\\s*)</(span|p|div)>\\s*){0,3}\\s*"
|
blanklines = "\\s*(?P<up2threeblanks><(p|span|div)[^>]*>\\s*(<(p|span|div)[^>]*>\\s*</(span|p|div)>\\s*)</(span|p|div)>\\s*){0,3}\\s*"
|
||||||
line_opening = "<(p|div)[^>]*>\\s*(?P<style_open><(span|[iub])[^>]*>)?\\s*"
|
line_opening = "<(p|div)[^>]*>\\s*(?P<style_open><(span|[iub])[^>]*>)?\\s*"
|
||||||
txt_line_wrap = u"((\u0020|\u0009)*\n){1,4}"
|
txt_line_wrap = "((\u0020|\u0009)*\n){1,4}"
|
||||||
|
|
||||||
if format == 'txt':
|
if format == 'txt':
|
||||||
unwrap_regex = lookahead+txt_line_wrap
|
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
|
em_en_unwrap_regex = em_en_lookahead+line_ending+blanklines+line_opening
|
||||||
shy_unwrap_regex = soft_hyphen+line_ending+blanklines+line_opening
|
shy_unwrap_regex = soft_hyphen+line_ending+blanklines+line_opening
|
||||||
|
|
||||||
unwrap = re.compile(u"%s" % unwrap_regex, re.UNICODE)
|
unwrap = re.compile("%s" % unwrap_regex, re.UNICODE)
|
||||||
em_en_unwrap = re.compile(u"%s" % em_en_unwrap_regex, re.UNICODE)
|
em_en_unwrap = re.compile("%s" % em_en_unwrap_regex, re.UNICODE)
|
||||||
shy_unwrap = re.compile(u"%s" % shy_unwrap_regex, re.UNICODE)
|
shy_unwrap = re.compile("%s" % shy_unwrap_regex, re.UNICODE)
|
||||||
|
|
||||||
if format == 'txt':
|
if format == 'txt':
|
||||||
content = unwrap.sub(' ', content)
|
content = unwrap.sub(' ', content)
|
||||||
@ -599,7 +600,7 @@ class HeuristicProcessor(object):
|
|||||||
' expression, using default')
|
' expression, using default')
|
||||||
else:
|
else:
|
||||||
replacement_break = re.sub('(?i)(width=\\d+\\%?|width:\\s*\\d+(\\%|px|pt|em)?;?)', '', replacement_break)
|
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)
|
hr_open = re.sub('45', unicode_type(divpercent), hr_open)
|
||||||
scene_break = hr_open+replacement_break+'</div>'
|
scene_break = hr_open+replacement_break+'</div>'
|
||||||
else:
|
else:
|
||||||
@ -865,5 +866,5 @@ class HeuristicProcessor(object):
|
|||||||
|
|
||||||
if self.deleted_nbsps:
|
if self.deleted_nbsps:
|
||||||
# put back non-breaking spaces in empty paragraphs so they render correctly
|
# put back non-breaking spaces in empty paragraphs so they render correctly
|
||||||
html = self.anyblank.sub('\n'+r'\g<openline>'+u'\u00a0'+r'\g<closeline>', html)
|
html = self.anyblank.sub('\n'+r'\g<openline>'+'\u00a0'+r'\g<closeline>', html)
|
||||||
return html
|
return html
|
||||||
|
Loading…
x
Reference in New Issue
Block a user