Esempio n. 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"])
Esempio n. 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'])
Esempio n. 3
0
    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
Esempio n. 4
0
    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
Esempio n. 5
0
 def __iter__(self):
     return iotools.line_iterator(self)
Esempio n. 6
0
 def readline(self, size=None):
     return next(iotools.line_iterator(self, size))
Esempio n. 7
0
 def readline(self, size=None):
     return next(iotools.line_iterator(self, size))
Esempio n. 8
0
 def readline(self, size=-1):
     return next(line_iterator(self, None if size == -1 else size))
Esempio n. 9
0
 def __iter__(self):
     return iotools.line_iterator(self)