summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2014-11-07 10:27:21 +1000
committerBenjamin Tissoires <benjamin.tissoires@gmail.com>2014-11-07 10:46:48 -0500
commitdfec5481e910dd0943b7d84e0fde373edd59d944 (patch)
tree453f3087bd9f0df0fade9cfd1f30ab3449a888a3 /python
parent511ea969c88c5ab306a985343a74084cbd9a1afa (diff)
python: check for fileno(), not read() and document it
We use fileno() on the various file arguments, not read() so check for that. And document it in the API that we need real file objects here, not just something that's file-like. Reported-by: Dan Callaghan Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net> Signed-off-by: Benjamin Tissoires <benjamin.tissoires@gmail.com>
Diffstat (limited to 'python')
-rw-r--r--python/evemu/__init__.py17
1 files changed, 13 insertions, 4 deletions
diff --git a/python/evemu/__init__.py b/python/evemu/__init__.py
index 531ef81..78cf42f 100644
--- a/python/evemu/__init__.py
+++ b/python/evemu/__init__.py
@@ -255,8 +255,10 @@ class Device(object):
You need the required permissions to access the device file to
succeed (usually root).
+
+ prop_file must be a real file with fileno(), not file-like.
"""
- if not hasattr(prop_file, "read"):
+ if not hasattr(prop_file, "fileno"):
raise TypeError("expected file")
fs = self._libc.fdopen(prop_file.fileno(), b"w")
@@ -267,9 +269,12 @@ class Device(object):
"""
Reads the events from the given file and returns them as a list of
dicts.
+
+ If not None, events_file must be a real file with fileno(), not
+ file-like. If None, the file used for creating this device is used.
"""
if events_file:
- if not hasattr(events_file, "read"):
+ if not hasattr(events_file, "fileno"):
raise TypeError("expected file")
else:
events_file = self._file
@@ -287,8 +292,10 @@ class Device(object):
You need the required permissions to access the device file to
succeed (usually root).
+
+ events_file must be a real file with fileno(), not file-like.
"""
- if not hasattr(events_file, "read"):
+ if not hasattr(events_file, "fileno"):
raise TypeError("expected file")
fs = self._libc.fdopen(events_file.fileno(), b"r")
@@ -303,8 +310,10 @@ class Device(object):
You need the required permissions to access the device file to
succeed (usually root).
+
+ events_file must be a real file with fileno(), not file-like.
"""
- if not hasattr(events_file, "read"):
+ if not hasattr(events_file, "fileno"):
raise TypeError("expected file")
fs = self._libc.fdopen(events_file.fileno(), b"w")