Skip to content

Commit 06eb62e

Browse files
committed
SerialEOF only for PTYs.
1 parent a50f769 commit 06eb62e

File tree

2 files changed

+4
-17
lines changed

2 files changed

+4
-17
lines changed

slip39/generator/main.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,6 @@
1616
log = logging.getLogger( __package__ )
1717

1818

19-
class SerialEOF( Serial ):
20-
"""Converts Serial exceptions into EOFError, for compatibility w/ expectations of file-like objects.
21-
22-
"""
23-
def read( self, size=1 ):
24-
while True:
25-
try:
26-
return super( SerialEOF, self ).read( size=size )
27-
except Exception as exc: # SerialError as exc:
28-
# if "readiness" in str(exc):
29-
# time.sleep( .1 )
30-
# continue
31-
raise EOFError( str( exc ))
32-
33-
3419
DtrDsr = namedtuple( 'DtrDsr', ('dtr', 'dsr') )
3520
RtsCts = namedtuple( 'RtsCts', ('rts', 'cts') )
3621

slip39/generator_test.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import pty
44
import threading
55

6-
from serial import Serial # , SerialError
6+
from serial import Serial
77

88
from .api import RANDOM_BYTES, accountgroups
99
from .generator import chacha20poly1305, accountgroups_output, accountgroups_input
@@ -78,6 +78,8 @@ def generator( password, cryptopaths, fd ):
7878

7979

8080
class SerialEOF( Serial ):
81+
"""Convert any SerialException to an EOFError, for compatibility with PTY. In real serial ports,
82+
we'll handle detection of counterparty readiness with DTR/DSR, and flow control with RTS/CTS."""
8183
def read( self, size=1 ):
8284
while True:
8385
try:
@@ -105,7 +107,7 @@ def test_groups_pty():
105107
gen.daemon = True
106108
gen.start()
107109

108-
ser = SerialEOF( slave_name, 300, timeout=1, xonxoff=True )
110+
ser = SerialEOF( slave_name, timeout=1)
109111
for group in accountgroups_input(
110112
cipher = chacha20poly1305( password=password ),
111113
encoding = 'UTF-8',

0 commit comments

Comments
 (0)