class IOFount(object): """ Fount that reads from a file-like-object. """ outputType = ISegment _source = attrib() # type: BinaryIO drain = attrib( validator=optional(provides(IDrain)), default=None, init=False ) # type: IDrain _paused = attrib(validator=instance_of(bool), default=False, init=False) def __attrs_post_init__(self): # type: () -> None self._pauser = Pauser(self._pause, self._resume) def _flowToDrain(self): # type: () -> None if self.drain is not None and not self._paused: data = self._source.read() if data: self.drain.receive(data) self.drain.flowStopped(Failure(StopIteration())) def flowTo(self, drain): # type: (IDrain) -> IFount result = beginFlowingTo(self, drain) self._flowToDrain() return result def pauseFlow(self): # type: () -> None return self._pauser.pause() def stopFlow(self): # type: () -> None return self._pauser.resume() def _pause(self): # type: () -> None self._paused = True def _resume(self): # type: () -> None self._paused = False self._flowToDrain()
def __attrs_post_init__(self): # type: () -> None self._pauser = Pauser(self._pause, self._resume)
def __attrs_post_init__(self) -> None: self._pauser = Pauser(self._pause, self._resume)