diff --git a/src/calibre/ebooks/pdf/pageoptions.py b/src/calibre/ebooks/pdf/pageoptions.py index 4cc3effe86..fd63da24f7 100644 --- a/src/calibre/ebooks/pdf/pageoptions.py +++ b/src/calibre/ebooks/pdf/pageoptions.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*- +from __future__ import absolute_import, division, print_function, unicode_literals + __license__ = 'GPL 3' __copyright__ = '2009, John Schember ' __docformat__ = 'restructuredtext en' @@ -72,5 +74,5 @@ def orientation(orientation): def size(size): try: return int(size) - except: + except Exception: return 1 diff --git a/src/calibre/ebooks/textile/__init__.py b/src/calibre/ebooks/textile/__init__.py index 1acbfc38fc..5a0a767bd2 100644 --- a/src/calibre/ebooks/textile/__init__.py +++ b/src/calibre/ebooks/textile/__init__.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import, division, print_function, unicode_literals from .functions import textile, textile_restricted, Textile if False: diff --git a/src/calibre/ebooks/textile/functions.py b/src/calibre/ebooks/textile/functions.py index a6bfca0488..49025a3ecc 100644 --- a/src/calibre/ebooks/textile/functions.py +++ b/src/calibre/ebooks/textile/functions.py @@ -1,5 +1,6 @@ #!/usr/bin/env python2 # -*- coding: utf-8 -*- +from __future__ import absolute_import, division, print_function, unicode_literals """ PyTextile @@ -64,6 +65,7 @@ import re import uuid from calibre.utils.smartypants import smartyPants +from polyglot.builtins import unicode_type from polyglot.urllib import urlopen, urlparse @@ -694,7 +696,7 @@ class Textile(object): def footnoteID(self, match): id, t = match.groups() if id not in self.fn: - self.fn[id] = str(uuid.uuid4()) + self.fn[id] = unicode_type(uuid.uuid4()) fnid = self.fn[id] if not t: t = '' @@ -799,7 +801,7 @@ class Textile(object): return url def shelve(self, text): - id = str(uuid.uuid4()) + 'c' + id = unicode_type(uuid.uuid4()) + 'c' self.shelf[id] = text return id diff --git a/src/calibre/ebooks/textile/unsmarten.py b/src/calibre/ebooks/textile/unsmarten.py index 1762e91764..ff05227842 100644 --- a/src/calibre/ebooks/textile/unsmarten.py +++ b/src/calibre/ebooks/textile/unsmarten.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL 3' __copyright__ = '2011, Leigh Parry ' diff --git a/src/calibre/translations/__init__.py b/src/calibre/translations/__init__.py index c03c4930f0..4f77912913 100644 --- a/src/calibre/translations/__init__.py +++ b/src/calibre/translations/__init__.py @@ -1,4 +1,4 @@ -from __future__ import print_function +from __future__ import absolute_import, division, print_function, unicode_literals __license__ = 'GPL v3' __copyright__ = '2008, Kovid Goyal ' ''' diff --git a/src/calibre/translations/dynamic.py b/src/calibre/translations/dynamic.py index 2db1c52815..37210c67cb 100644 --- a/src/calibre/translations/dynamic.py +++ b/src/calibre/translations/dynamic.py @@ -1,3 +1,4 @@ +from __future__ import absolute_import, division, print_function, unicode_literals ''' Dynamic language lookup of translations for user-visible strings. ''' @@ -26,7 +27,7 @@ def translate(lang, text): allow_user_override=False), 'r') as zf: try: buf = io.BytesIO(zf.read(mpath + '/messages.mo')) - except: + except Exception: pass else: trans = GNUTranslations(buf) diff --git a/src/calibre/translations/msgfmt.py b/src/calibre/translations/msgfmt.py index 0bbb521663..b840241076 100644 --- a/src/calibre/translations/msgfmt.py +++ b/src/calibre/translations/msgfmt.py @@ -1,5 +1,6 @@ #!/usr/bin/env python2 # Written by Martin v. Loewis +from __future__ import absolute_import, division, print_function, unicode_literals """Generate binary message catalog from textual translation description. @@ -44,11 +45,11 @@ def usage(code, msg=''): sys.exit(code) -def add(id, str, fuzzy): +def add(id, s, fuzzy): "Add a non-fuzzy translation to the dictionary." global MESSAGES - if not fuzzy and str: - MESSAGES[id] = str + if not fuzzy and s: + MESSAGES[id] = s if id: STATS['translated'] += 1 else: @@ -59,7 +60,7 @@ def add(id, str, fuzzy): def generate(): "Return the generated output." global MESSAGES - keys = MESSAGES.keys() + keys = list(MESSAGES) # the keys are sorted in the .mo file keys.sort() offsets = [] @@ -93,8 +94,8 @@ def generate(): 7*4+len(keys)*8, # start of value index 0, 0) # size and offset of hash table output += array.array("i", offsets).tostring() - output += ids - output += strs + output += ids.encode('utf-8') + output += strs.encode('utf-8') return output @@ -123,6 +124,7 @@ def make(filename, outfile): lno = 0 msgid = msgstr = '' for l in lines: + l = l.decode('utf-8') lno += 1 # If we get a comment line after a msgstr, this is a new entry if l[0] == '#' and section == STR: