41 lines
1.0 KiB
Python
41 lines
1.0 KiB
Python
from abc import ABC, abstractmethod
|
|
|
|
class IOBuffer(ABC):
|
|
"""
|
|
Abstract base class defining the interface for input/output operations.
|
|
|
|
This interface allows for different implementations of IO handling,
|
|
such as direct system IO or buffered web interface communication.
|
|
"""
|
|
|
|
@abstractmethod
|
|
def read(self) -> str:
|
|
"""
|
|
Read and return available input.
|
|
|
|
Should clear the input buffer after reading.
|
|
|
|
Returns:
|
|
str: Content from input buffer, or empty string if no input available
|
|
"""
|
|
pass
|
|
|
|
@abstractmethod
|
|
def write(self, content: str) -> None:
|
|
"""
|
|
Write content to output.
|
|
|
|
Args:
|
|
content: String content to write
|
|
"""
|
|
pass
|
|
|
|
@abstractmethod
|
|
def buffer_length(self) -> int:
|
|
"""
|
|
Get the current length of buffered input.
|
|
|
|
Returns:
|
|
int: Number of characters in the input buffer
|
|
"""
|
|
pass |