diff --git a/lib/hidapi/hidconsole.py b/lib/hidapi/hidconsole.py index 896aba76..1390de25 100644 --- a/lib/hidapi/hidconsole.py +++ b/lib/hidapi/hidconsole.py @@ -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) diff --git a/lib/logitech_receiver/base.py b/lib/logitech_receiver/base.py index 2c6b9611..1aa49894 100644 --- a/lib/logitech_receiver/base.py +++ b/lib/logitech_receiver/base.py @@ -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 # diff --git a/lib/logitech_receiver/common.py b/lib/logitech_receiver/common.py index 25edcd60..4189fce3 100644 --- a/lib/logitech_receiver/common.py +++ b/lib/logitech_receiver/common.py @@ -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)) diff --git a/lib/logitech_receiver/device.py b/lib/logitech_receiver/device.py index 15f19384..8d92e791 100644 --- a/lib/logitech_receiver/device.py +++ b/lib/logitech_receiver/device.py @@ -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 diff --git a/lib/logitech_receiver/i18n.py b/lib/logitech_receiver/i18n.py index 7f14f086..c2d51cce 100644 --- a/lib/logitech_receiver/i18n.py +++ b/lib/logitech_receiver/i18n.py @@ -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. diff --git a/lib/logitech_receiver/listener.py b/lib/logitech_receiver/listener.py index 5443c6be..2f0e870f 100644 --- a/lib/logitech_receiver/listener.py +++ b/lib/logitech_receiver/listener.py @@ -105,8 +105,6 @@ class _ThreadedHandle: if self._local: return str(int(self)) - __unicode__ = __str__ - def __repr__(self): return '<_ThreadedHandle(%s)>' % self.path diff --git a/lib/logitech_receiver/receiver.py b/lib/logitech_receiver/receiver.py index b8c7b3c9..868d5cea 100644 --- a/lib/logitech_receiver/receiver.py +++ b/lib/logitech_receiver/receiver.py @@ -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 diff --git a/lib/logitech_receiver/settings.py b/lib/logitech_receiver/settings.py index f74c3f56..44a38f39 100644 --- a/lib/logitech_receiver/settings.py +++ b/lib/logitech_receiver/settings.py @@ -347,7 +347,7 @@ class Setting: ) return '' % (self._rw.kind, self._validator.kind if self._validator else None, self.name) - __unicode__ = __repr__ = __str__ + __repr__ = __str__ class Settings(Setting): diff --git a/lib/logitech_receiver/status.py b/lib/logitech_receiver/status.py index 4b98ea6b..c3568e38 100644 --- a/lib/logitech_receiver/status.py +++ b/lib/logitech_receiver/status.py @@ -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) diff --git a/lib/solaar/i18n.py b/lib/solaar/i18n.py index 52adbd81..6a47be77 100644 --- a/lib/solaar/i18n.py +++ b/lib/solaar/i18n.py @@ -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 diff --git a/lib/solaar/listener.py b/lib/solaar/listener.py index 71585522..fed2f0e4 100644 --- a/lib/solaar/listener.py +++ b/lib/solaar/listener.py @@ -275,8 +275,6 @@ class ReceiverListener(_listener.EventsListener): def __str__(self): return '' % (self.receiver.path, self.receiver.handle) - __unicode__ = __str__ - # #