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
edc32ecdbd
commit
b5230d9bd8
@ -1,4 +1,7 @@
|
|||||||
#!/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'
|
||||||
@ -35,8 +38,8 @@ def unpickle_binary_string(data):
|
|||||||
which = data[offset:offset+1]
|
which = data[offset:offset+1]
|
||||||
offset += 1
|
offset += 1
|
||||||
if which == BINSTRING:
|
if which == BINSTRING:
|
||||||
sz, = struct.unpack_from(b'<i', data, offset)
|
sz, = struct.unpack_from('<i', data, offset)
|
||||||
offset += struct.calcsize(b'<i')
|
offset += struct.calcsize('<i')
|
||||||
elif which == SHORT_BINSTRING:
|
elif which == SHORT_BINSTRING:
|
||||||
sz = ord(data[offset])
|
sz = ord(data[offset])
|
||||||
offset += 1
|
offset += 1
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
#!/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 print_function
|
from __future__ import absolute_import, division, print_function, unicode_literals
|
||||||
|
|
||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
__copyright__ = '2011, Kovid Goyal <kovid@kovidgoyal.net>'
|
__copyright__ = '2011, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
@ -284,7 +285,7 @@ class OptionSet(object):
|
|||||||
try:
|
try:
|
||||||
if not isinstance(src, unicode_type):
|
if not isinstance(src, unicode_type):
|
||||||
src = src.decode('utf-8')
|
src = src.decode('utf-8')
|
||||||
src = src.replace(u'PyQt%d.QtCore' % 4, u'PyQt5.QtCore')
|
src = src.replace('PyQt%d.QtCore' % 4, 'PyQt5.QtCore')
|
||||||
exec(src, options)
|
exec(src, options)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
try:
|
try:
|
||||||
@ -360,7 +361,7 @@ class Config(ConfigInterface):
|
|||||||
return os.path.join(config_dir, self.filename_base + '.py.json')
|
return os.path.join(config_dir, self.filename_base + '.py.json')
|
||||||
|
|
||||||
def parse(self):
|
def parse(self):
|
||||||
src = u''
|
src = ''
|
||||||
migrate = False
|
migrate = False
|
||||||
path = self.config_file_path
|
path = self.config_file_path
|
||||||
if os.path.exists(path):
|
if os.path.exists(path):
|
||||||
@ -554,7 +555,7 @@ if prefs['installation_uuid'] is None:
|
|||||||
|
|
||||||
|
|
||||||
def tweaks_file():
|
def tweaks_file():
|
||||||
return os.path.join(config_dir, u'tweaks.json')
|
return os.path.join(config_dir, 'tweaks.json')
|
||||||
|
|
||||||
|
|
||||||
def make_unicode(obj):
|
def make_unicode(obj):
|
||||||
@ -623,7 +624,7 @@ def read_custom_tweaks():
|
|||||||
import traceback
|
import traceback
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
return ans
|
return ans
|
||||||
old_tweaks_file = tf.rpartition(u'.')[0] + u'.py'
|
old_tweaks_file = tf.rpartition('.')[0] + '.py'
|
||||||
if os.path.exists(old_tweaks_file):
|
if os.path.exists(old_tweaks_file):
|
||||||
ans = exec_tweaks(old_tweaks_file)
|
ans = exec_tweaks(old_tweaks_file)
|
||||||
ans = make_unicode(ans)
|
ans = make_unicode(ans)
|
||||||
|
@ -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>'
|
||||||
@ -34,7 +34,7 @@ if iswindows:
|
|||||||
elif isosx:
|
elif isosx:
|
||||||
try:
|
try:
|
||||||
date_fmt = plugins['usbobserver'][0].date_format()
|
date_fmt = plugins['usbobserver'][0].date_format()
|
||||||
parse_date_day_first = date_fmt.index(u'd') < date_fmt.index(u'M')
|
parse_date_day_first = date_fmt.index('d') < date_fmt.index('M')
|
||||||
except:
|
except:
|
||||||
parse_date_day_first = False
|
parse_date_day_first = False
|
||||||
else:
|
else:
|
||||||
@ -42,7 +42,7 @@ else:
|
|||||||
def first_index(raw, queries):
|
def first_index(raw, queries):
|
||||||
for q in queries:
|
for q in queries:
|
||||||
try:
|
try:
|
||||||
return raw.index(q)
|
return raw.index(native_string_type(q))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
return -1
|
return -1
|
||||||
@ -445,31 +445,31 @@ def clean_date_for_sort(dt, fmt=None):
|
|||||||
def replace_months(datestr, clang):
|
def replace_months(datestr, clang):
|
||||||
# Replace months by english equivalent for parse_date
|
# Replace months by english equivalent for parse_date
|
||||||
frtoen = {
|
frtoen = {
|
||||||
u'[jJ]anvier': u'jan',
|
'[jJ]anvier': 'jan',
|
||||||
u'[fF].vrier': u'feb',
|
'[fF].vrier': 'feb',
|
||||||
u'[mM]ars': u'mar',
|
'[mM]ars': 'mar',
|
||||||
u'[aA]vril': u'apr',
|
'[aA]vril': 'apr',
|
||||||
u'[mM]ai': u'may',
|
'[mM]ai': 'may',
|
||||||
u'[jJ]uin': u'jun',
|
'[jJ]uin': 'jun',
|
||||||
u'[jJ]uillet': u'jul',
|
'[jJ]uillet': 'jul',
|
||||||
u'[aA]o.t': u'aug',
|
'[aA]o.t': 'aug',
|
||||||
u'[sS]eptembre': u'sep',
|
'[sS]eptembre': 'sep',
|
||||||
u'[Oo]ctobre': u'oct',
|
'[Oo]ctobre': 'oct',
|
||||||
u'[nN]ovembre': u'nov',
|
'[nN]ovembre': 'nov',
|
||||||
u'[dD].cembre': u'dec'}
|
'[dD].cembre': 'dec'}
|
||||||
detoen = {
|
detoen = {
|
||||||
u'[jJ]anuar': u'jan',
|
'[jJ]anuar': 'jan',
|
||||||
u'[fF]ebruar': u'feb',
|
'[fF]ebruar': 'feb',
|
||||||
u'[mM].rz': u'mar',
|
'[mM].rz': 'mar',
|
||||||
u'[aA]pril': u'apr',
|
'[aA]pril': 'apr',
|
||||||
u'[mM]ai': u'may',
|
'[mM]ai': 'may',
|
||||||
u'[jJ]uni': u'jun',
|
'[jJ]uni': 'jun',
|
||||||
u'[jJ]uli': u'jul',
|
'[jJ]uli': 'jul',
|
||||||
u'[aA]ugust': u'aug',
|
'[aA]ugust': 'aug',
|
||||||
u'[sS]eptember': u'sep',
|
'[sS]eptember': 'sep',
|
||||||
u'[Oo]ktober': u'oct',
|
'[Oo]ktober': 'oct',
|
||||||
u'[nN]ovember': u'nov',
|
'[nN]ovember': 'nov',
|
||||||
u'[dD]ezember': u'dec'}
|
'[dD]ezember': 'dec'}
|
||||||
|
|
||||||
if clang == 'fr':
|
if clang == 'fr':
|
||||||
dictoen = frtoen
|
dictoen = frtoen
|
||||||
|
@ -119,7 +119,7 @@ def find_ext_volume_global_trash(volume_root):
|
|||||||
if not op.isdir(trash_dir) or op.islink(trash_dir) or not (mode & stat.S_ISVTX):
|
if not op.isdir(trash_dir) or op.islink(trash_dir) or not (mode & stat.S_ISVTX):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
trash_dir = op.join(trash_dir, str(uid))
|
trash_dir = op.join(trash_dir, unicode_type(uid))
|
||||||
try:
|
try:
|
||||||
check_create(trash_dir)
|
check_create(trash_dir)
|
||||||
except OSError:
|
except OSError:
|
||||||
|
@ -19,7 +19,7 @@ from calibre.utils.tdir_in_cache import (
|
|||||||
clean_tdirs_in, is_tdir_locked, retry_lock_tdir, tdir_in_cache, tdirs_in,
|
clean_tdirs_in, is_tdir_locked, retry_lock_tdir, tdir_in_cache, tdirs_in,
|
||||||
unlock_file
|
unlock_file
|
||||||
)
|
)
|
||||||
from polyglot.builtins import iteritems, getcwd
|
from polyglot.builtins import iteritems, getcwd, native_string_type
|
||||||
|
|
||||||
|
|
||||||
def FastFailEF(name):
|
def FastFailEF(name):
|
||||||
@ -53,7 +53,7 @@ def run_worker(mod, func, **kw):
|
|||||||
if iswindows:
|
if iswindows:
|
||||||
import win32process
|
import win32process
|
||||||
kw['creationflags'] = win32process.CREATE_NO_WINDOW
|
kw['creationflags'] = win32process.CREATE_NO_WINDOW
|
||||||
kw['env'] = {str(k): str(v)
|
kw['env'] = {native_string_type(k): native_string_type(v)
|
||||||
for k, v in iteritems(env)} # windows needs bytes in env
|
for k, v in iteritems(env)} # windows needs bytes in env
|
||||||
return subprocess.Popen(exe, **kw)
|
return subprocess.Popen(exe, **kw)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user