Skip to content

Commit

Permalink
Remove some py2 cruft and completely disable buffering for the patche…
Browse files Browse the repository at this point in the history
…d std fhs. Ref #66.
  • Loading branch information
ionelmc committed Dec 18, 2023
1 parent 0fb66e6 commit f4adf45
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/manhole/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

__version__ = '1.8.0'

from io import TextIOWrapper

try:
import signalfd
except ImportError:
Expand Down Expand Up @@ -63,8 +65,6 @@ def _get_original(mod, name):
_ORIGINAL__ACTIVE = _get_original('threading', '_active')
_ORIGINAL_SLEEP = _get_original('time', 'sleep')

PY3 = sys.version_info[0] == 3

try:
import ctypes
import ctypes.util
Expand Down Expand Up @@ -287,7 +287,7 @@ def exit():
_LOG('Exiting exec loop.')


def handle_connection_repl(client):
def handle_connection_repl(client: socket.socket):
"""
Handles connection.
"""
Expand All @@ -304,8 +304,10 @@ def handle_connection_repl(client):
try:
for mode, names in patches:
for name in names:
backup.append((name, getattr(sys, name)))
setattr(sys, name, client.makefile(mode, 1 if PY3 else 0))
backup.append((name, backup_fh := getattr(sys, name)))
setattr(sys, name, wrapped_fh := TextIOWrapper(client.makefile(f'{mode}b', 0), encoding=backup_fh.encoding))
wrapped_fh.mode = mode

try:
handle_repl(_MANHOLE.locals)
except BrokenPipeError:
Expand Down

0 comments on commit f4adf45

Please sign in to comment.