Skip to content

Commit

Permalink
assert instead
Browse files Browse the repository at this point in the history
  • Loading branch information
sezanzeb committed Jan 19, 2025
1 parent 3256cb4 commit 6d3b590
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions evdev/uinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,12 @@ def _verify(self):
Verify that an uinput device exists and is readable and writable
by the current process.
"""
self._verify_character_device()
try:
m = os.stat(self.devnode)[stat.ST_MODE]
assert stat.S_ISCHR(m)
except (IndexError, OSError, AssertionError):
msg = '"{}" does not exist or is not a character device file ' "- verify that the uinput module is loaded"
raise UInputError(msg.format(self.devnode))

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

def _verify_character_device(self):
try:
mode = os.stat(self.devnode)[stat.ST_MODE]
if stat.S_ISCHR(mode):
return
except (IndexError, OSError):
pass

raise UInputError(
f'"{self.devnode}" does not exist or is not a character device file '
"- verify that the uinput module is loaded"
)

def _find_device(self, fd):
"""
Tries to find the device node. Will delegate this task to one of
Expand Down

0 comments on commit 6d3b590

Please sign in to comment.