def _content_reader(self, max_length): if max_length is None: length_to_read = self._remaining_length else: length_to_read = min(max_length, self._remaining_length) self._remaining_length -= length_to_read bytes = self.reader_func(length_to_read) if len(bytes) != length_to_read: raise errors.UnexpectedEndOfContainerError() return bytes
def _iter_record_objects(self): while True: record_kind = self.reader_func(1) if record_kind == 'B': # Bytes record. reader = BytesRecordReader(self._source) yield reader elif record_kind == 'E': # End marker. There are no more records. return elif record_kind == '': # End of stream encountered, but no End Marker record seen, so # this container is incomplete. raise errors.UnexpectedEndOfContainerError() else: # Unknown record type. raise errors.UnknownRecordTypeError(record_kind)
def _read_line(self): line = self._source.readline() if not line.endswith('\n'): raise errors.UnexpectedEndOfContainerError() return line.rstrip('\n')
def test_unexpected_end_of_container(self): """Test the formatting of UnexpectedEndOfContainerError.""" e = errors.UnexpectedEndOfContainerError() self.assertEqual("Unexpected end of container stream", str(e))