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 -*-
|
# -*- 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>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
@ -72,5 +74,5 @@ def orientation(orientation):
|
|||||||
def size(size):
|
def size(size):
|
||||||
try:
|
try:
|
||||||
return int(size)
|
return int(size)
|
||||||
except:
|
except Exception:
|
||||||
return 1
|
return 1
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||||
from .functions import textile, textile_restricted, Textile
|
from .functions import textile, textile_restricted, Textile
|
||||||
|
|
||||||
if False:
|
if False:
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#!/usr/bin/env python2
|
#!/usr/bin/env python2
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||||
|
|
||||||
"""
|
"""
|
||||||
PyTextile
|
PyTextile
|
||||||
@ -64,6 +65,7 @@ import re
|
|||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
from calibre.utils.smartypants import smartyPants
|
from calibre.utils.smartypants import smartyPants
|
||||||
|
from polyglot.builtins import unicode_type
|
||||||
from polyglot.urllib import urlopen, urlparse
|
from polyglot.urllib import urlopen, urlparse
|
||||||
|
|
||||||
|
|
||||||
@ -694,7 +696,7 @@ class Textile(object):
|
|||||||
def footnoteID(self, match):
|
def footnoteID(self, match):
|
||||||
id, t = match.groups()
|
id, t = match.groups()
|
||||||
if id not in self.fn:
|
if id not in self.fn:
|
||||||
self.fn[id] = str(uuid.uuid4())
|
self.fn[id] = unicode_type(uuid.uuid4())
|
||||||
fnid = self.fn[id]
|
fnid = self.fn[id]
|
||||||
if not t:
|
if not t:
|
||||||
t = ''
|
t = ''
|
||||||
@ -799,7 +801,7 @@ class Textile(object):
|
|||||||
return url
|
return url
|
||||||
|
|
||||||
def shelve(self, text):
|
def shelve(self, text):
|
||||||
id = str(uuid.uuid4()) + 'c'
|
id = unicode_type(uuid.uuid4()) + 'c'
|
||||||
self.shelf[id] = text
|
self.shelf[id] = text
|
||||||
return id
|
return id
|
||||||
|
|
||||||
|
@ -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__ = '2011, Leigh Parry <leighparry@blueyonder.co.uk>'
|
__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'
|
__license__ = 'GPL v3'
|
||||||
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
__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.
|
Dynamic language lookup of translations for user-visible strings.
|
||||||
'''
|
'''
|
||||||
@ -26,7 +27,7 @@ def translate(lang, text):
|
|||||||
allow_user_override=False), 'r') as zf:
|
allow_user_override=False), 'r') as zf:
|
||||||
try:
|
try:
|
||||||
buf = io.BytesIO(zf.read(mpath + '/messages.mo'))
|
buf = io.BytesIO(zf.read(mpath + '/messages.mo'))
|
||||||
except:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
trans = GNUTranslations(buf)
|
trans = GNUTranslations(buf)
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#!/usr/bin/env python2
|
#!/usr/bin/env python2
|
||||||
# Written by Martin v. Loewis <loewis@informatik.hu-berlin.de>
|
# 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.
|
"""Generate binary message catalog from textual translation description.
|
||||||
|
|
||||||
@ -44,11 +45,11 @@ def usage(code, msg=''):
|
|||||||
sys.exit(code)
|
sys.exit(code)
|
||||||
|
|
||||||
|
|
||||||
def add(id, str, fuzzy):
|
def add(id, s, fuzzy):
|
||||||
"Add a non-fuzzy translation to the dictionary."
|
"Add a non-fuzzy translation to the dictionary."
|
||||||
global MESSAGES
|
global MESSAGES
|
||||||
if not fuzzy and str:
|
if not fuzzy and s:
|
||||||
MESSAGES[id] = str
|
MESSAGES[id] = s
|
||||||
if id:
|
if id:
|
||||||
STATS['translated'] += 1
|
STATS['translated'] += 1
|
||||||
else:
|
else:
|
||||||
@ -59,7 +60,7 @@ def add(id, str, fuzzy):
|
|||||||
def generate():
|
def generate():
|
||||||
"Return the generated output."
|
"Return the generated output."
|
||||||
global MESSAGES
|
global MESSAGES
|
||||||
keys = MESSAGES.keys()
|
keys = list(MESSAGES)
|
||||||
# the keys are sorted in the .mo file
|
# the keys are sorted in the .mo file
|
||||||
keys.sort()
|
keys.sort()
|
||||||
offsets = []
|
offsets = []
|
||||||
@ -93,8 +94,8 @@ def generate():
|
|||||||
7*4+len(keys)*8, # start of value index
|
7*4+len(keys)*8, # start of value index
|
||||||
0, 0) # size and offset of hash table
|
0, 0) # size and offset of hash table
|
||||||
output += array.array("i", offsets).tostring()
|
output += array.array("i", offsets).tostring()
|
||||||
output += ids
|
output += ids.encode('utf-8')
|
||||||
output += strs
|
output += strs.encode('utf-8')
|
||||||
return output
|
return output
|
||||||
|
|
||||||
|
|
||||||
@ -123,6 +124,7 @@ def make(filename, outfile):
|
|||||||
lno = 0
|
lno = 0
|
||||||
msgid = msgstr = ''
|
msgid = msgstr = ''
|
||||||
for l in lines:
|
for l in lines:
|
||||||
|
l = l.decode('utf-8')
|
||||||
lno += 1
|
lno += 1
|
||||||
# If we get a comment line after a msgstr, this is a new entry
|
# If we get a comment line after a msgstr, this is a new entry
|
||||||
if l[0] == '#' and section == STR:
|
if l[0] == '#' and section == STR:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user