30 lines
764 B
Python
30 lines
764 B
Python
|
|
# -*- coding: utf-8 -*-
|
||
|
|
|
||
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
from enum import Enum, auto
|
||
|
|
from typing import NamedTuple, TypeAlias, TYPE_CHECKING
|
||
|
|
|
||
|
|
if TYPE_CHECKING:
|
||
|
|
from typing import Type
|
||
|
|
|
||
|
|
class InputMode(Enum):
|
||
|
|
Interactive = auto()
|
||
|
|
NonInteractive = auto()
|
||
|
|
OptInteractive = auto()
|
||
|
|
Auto = auto()
|
||
|
|
|
||
|
|
Input: TypeAlias = InputMode | bytes | str
|
||
|
|
|
||
|
|
class Result(NamedTuple):
|
||
|
|
|
||
|
|
stdout: str|None
|
||
|
|
stderr: str|None
|
||
|
|
status: int|None
|
||
|
|
|
||
|
|
def decode(self, encoding='UTF-8', errors='replace') -> Result:
|
||
|
|
return Result(
|
||
|
|
self.stdout.decode(encoding, errors=errors) if self.stdout is not None else None,
|
||
|
|
self.stderr.decode(encoding, errors=errors) if self.stderr is not None else None,
|
||
|
|
self.status
|
||
|
|
)
|