Пример #1
0
    def dumpf(self, obj, fp: IOBase, options: dict):
        'dump a obj into the file-like object.'

        assert fp.writable()
        if isinstance(fp, _TextIOBase):
            fp.write(self.dumps(obj, options))
        else:
            fp.write(self.dumpb(obj, options))
Пример #2
0
def test_attributes_iobase(sio: io.IOBase) -> None:
    """Check basic attrs/descriptor functions related to being subclass of io.IOBase."""
    assert sio is not None
    assert isinstance(sio, io.IOBase)
    assert isinstance(sio, io.RawIOBase)
    assert not isinstance(sio, io.TextIOBase)
    assert sio.readable() is True
    assert sio.writable() is True
    assert sio.seekable() is False
    assert sio.isatty() is False
    assert sio.closed() is False
Пример #3
0
    def __init__(self, handle : io.IOBase, key : Union[Iterable[int], int, str, None]):
        self._init_key(key)

        self._handle = handle
        self._size = 0
        self._pos = 0
        self._buffer = bytearray(8)

        if handle.readable():
            # Don't assert due to BriceIsSmart
            handle.read(12)
            self._size = self._readu32()
        if handle.writable():
            self._write_header()
Пример #4
0
    def read_into_stream(self, stream: io.IOBase, *,
                         encoding=None, buffering: int = -1):
        ''' read all content into stream. '''
        if not isinstance(stream, io.IOBase):
            raise TypeError(type(stream))
        if not stream.writable():
            raise ValueError('stream is unable to write.')

        if isinstance(stream, io.TextIOBase):
            fp = self.open_for_read_text(encoding=encoding or 'utf-8')
        else:
            fp = self.open_for_read_bytes(buffering=buffering)

        with fp as fsrc:
            shutil.copyfileobj(fsrc, stream)