[PATCH evemu v2 4/4] py: make Device python 3 compatible

Benjamin Tissoires benjamin.tissoires at gmail.com
Wed Jan 15 13:05:01 PST 2014


The previous commit breaks Python 3.0 support due to devnode returning
a bytes object.

We could also force devnode to return an unicode string by using
decode, but still, the test "if type(f) == str" will fail in Python 2.X
because str and unicode are distinct object types.

So, in order to avoid having to introduce bad quirks, just drop the test
regarding str, and let open() telling us what is wrong in case we don't
give it a file object.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires at gmail.com>
---

v2:
- extracted from previous v1 patch
- removed python 2/3 crap
- removed the test regarding the string

 python/evemu/__init__.py | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/python/evemu/__init__.py b/python/evemu/__init__.py
index deaf95e..a914687 100644
--- a/python/evemu/__init__.py
+++ b/python/evemu/__init__.py
@@ -45,12 +45,10 @@ class Device(object):
         to create a pseudo-device node.
         """
 
-        if type(f) == str:
-            self._file = open(f)
-        elif hasattr(f, "read"):
+        if hasattr(f, "read"):
             self._file = f
         else:
-            raise TypeError("expected file or file name")
+            self._file = open(f)
 
         self._is_propfile = self._check_is_propfile(self._file)
         self._libc = evemu.base.LibC()
-- 
1.8.4.2



More information about the Input-tools mailing list