mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
py3: more unicode porting
This commit is contained in:
parent
216a5c2758
commit
d39087a356
@ -1,4 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||
|
||||
__license__ = 'GPL 3'
|
||||
__copyright__ = '2009, John Schember <john@nachtimwald.com>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
@ -72,5 +74,5 @@ def orientation(orientation):
|
||||
def size(size):
|
||||
try:
|
||||
return int(size)
|
||||
except:
|
||||
except Exception:
|
||||
return 1
|
||||
|
@ -1,3 +1,4 @@
|
||||
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||
from .functions import textile, textile_restricted, Textile
|
||||
|
||||
if False:
|
||||
|
@ -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
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||
|
||||
__license__ = 'GPL 3'
|
||||
__copyright__ = '2011, Leigh Parry <leighparry@blueyonder.co.uk>'
|
||||
|
@ -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 <kovid at kovidgoyal.net>'
|
||||
'''
|
||||
|
@ -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)
|
||||
|
@ -1,5 +1,6 @@
|
||||
#!/usr/bin/env python2
|
||||
# Written by Martin v. Loewis <loewis@informatik.hu-berlin.de>
|
||||
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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user