py3: more unicode porting

This commit is contained in:
Kovid Goyal 2019-06-02 14:33:27 +05:30
parent edc32ecdbd
commit b5230d9bd8
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
5 changed files with 41 additions and 37 deletions

View File

@ -1,4 +1,7 @@
#!/usr/bin/env python2
from __future__ import absolute_import, division, print_function, unicode_literals
__license__ = 'GPL v3'
__copyright__ = '2008, Kovid Goyal kovid@kovidgoyal.net'
__docformat__ = 'restructuredtext en'
@ -35,8 +38,8 @@ def unpickle_binary_string(data):
which = data[offset:offset+1]
offset += 1
if which == BINSTRING:
sz, = struct.unpack_from(b'<i', data, offset)
offset += struct.calcsize(b'<i')
sz, = struct.unpack_from('<i', data, offset)
offset += struct.calcsize('<i')
elif which == SHORT_BINSTRING:
sz = ord(data[offset])
offset += 1

View File

@ -1,7 +1,8 @@
#!/usr/bin/env python2
# 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'
__copyright__ = '2011, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en'
@ -284,7 +285,7 @@ class OptionSet(object):
try:
if not isinstance(src, unicode_type):
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)
except Exception as err:
try:
@ -360,7 +361,7 @@ class Config(ConfigInterface):
return os.path.join(config_dir, self.filename_base + '.py.json')
def parse(self):
src = u''
src = ''
migrate = False
path = self.config_file_path
if os.path.exists(path):
@ -554,7 +555,7 @@ if prefs['installation_uuid'] is None:
def tweaks_file():
return os.path.join(config_dir, u'tweaks.json')
return os.path.join(config_dir, 'tweaks.json')
def make_unicode(obj):
@ -623,7 +624,7 @@ def read_custom_tweaks():
import traceback
traceback.print_exc()
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):
ans = exec_tweaks(old_tweaks_file)
ans = make_unicode(ans)

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python2
# 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'
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
@ -34,7 +34,7 @@ if iswindows:
elif isosx:
try:
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:
parse_date_day_first = False
else:
@ -42,7 +42,7 @@ else:
def first_index(raw, queries):
for q in queries:
try:
return raw.index(q)
return raw.index(native_string_type(q))
except ValueError:
pass
return -1
@ -445,31 +445,31 @@ def clean_date_for_sort(dt, fmt=None):
def replace_months(datestr, clang):
# Replace months by english equivalent for parse_date
frtoen = {
u'[jJ]anvier': u'jan',
u'[fF].vrier': u'feb',
u'[mM]ars': u'mar',
u'[aA]vril': u'apr',
u'[mM]ai': u'may',
u'[jJ]uin': u'jun',
u'[jJ]uillet': u'jul',
u'[aA]o.t': u'aug',
u'[sS]eptembre': u'sep',
u'[Oo]ctobre': u'oct',
u'[nN]ovembre': u'nov',
u'[dD].cembre': u'dec'}
'[jJ]anvier': 'jan',
'[fF].vrier': 'feb',
'[mM]ars': 'mar',
'[aA]vril': 'apr',
'[mM]ai': 'may',
'[jJ]uin': 'jun',
'[jJ]uillet': 'jul',
'[aA]o.t': 'aug',
'[sS]eptembre': 'sep',
'[Oo]ctobre': 'oct',
'[nN]ovembre': 'nov',
'[dD].cembre': 'dec'}
detoen = {
u'[jJ]anuar': u'jan',
u'[fF]ebruar': u'feb',
u'[mM].rz': u'mar',
u'[aA]pril': u'apr',
u'[mM]ai': u'may',
u'[jJ]uni': u'jun',
u'[jJ]uli': u'jul',
u'[aA]ugust': u'aug',
u'[sS]eptember': u'sep',
u'[Oo]ktober': u'oct',
u'[nN]ovember': u'nov',
u'[dD]ezember': u'dec'}
'[jJ]anuar': 'jan',
'[fF]ebruar': 'feb',
'[mM].rz': 'mar',
'[aA]pril': 'apr',
'[mM]ai': 'may',
'[jJ]uni': 'jun',
'[jJ]uli': 'jul',
'[aA]ugust': 'aug',
'[sS]eptember': 'sep',
'[Oo]ktober': 'oct',
'[nN]ovember': 'nov',
'[dD]ezember': 'dec'}
if clang == 'fr':
dictoen = frtoen

View File

@ -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):
return None
trash_dir = op.join(trash_dir, str(uid))
trash_dir = op.join(trash_dir, unicode_type(uid))
try:
check_create(trash_dir)
except OSError:

View File

@ -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,
unlock_file
)
from polyglot.builtins import iteritems, getcwd
from polyglot.builtins import iteritems, getcwd, native_string_type
def FastFailEF(name):
@ -53,7 +53,7 @@ def run_worker(mod, func, **kw):
if iswindows:
import win32process
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
return subprocess.Popen(exe, **kw)