jw-pkg/src/python/jw/pkg/lib/base.py

30 lines
764 B
Python
Raw Normal View History

# -*- 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
)