Skip to content

Commit

Permalink
Merge pull request #173 from BrianPugh/telnet-tweaks
Browse files Browse the repository at this point in the history
Telnet tweaks; python3.13 compat
  • Loading branch information
BrianPugh authored Oct 16, 2024
2 parents f4d54fc + 07ead55 commit b8e16c8
Show file tree
Hide file tree
Showing 4 changed files with 684 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]

env:
OS: ${{ matrix.os }}
Expand Down
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
exclude: ^belay/telnetlib.py
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
Expand Down
9 changes: 5 additions & 4 deletions belay/pyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,15 @@ def _extract_ip_port(uri):

class TelnetToSerial:
def __init__(self, ip, user, password, read_timeout=None):
import telnetlib
from collections import deque

from belay.telnetlib import Telnet

address, port = _extract_ip_port(ip)
if port is None:
self.tn = telnetlib.Telnet(address, timeout=15)
self.tn = Telnet(address, timeout=15)
else:
self.tn = telnetlib.Telnet(address, port=port, timeout=15)
self.tn = Telnet(address, port=port, timeout=15)

self.fifo = deque()
self.read_timeout = read_timeout
Expand Down Expand Up @@ -169,7 +170,7 @@ def read(self, size=1):
self.fifo.extend(data)
timeout_count = 0
else:
time.sleep(0.25)
time.sleep(0.0001)
if self.read_timeout is not None and timeout_count > 4 * self.read_timeout:
break
timeout_count += 1
Expand Down
Loading

0 comments on commit b8e16c8

Please sign in to comment.