def read(self, length, skip=False):
        """Consumes the first ``length`` bytes from the accumulator."""
        if length > self.__size:
            raise IndexError(
                'Cannot pop %d bytes, %d bytes in buffer queue' % (length, self.__size))
        self.position += length
        self.__size -= length
        segments = self.__segments
        offset = self.__offset

        data = self.__data_cls()
        while length > 0:
            segment = segments[0]
            segment_off = offset
            segment_len = len(segment)
            segment_rem = segment_len - segment_off
            segment_read_len = min(segment_rem, length)

            if segment_off == 0 and segment_read_len == segment_rem:
                # consume an entire segment
                if skip:
                    segment_slice = self.__element_type()
                else:
                    segment_slice = segment
            else:
                # Consume a part of the segment.
                if skip:
                    segment_slice = self.__element_type()
                else:
                    segment_slice = segment[segment_off:segment_off + segment_read_len]
                offset = 0
            segment_off += segment_read_len
            if segment_off == segment_len:
                segments.popleft()
                self.__offset = 0
            else:
                self.__offset = segment_off

            if length <= segment_rem and len(data) == 0:
                return segment_slice
            data.extend(segment_slice)
            length -= segment_read_len
        if self.is_unicode:
            return data.as_text()
        else:
            return data
def read ( self , length , skip = False ) : if length > self . __size : raise IndexError ( 'Cannot pop %d bytes, %d bytes in buffer queue' % ( length , self . __size ) ) self . position += length self . __size -= length segments = self . __segments offset = self . __offset data = self . __data_cls ( ) while length > 0 : segment = segments [ 0 ] segment_off = offset segment_len = len ( segment ) segment_rem = segment_len - segment_off segment_read_len = min ( segment_rem , length ) if segment_off == 0 and segment_read_len == segment_rem : if skip : segment_slice = self . __element_type ( ) else : segment_slice = segment else : if skip : segment_slice = self . __element_type ( ) else : segment_slice = segment [ segment_off : segment_off + segment_read_len ] offset = 0 segment_off += segment_read_len if segment_off == segment_len : segments . popleft ( ) self . __offset = 0 else : self . __offset = segment_off if length <= segment_rem and len ( data ) == 0 : return segment_slice data . extend ( segment_slice ) length -= segment_read_len if self . is_unicode : return data . as_text ( ) else : return data
Consumes the first ``length`` bytes from the accumulator.