Skip to content

Commit

Permalink
Merge pull request #1244 from moreati/issue1121
Browse files Browse the repository at this point in the history
mitogen: cfmakeraw() cleanups
  • Loading branch information
moreati authored Feb 6, 2025
2 parents a3768a0 + 927fb17 commit 77d87cd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ To avail of fixes in an unreleased version, please download a ZIP file
In progress (unreleased)
------------------------

* :gh:issue:`1121` :mod:`mitogen`: Log skipped :py:mod:`termios` attributes


v0.3.22 (2025-02-04)
Expand Down
17 changes: 11 additions & 6 deletions mitogen/parent.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,16 @@ def flags(names):
Return the result of ORing a set of (space separated) :py:mod:`termios`
module constants together.
"""
return sum(getattr(termios, name, 0)
for name in names.split())
i = 0
skipped = []
for name in names.split():
try:
i |= getattr(termios, name)
except AttributeError:
skipped.append(name)
if skipped:
LOG.debug('Skipped termios attributes: %s', ', '.join(skipped))
return i


def cfmakeraw(tflags):
Expand All @@ -234,12 +242,9 @@ def cfmakeraw(tflags):
modified in a manner similar to the `cfmakeraw()` C library function, but
additionally disabling local echo.
"""
# BSD: github.com/freebsd/freebsd/blob/master/lib/libc/gen/termios.c#L162
# Linux: github.com/lattera/glibc/blob/master/termios/cfmakeraw.c#L20
iflag, oflag, cflag, lflag, ispeed, ospeed, cc = tflags
iflag &= ~flags('IMAXBEL IXOFF INPCK BRKINT PARMRK '
'ISTRIP INLCR ICRNL IXON IGNPAR')
iflag &= ~flags('IGNBRK BRKINT PARMRK')
'ISTRIP INLCR ICRNL IXON IGNPAR IGNBRK')
oflag &= ~flags('OPOST')
lflag &= ~flags('ECHO ECHOE ECHOK ECHONL ICANON ISIG '
'IEXTEN NOFLSH TOSTOP PENDIN')
Expand Down

0 comments on commit 77d87cd

Please sign in to comment.