def stream(self, val): # type: (Any) -> None if val is None: return self._stream = None if isinstance(val, text_type): self.name = "<unicode string>" self.check_printable(val) self.buffer = val + u'\0' elif isinstance(val, binary_type): self.name = "<byte string>" self.raw_buffer = val self.determine_encoding() else: if not hasattr(val, 'read'): raise YAMLStreamError('stream argument needs to have a read() method') self._stream = val self.name = getattr(self.stream, 'name', "<file>") self.eof = False self.raw_buffer = None self.determine_encoding()
def stream(self): # type: () -> Any try: return self._stream except AttributeError: raise YAMLStreamError('input stream needs to specified')