Skip to content

Commit 6d3b590

Browse files
committed
assert instead
1 parent 3256cb4 commit 6d3b590

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

evdev/uinput.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,12 @@ def _verify(self):
268268
Verify that an uinput device exists and is readable and writable
269269
by the current process.
270270
"""
271-
self._verify_character_device()
271+
try:
272+
m = os.stat(self.devnode)[stat.ST_MODE]
273+
assert stat.S_ISCHR(m)
274+
except (IndexError, OSError, AssertionError):
275+
msg = '"{}" does not exist or is not a character device file ' "- verify that the uinput module is loaded"
276+
raise UInputError(msg.format(self.devnode))
272277

273278
if not os.access(self.devnode, os.W_OK):
274279
msg = '"{}" cannot be opened for writing'
@@ -278,19 +283,6 @@ def _verify(self):
278283
msg = "uinput device name must not be longer than {} characters"
279284
raise UInputError(msg.format(_uinput.maxnamelen))
280285

281-
def _verify_character_device(self):
282-
try:
283-
mode = os.stat(self.devnode)[stat.ST_MODE]
284-
if stat.S_ISCHR(mode):
285-
return
286-
except (IndexError, OSError):
287-
pass
288-
289-
raise UInputError(
290-
f'"{self.devnode}" does not exist or is not a character device file '
291-
"- verify that the uinput module is loaded"
292-
)
293-
294286
def _find_device(self, fd):
295287
"""
296288
Tries to find the device node. Will delegate this task to one of

0 commit comments

Comments
 (0)