Skip to content

Commit 905fc4f

Browse files
committed
lint
1 parent ade7d49 commit 905fc4f

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

src/pyssm_client/utils/command.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from ..communicator.utils import create_websocket_config
1313

1414

15-
1615
def _filter_shell_output(data: bytes, original_command: str) -> bytes:
1716
"""Filter shell prompts, command echoes, and ANSI sequences from output."""
1817
import re
@@ -148,35 +147,37 @@ async def run_command(
148147
stderr_buf = bytearray()
149148
session_done = asyncio.Event()
150149
exit_code = 0
151-
150+
152151
# Line buffers for streaming
153152
stdout_line_buf = bytearray()
154153
stderr_line_buf = bytearray()
155-
154+
156155
def handle_stdout(data: bytes) -> None:
157156
"""Handle stdout from shell."""
158157
nonlocal stdout_buf, exit_code, stdout_line_buf
159158

160159
# Add to line buffer for streaming
161160
stdout_line_buf.extend(data)
162-
161+
163162
# Process complete lines for streaming
164-
while b'\n' in stdout_line_buf:
165-
line_end = stdout_line_buf.index(b'\n')
166-
line = stdout_line_buf[:line_end + 1]
167-
stdout_line_buf = stdout_line_buf[line_end + 1:]
168-
163+
while b"\n" in stdout_line_buf:
164+
line_end = stdout_line_buf.index(b"\n")
165+
line = stdout_line_buf[: line_end + 1]
166+
stdout_line_buf = stdout_line_buf[line_end + 1 :]
167+
169168
# Apply existing filter to the line and stream if requested
170169
if stream_output:
171170
filtered = _filter_shell_output(line, command)
172171
if filtered and filtered.strip():
173172
try:
174173
import sys
174+
175175
sys.stdout.buffer.write(filtered)
176176
sys.stdout.buffer.flush()
177177
except Exception:
178178
try:
179179
import sys
180+
180181
sys.stdout.write(filtered.decode("utf-8", errors="replace"))
181182
sys.stdout.flush()
182183
except Exception:
@@ -205,32 +206,34 @@ def handle_stdout(data: bytes) -> None:
205206
def handle_stderr(data: bytes) -> None:
206207
"""Handle stderr from shell."""
207208
nonlocal stderr_buf, stderr_line_buf
208-
209+
209210
# Add to line buffer for streaming
210211
stderr_line_buf.extend(data)
211-
212+
212213
# Process complete lines for streaming
213-
while b'\n' in stderr_line_buf:
214-
line_end = stderr_line_buf.index(b'\n')
215-
line = stderr_line_buf[:line_end + 1]
216-
stderr_line_buf = stderr_line_buf[line_end + 1:]
217-
214+
while b"\n" in stderr_line_buf:
215+
line_end = stderr_line_buf.index(b"\n")
216+
line = stderr_line_buf[: line_end + 1]
217+
stderr_line_buf = stderr_line_buf[line_end + 1 :]
218+
218219
# Apply existing filter to stderr line and stream if requested
219220
if stream_output:
220221
filtered = _filter_shell_output(line, command)
221222
if filtered and filtered.strip():
222223
try:
223224
import sys
225+
224226
sys.stderr.buffer.write(filtered)
225227
sys.stderr.buffer.flush()
226228
except Exception:
227229
try:
228230
import sys
231+
229232
sys.stderr.write(filtered.decode("utf-8", errors="replace"))
230233
sys.stderr.flush()
231234
except Exception:
232235
pass
233-
236+
234237
stderr_buf.extend(data)
235238

236239
def handle_closed() -> None:
@@ -281,7 +284,6 @@ def handle_closed() -> None:
281284
else:
282285
final_stdout = _filter_shell_output(bytes(stdout_buf), command)
283286

284-
285287
return CommandResult(
286288
stdout=final_stdout,
287289
stderr=bytes(stderr_buf), # Now using proper stderr separation

0 commit comments

Comments
 (0)