mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-25 00:51:20 +00:00
Merge PR #458: Add explicit UTF-8 encoding to config/data file I/O
Authored by shitcoinsherpa. Adds encoding='utf-8' to all text-mode open() calls in gateway/run.py, gateway/config.py, hermes_cli/config.py, hermes_cli/main.py, and hermes_cli/status.py. Prevents encoding errors on Windows where the default locale is not UTF-8. Also fixed 4 additional open() calls in gateway/run.py that were added after the PR branch was created.
This commit is contained in:
commit
36328a996f
6 changed files with 51 additions and 48 deletions
|
|
@ -194,6 +194,8 @@ def _prompt_for_sudo_password(timeout_seconds: int = 45) -> str:
|
|||
|
||||
def read_password_thread():
|
||||
"""Read password with echo disabled. Uses msvcrt on Windows, /dev/tty on Unix."""
|
||||
tty_fd = None
|
||||
old_attrs = None
|
||||
try:
|
||||
if platform.system() == "Windows":
|
||||
import msvcrt
|
||||
|
|
@ -213,28 +215,29 @@ def _prompt_for_sudo_password(timeout_seconds: int = 45) -> str:
|
|||
new_attrs = termios.tcgetattr(tty_fd)
|
||||
new_attrs[3] = new_attrs[3] & ~termios.ECHO
|
||||
termios.tcsetattr(tty_fd, termios.TCSAFLUSH, new_attrs)
|
||||
try:
|
||||
chars = []
|
||||
while True:
|
||||
b = os.read(tty_fd, 1)
|
||||
if not b or b in (b"\n", b"\r"):
|
||||
break
|
||||
chars.append(b)
|
||||
result["password"] = b"".join(chars).decode("utf-8", errors="replace")
|
||||
finally:
|
||||
try:
|
||||
termios.tcsetattr(tty_fd, termios.TCSAFLUSH, old_attrs)
|
||||
except Exception:
|
||||
pass
|
||||
try:
|
||||
os.close(tty_fd)
|
||||
except Exception:
|
||||
pass
|
||||
chars = []
|
||||
while True:
|
||||
b = os.read(tty_fd, 1)
|
||||
if not b or b in (b"\n", b"\r"):
|
||||
break
|
||||
chars.append(b)
|
||||
result["password"] = b"".join(chars).decode("utf-8", errors="replace")
|
||||
except (EOFError, KeyboardInterrupt, OSError):
|
||||
result["password"] = ""
|
||||
except Exception:
|
||||
result["password"] = ""
|
||||
finally:
|
||||
if tty_fd is not None and old_attrs is not None:
|
||||
try:
|
||||
import termios as _termios
|
||||
_termios.tcsetattr(tty_fd, _termios.TCSAFLUSH, old_attrs)
|
||||
except Exception:
|
||||
pass
|
||||
if tty_fd is not None:
|
||||
try:
|
||||
os.close(tty_fd)
|
||||
except Exception:
|
||||
pass
|
||||
result["done"] = True
|
||||
|
||||
try:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue