py3: More unicode porting

This commit is contained in:
Kovid Goyal 2019-05-30 09:23:58 +05:30
parent c03fad6f5d
commit 831a938855
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
5 changed files with 24 additions and 21 deletions

View File

@ -1,3 +1,5 @@
from __future__ import absolute_import, division, print_function, unicode_literals
# Copyright (C) 2003-2006 Red Hat Inc. <http://www.redhat.com/>
# Copyright (C) 2003 David Zeuthen
# Copyright (C) 2004 Rob Taylor
@ -24,9 +26,6 @@
# DEALINGS IN THE SOFTWARE.
#
from __future__ import absolute_import
from polyglot.builtins import itervalues, zip
__all__ = ('BusName', 'Object', 'PropertiesInterface', 'method', 'dbus_property', 'signal')
__docformat__ = 'restructuredtext'
@ -45,7 +44,8 @@ from dbus.exceptions import (
DBusException, NameExistsException, UnknownMethodException)
from dbus.lowlevel import ErrorMessage, MethodReturnMessage, MethodCallMessage
from dbus.proxies import LOCAL_PATH
is_py2 = sys.version_info.major == 2
from polyglot.builtins import itervalues, zip, is_py3
class dbus_property(object):
@ -161,7 +161,7 @@ class _VariantSignature(object):
"""Return 'v' whenever called."""
return 'v'
if is_py2:
if not is_py3:
next = __next__
@ -602,7 +602,7 @@ class Object(Interface):
self.LastInputChanged(var) # emits the signal
# Emit the property changed signal
self.PropertiesChanged('com.example.Sample', {'LastInput': var}, [])
return str(var)
return unicode_type(var)
@dbus.service.signal(interface='com.example.Sample',
signature='v')

View File

@ -22,7 +22,7 @@ from calibre.utils.filenames import atomic_rename
from calibre.utils.terminal import ANSIStream
from duktape import Context, JSError, to_python
from lzma.xz import compress, decompress
from polyglot.builtins import itervalues, range, exec_path, raw_input, error_message, filter, getcwd, zip
from polyglot.builtins import itervalues, range, exec_path, raw_input, error_message, filter, getcwd, zip, unicode_type
from polyglot.queue import Empty, Queue
COMPILER_PATH = 'rapydscript/compiler.js.xz'
@ -210,7 +210,7 @@ def compile_srv():
rapydscript_dir = os.path.join(base, 'src', 'pyj')
rb = os.path.join(base, 'src', 'calibre', 'srv', 'render_book.py')
with lopen(rb, 'rb') as f:
rv = str(int(re.search(br'^RENDER_VERSION\s+=\s+(\d+)', f.read(), re.M).group(1)))
rv = unicode_type(int(re.search(br'^RENDER_VERSION\s+=\s+(\d+)', f.read(), re.M).group(1)))
mathjax_version = json.loads(P('mathjax/manifest.json', data=True, allow_user_override=False))['etag']
base = os.path.join(base, 'resources', 'content-server')
fname = os.path.join(rapydscript_dir, 'srv.pyj')

View File

@ -1,6 +1,7 @@
#!/usr/bin/env python2
# encoding: utf-8
from __future__ import print_function
from __future__ import absolute_import, division, print_function, unicode_literals
__license__ = 'GPL v3'
__copyright__ = '2008, Kovid Goyal kovid@kovidgoyal.net'
__docformat__ = 'restructuredtext en'
@ -144,15 +145,15 @@ class Parser(object):
WORD = 2
QUOTED_WORD = 3
EOF = 4
REPLACEMENTS = tuple((u'\\' + x, codepoint_to_chr(i + 1)) for i, x in enumerate(u'\\"()'))
REPLACEMENTS = tuple(('\\' + x, codepoint_to_chr(i + 1)) for i, x in enumerate('\\"()'))
# Had to translate named constants to numeric values
lex_scanner = re.Scanner([
(unicode_type(r'[()]'), lambda x,t: (Parser.OPCODE, t)),
(unicode_type(r'@.+?:[^")\s]+'), lambda x,t: (Parser.WORD, unicode_type(t))),
(unicode_type(r'[^"()\s]+'), lambda x,t: (Parser.WORD, unicode_type(t))),
(unicode_type(r'".*?((?<!\\)")'), lambda x,t: (Parser.QUOTED_WORD, t[1:-1])),
(unicode_type(r'\s+'), None)
(r'[()]', lambda x,t: (Parser.OPCODE, t)),
(r'@.+?:[^")\s]+', lambda x,t: (Parser.WORD, unicode_type(t))),
(r'[^"()\s]+', lambda x,t: (Parser.WORD, unicode_type(t))),
(r'".*?((?<!\\)")', lambda x,t: (Parser.QUOTED_WORD, t[1:-1])),
(r'\s+', None)
], flags=re.DOTALL)
def token(self, advance=False):
@ -432,10 +433,10 @@ class SearchQueryParser(object):
:param:`query` is a string literal.
:return: None or a subset of the set returned by :meth:`universal_set`.
'''
return set([])
return set()
def universal_set(self):
'''
Should return the set of all matches.
'''
return set([])
return set()

View File

@ -1,5 +1,5 @@
from __future__ import with_statement
from __future__ import print_function
from __future__ import absolute_import, division, print_function, unicode_literals
__license__ = 'GPL 3'
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en'
@ -13,6 +13,7 @@ This module implements a simple commandline SMTP client that supports:
import sys, traceback, os, socket, encodings.idna as idna
from calibre import isbytestring, force_unicode
from calibre.constants import ispy3
from polyglot.builtins import unicode_type
def safe_localhost():
@ -100,7 +101,7 @@ def get_mx(host, verbose=0):
print('Find mail exchanger for', host)
answers = list(dns.resolver.query(host, 'MX'))
answers.sort(key=lambda x: int(getattr(x, 'preference', sys.maxsize)))
return [str(x.exchange) for x in answers if hasattr(x, 'exchange')]
return [unicode_type(x.exchange) for x in answers if hasattr(x, 'exchange')]
def sendmail_direct(from_, to, msg, timeout, localhost, verbose,

View File

@ -1,3 +1,5 @@
from __future__ import absolute_import, division, print_function, unicode_literals
"""Easy to use object-oriented thread pool framework.
A thread pool is an object that maintains a pool of worker threads to perform
@ -29,7 +31,6 @@ See the end of the module code for a brief, annotated usage example.
Website : http://chrisarndt.de/en/software/python/threadpool/
"""
from __future__ import print_function
__all__ = [
'makeRequests',