misc: remove support for Python 2 unicode
This commit is contained in:
parent
8ac8fe6401
commit
bb20631a27
|
@ -41,19 +41,6 @@ prompt = '?? Input: ' if interactive else ''
|
|||
start_time = time.time()
|
||||
|
||||
strhex = lambda d: hexlify(d).decode('ascii').upper()
|
||||
try:
|
||||
unicode # noqa: F821
|
||||
# this is certanly Python 2
|
||||
is_string = lambda d: isinstance(d, unicode) # noqa: F821
|
||||
# no easy way to distinguish between b'' and '' :(
|
||||
# or (isinstance(d, str) \
|
||||
# and not any((chr(k) in d for k in range(0x00, 0x1F))) \
|
||||
# and not any((chr(k) in d for k in range(0x80, 0xFF))) \
|
||||
# )
|
||||
except Exception:
|
||||
# this is certanly Python 3
|
||||
# In Py3, unicode and str are equal (the unicode object does not exist)
|
||||
is_string = lambda d: isinstance(d, str)
|
||||
|
||||
#
|
||||
#
|
||||
|
@ -65,7 +52,7 @@ del Lock
|
|||
|
||||
def _print(marker, data, scroll=False):
|
||||
t = time.time() - start_time
|
||||
if is_string(data):
|
||||
if isinstance(data, str):
|
||||
s = marker + ' ' + data
|
||||
else:
|
||||
hexs = strhex(data)
|
||||
|
|
|
@ -346,7 +346,6 @@ _HIDPP_Notification = namedtuple('_HIDPP_Notification', ('report_id', 'devnumber
|
|||
_HIDPP_Notification.__str__ = lambda self: 'Notification(%02x,%d,%02X,%02X,%s)' % (
|
||||
self.report_id, self.devnumber, self.sub_id, self.address, _strhex(self.data)
|
||||
)
|
||||
_HIDPP_Notification.__unicode__ = _HIDPP_Notification.__str__
|
||||
del namedtuple
|
||||
|
||||
#
|
||||
|
|
|
@ -22,24 +22,7 @@ from binascii import hexlify as _hexlify
|
|||
from collections import namedtuple
|
||||
from struct import pack, unpack
|
||||
|
||||
try:
|
||||
unicode # noqa: F821
|
||||
# if Python2, unicode_literals will mess our first (un)pack() argument
|
||||
_pack_str = pack
|
||||
_unpack_str = unpack
|
||||
pack = lambda x, *args: _pack_str(str(x), *args)
|
||||
unpack = lambda x, *args: _unpack_str(str(x), *args)
|
||||
|
||||
is_string = lambda d: isinstance(d, unicode) or isinstance(d, str) # noqa: F821
|
||||
# no easy way to distinguish between b'' and '' :(
|
||||
# or (isinstance(d, str) \
|
||||
# and not any((chr(k) in d for k in range(0x00, 0x1F))) \
|
||||
# and not any((chr(k) in d for k in range(0x80, 0xFF))) \
|
||||
# )
|
||||
except Exception:
|
||||
# this is certainly Python 3
|
||||
# In Py3, unicode and str are equal (the unicode object does not exist)
|
||||
is_string = lambda d: isinstance(d, str)
|
||||
is_string = lambda d: isinstance(d, str)
|
||||
|
||||
#
|
||||
#
|
||||
|
@ -80,8 +63,6 @@ class NamedInt(int):
|
|||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
__unicode__ = __str__
|
||||
|
||||
def __repr__(self):
|
||||
return 'NamedInt(%d, %r)' % (int(self), self.name)
|
||||
|
||||
|
@ -104,7 +85,7 @@ class NamedInts:
|
|||
def __init__(self, **kwargs):
|
||||
def _readable_name(n):
|
||||
if not is_string(n):
|
||||
raise TypeError('expected (unicode) string, got ' + str(type(n)))
|
||||
raise TypeError('expected string, got ' + str(type(n)))
|
||||
return n.replace('__', '/').replace('_', ' ')
|
||||
|
||||
# print (repr(kwargs))
|
||||
|
|
|
@ -444,7 +444,7 @@ class Device:
|
|||
self.number, self.wpid or self.product_id, self.name or self.codename or '?', self.serial
|
||||
)
|
||||
|
||||
__unicode__ = __repr__ = __str__
|
||||
__repr__ = __str__
|
||||
|
||||
def notify_devices(self): # no need to notify, as there are none
|
||||
pass
|
||||
|
|
|
@ -20,13 +20,8 @@
|
|||
|
||||
import gettext as _gettext
|
||||
|
||||
try:
|
||||
unicode # noqa: F821
|
||||
_ = lambda x: _gettext.gettext(x).decode('UTF-8')
|
||||
ngettext = lambda *x: _gettext.ngettext(*x).decode('UTF-8')
|
||||
except Exception:
|
||||
_ = _gettext.gettext
|
||||
ngettext = _gettext.ngettext
|
||||
_ = _gettext.gettext
|
||||
ngettext = _gettext.ngettext
|
||||
|
||||
# A few common strings, not always accessible as such in the code.
|
||||
|
||||
|
|
|
@ -105,8 +105,6 @@ class _ThreadedHandle:
|
|||
if self._local:
|
||||
return str(int(self))
|
||||
|
||||
__unicode__ = __str__
|
||||
|
||||
def __repr__(self):
|
||||
return '<_ThreadedHandle(%s)>' % self.path
|
||||
|
||||
|
|
|
@ -375,7 +375,7 @@ class Receiver:
|
|||
def __str__(self):
|
||||
return self._str
|
||||
|
||||
__unicode__ = __repr__ = __str__
|
||||
__repr__ = __str__
|
||||
|
||||
__bool__ = __nonzero__ = lambda self: self.handle is not None
|
||||
|
||||
|
|
|
@ -347,7 +347,7 @@ class Setting:
|
|||
)
|
||||
return '<Setting([%s:%s] %s)>' % (self._rw.kind, self._validator.kind if self._validator else None, self.name)
|
||||
|
||||
__unicode__ = __repr__ = __str__
|
||||
__repr__ = __str__
|
||||
|
||||
|
||||
class Settings(Setting):
|
||||
|
|
|
@ -116,8 +116,6 @@ class ReceiverStatus(dict):
|
|||
}
|
||||
)
|
||||
|
||||
__unicode__ = __str__
|
||||
|
||||
def changed(self, alert=ALERT.NOTIFICATION, reason=None):
|
||||
# self.updated = _timestamp()
|
||||
self._changed_callback(self._receiver, alert=alert, reason=reason)
|
||||
|
|
|
@ -59,11 +59,6 @@ _gettext.bindtextdomain(_LOCALE_DOMAIN, path)
|
|||
_gettext.textdomain(_LOCALE_DOMAIN)
|
||||
_gettext.install(_LOCALE_DOMAIN)
|
||||
|
||||
try:
|
||||
unicode # noqa: F821
|
||||
_ = lambda x: _gettext.gettext(x).decode('UTF-8')
|
||||
ngettext = lambda *x: _gettext.ngettext(*x).decode('UTF-8')
|
||||
except Exception:
|
||||
_ = _gettext.gettext
|
||||
ngettext = _gettext.ngettext
|
||||
pgettext = _gettext.pgettext
|
||||
_ = _gettext.gettext
|
||||
ngettext = _gettext.ngettext
|
||||
pgettext = _gettext.pgettext
|
||||
|
|
|
@ -275,8 +275,6 @@ class ReceiverListener(_listener.EventsListener):
|
|||
def __str__(self):
|
||||
return '<ReceiverListener(%s,%s)>' % (self.receiver.path, self.receiver.handle)
|
||||
|
||||
__unicode__ = __str__
|
||||
|
||||
|
||||
#
|
||||
#
|
||||
|
|
Loading…
Reference in New Issue