[PATCH evemu 08/11] py: Add _callstr() - returns str object
Daniel Martin
consume.noise at gmail.com
Thu Jan 2 13:47:58 PST 2014
Python 3 handles bytes objects differently. Therefor the result check in
_call() raises a "TypeError: unorderable types: bytes() < int()".
Add an additional _callstr() function, which converts the bytes object
to str on its way, to fix this error.
Signed-off-by: Daniel Martin <consume.noise at gmail.com>
---
python/evemu/__init__.py | 2 +-
python/evemu/base.py | 7 +++++++
python/evemu/const.py | 1 +
3 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/python/evemu/__init__.py b/python/evemu/__init__.py
index 21cd22f..20d82b5 100644
--- a/python/evemu/__init__.py
+++ b/python/evemu/__init__.py
@@ -199,7 +199,7 @@ class Device(object):
"""
func = self._evemu.get_lib().evemu_get_name
func.restype = ctypes.c_char_p
- return self._evemu._call(func, self._evemu_device)
+ return self._evemu._callstr(func, self._evemu_device)
@property
def id_bustype(self):
diff --git a/python/evemu/base.py b/python/evemu/base.py
index 0f2fa97..66ea36a 100644
--- a/python/evemu/base.py
+++ b/python/evemu/base.py
@@ -28,6 +28,13 @@ class EvEmuBase(object):
api_call.__name__, self.get_c_error()))
return result
+ def _callstr(self, api_call, *parameters):
+ result = api_call(*parameters)
+ if result == None and self.get_c_errno() != 0:
+ raise exception.ExecutionError("%s: %s" % (
+ api_call.__name__, self.get_c_error()))
+ return result.decode(const.ENCODING)
+
def get_c_errno(self):
return ctypes.get_errno()
diff --git a/python/evemu/const.py b/python/evemu/const.py
index bd1bcde..257963e 100644
--- a/python/evemu/const.py
+++ b/python/evemu/const.py
@@ -1,3 +1,4 @@
+ENCODING = "iso8859-1"
LIB = "libevemu.so"
UINPUT_NODE = "/dev/uinput"
MAX_EVENT_NODE = 32
--
1.8.5.2
More information about the Input-tools
mailing list