tailhead/__init__.py
def seek_next_line(self):
        """
        Seek next line relative to the current file position.

        :return: Position of the line or -1 if next line was not found.
        """
        where = self.file.tell()
        offset = 0

        while True:
            data_len, data = self.read(self.read_size)
            data_where = 0

            if not data_len:
                break

            # Consider the following example: Foo\r | \nBar where " | " denotes current position,
            # 'Foo\r' is the read part and '\nBar' is the remaining part.
            # We should completely consume terminator "\r\n" by reading one extra byte.
            if b'\r\n' in self.LINE_TERMINATORS and data[-1] == b'\r'[0]:
                terminator_where = self.file.tell()
                terminator_len, terminator_data = self.read(1)

                if terminator_len and terminator_data[0] == b'\n'[0]:
                    data_len += 1
                    data += b'\n'
                else:
                    self.file.seek(terminator_where)

            while data_where < data_len:
                terminator = self.prefix_line_terminator(data[data_where:])
                if terminator:
                    self.file.seek(where + offset + data_where + len(terminator))
                    return self.file.tell()
                else:
                    data_where += 1

            offset += data_len
            self.file.seek(where + offset)

        return -1
def seek_next_line(self):
        where = self.file.tell()
        offset = 0

        while True:
            data_len, data = self.read(self.read_size)
            data_where = 0

            if not data_len:
                break

            # Consider the following example: Foo\r | \nBar where " | " denotes current position,
            # 'Foo\r' is the read part and '\nBar' is the remaining part.
            # We should completely consume terminator "\r\n" by reading one extra byte.
            if b'\r\n' in self.LINE_TERMINATORS and data[-1] == b'\r'[0]:
                terminator_where = self.file.tell()
                terminator_len, terminator_data = self.read(1)

                if terminator_len and terminator_data[0] == b'\n'[0]:
                    data_len += 1
                    data += b'\n'
                else:
                    self.file.seek(terminator_where)

            while data_where < data_len:
                terminator = self.prefix_line_terminator(data[data_where:])
                if terminator:
                    self.file.seek(where + offset + data_where + len(terminator))
                    return self.file.tell()
                else:
                    data_where += 1

            offset += data_len
            self.file.seek(where + offset)

        return -1
def seek_next_line ( self ) : where = self . file . tell ( ) offset = 0 while True : data_len , data = self . read ( self . read_size ) data_where = 0 if not data_len : break # Consider the following example: Foo\r | \nBar where " | " denotes current position, # 'Foo\r' is the read part and '\nBar' is the remaining part. # We should completely consume terminator "\r\n" by reading one extra byte. if b'\r\n' in self . LINE_TERMINATORS and data [ - 1 ] == b'\r' [ 0 ] : terminator_where = self . file . tell ( ) terminator_len , terminator_data = self . read ( 1 ) if terminator_len and terminator_data [ 0 ] == b'\n' [ 0 ] : data_len += 1 data += b'\n' else : self . file . seek ( terminator_where ) while data_where < data_len : terminator = self . prefix_line_terminator ( data [ data_where : ] ) if terminator : self . file . seek ( where + offset + data_where + len ( terminator ) ) return self . file . tell ( ) else : data_where += 1 offset += data_len self . file . seek ( where + offset ) return - 1
Seek next line relative to the current file position.

        :return: Position of the line or -1 if next line was not found.
Seek next line relative to the current file position .