mirror of
ssh://git.janware.com/janware/proj/jw-pkg
synced 2026-04-25 17:45:55 +02:00
lib.base: Add module
Add lib.base to provide basic definitions. For now, move the definiions of Result, Input and InputMode from ExecContext into lib.base. Having to import them from the ExecContect module is too heavy-handed for those simple types. Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
04fef1e67a
commit
888c0495ec
17 changed files with 50 additions and 38 deletions
|
|
@ -4,34 +4,14 @@ from __future__ import annotations
|
|||
|
||||
import abc, re, sys
|
||||
from enum import Enum, auto
|
||||
from typing import NamedTuple, TypeAlias, TYPE_CHECKING
|
||||
from typing import NamedTuple, TYPE_CHECKING
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from typing import Self, Type
|
||||
from types import TracebackType
|
||||
|
||||
from .log import *
|
||||
|
||||
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
|
||||
)
|
||||
from .base import Input, InputMode, Result
|
||||
|
||||
class ExecContext(abc.ABC):
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue