Introduce a string-specific version of clear_vt100_escape_codes (#3241)
This commit helps fix some existing type errors in the code. It also helps avoid ~280,000 isinstance calls when opening the additional packages menu.
This commit is contained in:
parent
2819ea02b1
commit
dbf45e23cc
|
|
@ -7,7 +7,7 @@ from typing import ClassVar
|
|||
from archinstall.lib.models.device_model import Fido2Device
|
||||
|
||||
from ..exceptions import SysCallError
|
||||
from ..general import SysCommand, SysCommandWorker, clear_vt100_escape_codes
|
||||
from ..general import SysCommand, SysCommandWorker, clear_vt100_escape_codes_from_str
|
||||
from ..output import error, info
|
||||
|
||||
|
||||
|
|
@ -44,7 +44,7 @@ class Fido2:
|
|||
error('fido2 support is most likely not installed')
|
||||
raise ValueError('HSM devices can not be detected, is libfido2 installed?')
|
||||
|
||||
fido_devices: str = clear_vt100_escape_codes(ret) # type: ignore[assignment]
|
||||
fido_devices = clear_vt100_escape_codes_from_str(ret)
|
||||
|
||||
manufacturer_pos = 0
|
||||
product_pos = 0
|
||||
|
|
|
|||
|
|
@ -44,9 +44,11 @@ def locate_binary(name: str) -> str:
|
|||
raise RequirementError(f"Binary {name} does not exist.")
|
||||
|
||||
|
||||
def clear_vt100_escape_codes(data: bytes | str) -> bytes | str:
|
||||
if isinstance(data, bytes):
|
||||
return re.sub(_VT100_ESCAPE_REGEX_BYTES, b'', data)
|
||||
def clear_vt100_escape_codes(data: bytes) -> bytes:
|
||||
return re.sub(_VT100_ESCAPE_REGEX_BYTES, b'', data)
|
||||
|
||||
|
||||
def clear_vt100_escape_codes_from_str(data: str) -> str:
|
||||
return re.sub(_VT100_ESCAPE_REGEX, '', data)
|
||||
|
||||
|
||||
|
|
@ -159,7 +161,7 @@ class SysCommandWorker:
|
|||
lines = filter(None, self._trace_log[self._trace_log_pos:last_line].splitlines())
|
||||
for line in lines:
|
||||
if self.remove_vt100_escape_codes_from_lines:
|
||||
line = clear_vt100_escape_codes(line) # type: ignore[assignment]
|
||||
line = clear_vt100_escape_codes(line)
|
||||
|
||||
yield line + b'\n'
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue