def next_fixture(self, request): start, marker_code, segment_offset = request.param bytes_ = b'\xFF\xD8\xFF\xE0\x00\x01\xFF\x00\xFF\xFF\xFF\xD9' stream_reader = StreamReader(BytesIO(bytes_), BIG_ENDIAN) marker_finder = _MarkerFinder(stream_reader) expected_code_and_offset = (marker_code, segment_offset) return marker_finder, start, expected_code_and_offset
def iter_offsets_fixture(self): bytes_ = b'-filler-\x00\x00\x00\x00IHDRxxxx\x00\x00\x00\x00IEND' stream_rdr = StreamReader(BytesIO(bytes_), BIG_ENDIAN) chunk_parser = _ChunkParser(stream_rdr) expected_chunk_offsets = [ (PNG_CHUNK_TYPE.IHDR, 16), (PNG_CHUNK_TYPE.IEND, 28), ] return chunk_parser, expected_chunk_offsets
def it_can_construct_from_non_Exif_APP1_segment(self, _App1Marker__init_): bytes_ = b'\x00\x42Foobar' marker_code, offset, length = JPEG_MARKER_CODE.APP1, 0, 66 stream = StreamReader(BytesIO(bytes_), BIG_ENDIAN) app1_marker = _App1Marker.from_stream(stream, marker_code, offset) _App1Marker__init_.assert_called_once_with(ANY, marker_code, offset, length, 72, 72) assert isinstance(app1_marker, _App1Marker)
def from_offset_fixture(self): bytes_ = b'\x00\x00\x00\x2A\x00\x00\x00\x18\x01' stream_rdr = StreamReader(BytesIO(bytes_), BIG_ENDIAN) offset, horz_px_per_unit, vert_px_per_unit, units_specifier = ( 0, 42, 24, 1 ) return ( stream_rdr, offset, horz_px_per_unit, vert_px_per_unit, units_specifier )
def it_can_construct_from_a_stream_and_offset(self, request, _SofMarker__init_): bytes_ = b'\x00\x11\x00\x00\x2A\x00\x18' marker_code, offset, length = JPEG_MARKER_CODE.SOF0, 0, 17 px_width, px_height = 24, 42 stream = StreamReader(BytesIO(bytes_), BIG_ENDIAN) sof_marker = _SofMarker.from_stream(stream, marker_code, offset) _SofMarker__init_.assert_called_once_with(ANY, marker_code, offset, length, px_width, px_height) assert isinstance(sof_marker, _SofMarker)
def it_can_construct_from_a_stream_and_offset(self, _App0Marker__init_): bytes_ = b'\x00\x10JFIF\x00\x01\x01\x01\x00\x2A\x00\x18' marker_code, offset, length = JPEG_MARKER_CODE.APP0, 0, 16 density_units, x_density, y_density = 1, 42, 24 stream = StreamReader(BytesIO(bytes_), BIG_ENDIAN) app0_marker = _App0Marker.from_stream(stream, marker_code, offset) _App0Marker__init_.assert_called_once_with(ANY, marker_code, offset, length, density_units, x_density, y_density) assert isinstance(app0_marker, _App0Marker)
def it_can_construct_from_a_stream_and_offset(self, _App1Marker__init_, _tiff_from_exif_segment_): bytes_ = b'\x00\x42Exif\x00\x00' marker_code, offset, length = JPEG_MARKER_CODE.APP1, 0, 66 horz_dpi, vert_dpi = 42, 24 stream = StreamReader(BytesIO(bytes_), BIG_ENDIAN) app1_marker = _App1Marker.from_stream(stream, marker_code, offset) _tiff_from_exif_segment_.assert_called_once_with( stream, offset, length) _App1Marker__init_.assert_called_once_with(ANY, marker_code, offset, length, horz_dpi, vert_dpi) assert isinstance(app1_marker, _App1Marker)
def get_tiff_fixture(self, request, BytesIO_, substream_, Tiff_, tiff_): bytes_ = b'xfillerxMM\x00*\x00\x00\x00\x42' stream_reader = StreamReader(BytesIO(bytes_), BIG_ENDIAN) offset, segment_length, segment_bytes = 0, 16, bytes_[8:] return (stream_reader, offset, segment_length, BytesIO_, segment_bytes, substream_, Tiff_, tiff_)
def from_stream_fixture(self, request, _Marker__init_): marker_code, offset, length = request.param bytes_ = b'\xFF\xD8\xFF\xE0\x00\x10' stream_reader = StreamReader(BytesIO(bytes_), BIG_ENDIAN) return stream_reader, marker_code, offset, _Marker__init_, length
def from_offset_fixture(self): bytes_ = b'\x00\x00\x00\x2A\x00\x00\x00\x18' stream_rdr = StreamReader(BytesIO(bytes_), BIG_ENDIAN) offset, px_width, px_height = 0, 42, 24 return stream_rdr, offset, px_width, px_height