コード例 #1
0
    def test_line_iterator(self):
        f = io.BytesIO(b"Hello\nWorld\n\nfoo")
        self.assertEqual(list(iotools.line_iterator(f)),
                         [b"Hello\n", b"World\n", b"\n", b"foo"])

        f = io.BytesIO(b"Hello\nWorld\n\nfoo")
        self.assertEqual(list(iotools.line_iterator(f, 10)),
                         [b"Hello\n", b"Worl"])
コード例 #2
0
    def test_line_iterator(self):
        f = io.BytesIO(b'Hello\nWorld\n\nfoo')
        self.assertEqual(list(iotools.line_iterator(f)),
                         [b'Hello\n', b'World\n', b'\n', b'foo'])

        f = io.BytesIO(b'Hello\nWorld\n\nfoo')
        self.assertEqual(list(iotools.line_iterator(f, 10)),
                         [b'Hello\n', b'Worl'])
コード例 #3
0
ファイル: _onedatafs.py プロジェクト: onedata/fs-onedatafs
    def readline(self, size=-1):
        """
        Read `size` bytes from the file starting from current position
        in the file until the end of the line.

        If `size` is negative read until end of the line.

        :param int size: Number of bytes to read from the current line.
        """
        # type: (int) -> bytes

        return next(line_iterator(self, size))  # type: ignore
コード例 #4
0
ファイル: _onedatafs.py プロジェクト: onedata/fs-onedatafs
    def readlines(self, hint=-1):
        """
        Read `hint` lines from the file starting from current position.

        If `hint` is negative read until end of the line.

        :param int hint: Number of lines to read.
        """
        # type: (int) -> List[bytes]

        lines = []
        size = 0
        for line in line_iterator(self):  # type: ignore
            lines.append(line)
            size += len(line)
            if hint != -1 and size > hint:
                break
        return lines
コード例 #5
0
ファイル: ftpfs.py プロジェクト: svn2github/pyfilesystem
 def __iter__(self):
     return iotools.line_iterator(self)
コード例 #6
0
ファイル: ftpfs.py プロジェクト: svn2github/pyfilesystem
 def readline(self, size=None):
     return next(iotools.line_iterator(self, size))
コード例 #7
0
ファイル: ftpfs.py プロジェクト: smartfile/pyfilesystem
 def readline(self, size=None):
     return next(iotools.line_iterator(self, size))
コード例 #8
0
 def readline(self, size=-1):
     return next(line_iterator(self, None if size == -1 else size))
コード例 #9
0
 def __iter__(self):
     return iotools.line_iterator(self)