[PATCH evemu 06/11] py: Fix file opening

Daniel Martin consume.noise at gmail.com
Thu Jan 2 13:47:56 PST 2014


The device node is the only file that needs to be opened in binary mode
and we've to open other "device" files (like prop files) in text mode.
Otherwise lots of conversions from bytes objects to str will be
necessary as Python 3 handles them differently.

Signed-off-by: Daniel Martin <consume.noise at gmail.com>
---
 python/evemu/__init__.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/python/evemu/__init__.py b/python/evemu/__init__.py
index 3f8e801..3a1a8d4 100644
--- a/python/evemu/__init__.py
+++ b/python/evemu/__init__.py
@@ -47,7 +47,7 @@ class Device(object):
         """
 
         if type(f).__name__ == 'str':
-            self._file = open(f, 'r+b')
+            self._file = open(f)
         elif type(f).__name__ == 'file':
             self._file = f
         else:
@@ -85,7 +85,7 @@ class Device(object):
         self._evemu._call(self._evemu.get_lib().evemu_create,
                           self._evemu_device,
                           self._uinput)
-        return open(self._find_newest_devnode(self.name), 'r+')
+        return open(self._find_newest_devnode(self.name), 'r+b', buffering=0)
 
     def _find_newest_devnode(self, target_name):
         newest_node = (None, float(0))
-- 
1.8.5.2



More information about the Input-tools mailing list