Ejemplo n.º 1
0
 def from_stream_fixture(self, request, _App0Marker__init_):
     bytes_ = b'\x00\x10JFIF\x00\x01\x01\x01\x00\x2A\x00\x18'
     stream_reader = StreamReader(BytesIO(bytes_), BIG_ENDIAN)
     marker_code, offset, length = JPEG_MARKER_CODE.APP0, 0, 16
     density_units, x_density, y_density = 1, 42, 24
     return (stream_reader, marker_code, offset, _App0Marker__init_, length,
             density_units, x_density, y_density)
Ejemplo n.º 2
0
 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)
Ejemplo n.º 3
0
 def iter_fixture(self, _IfdEntryFactory_, ifd_entry_, ifd_entry_2_):
     stream_rdr = StreamReader(BytesIO(b'\x00\x02'), BIG_ENDIAN)
     offsets = [2, 14]
     ifd_parser = _IfdParser(stream_rdr, offset=0)
     expected_entries = [ifd_entry_, ifd_entry_2_]
     return (ifd_parser, _IfdEntryFactory_, stream_rdr, offsets,
             expected_entries)
Ejemplo n.º 4
0
 def from_stream_fixture(self, request, _SofMarker__init_):
     bytes_ = b'\x00\x11\x00\x00\x2A\x00\x18'
     stream_reader = StreamReader(BytesIO(bytes_), BIG_ENDIAN)
     marker_code, offset, length = JPEG_MARKER_CODE.SOF0, 0, 17
     px_width, px_height = 24, 42
     return (stream_reader, marker_code, offset, _SofMarker__init_, length,
             px_width, px_height)
Ejemplo n.º 5
0
 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
Ejemplo n.º 6
0
 def from_stream_fixture(self, request, _App1Marker__init_,
                         _tiff_from_exif_segment_):
     bytes_ = b'\x00\x42Exif\x00\x00'
     stream_reader = StreamReader(BytesIO(bytes_), BIG_ENDIAN)
     marker_code, offset, length = JPEG_MARKER_CODE.APP1, 0, 66
     horz_dpi, vert_dpi = 42, 24
     return (stream_reader, marker_code, offset, _App1Marker__init_, length,
             _tiff_from_exif_segment_, horz_dpi, vert_dpi)
Ejemplo n.º 7
0
 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
Ejemplo n.º 8
0
 def from_stream_fixture(
         self, _parse_value_, _IfdEntry__init_, value_):
     bytes_ = b'\x00\x01\x66\x66\x00\x00\x00\x02\x00\x00\x00\x03'
     stream_rdr = StreamReader(BytesIO(bytes_), BIG_ENDIAN)
     offset, tag_code, value_count, value_offset = 0, 1, 2, 3
     return (
         stream_rdr, offset, _parse_value_, value_count, value_offset,
         _IfdEntry__init_, tag_code, value_
     )
Ejemplo n.º 9
0
    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)
Ejemplo n.º 10
0
    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)
Ejemplo n.º 11
0
    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)
Ejemplo n.º 12
0
    def it_can_construct_from_a_stream_and_offset(self, _parse_value_,
                                                  _IfdEntry__init_, value_):
        bytes_ = b"\x00\x01\x66\x66\x00\x00\x00\x02\x00\x00\x00\x03"
        stream_rdr = StreamReader(BytesIO(bytes_), BIG_ENDIAN)
        offset, tag_code, value_count, value_offset = 0, 1, 2, 3
        _parse_value_.return_value = value_

        ifd_entry = _IfdEntry.from_stream(stream_rdr, offset)

        _parse_value_.assert_called_once_with(stream_rdr, offset, value_count,
                                              value_offset)
        _IfdEntry__init_.assert_called_once_with(ANY, tag_code, value_)
        assert isinstance(ifd_entry, _IfdEntry)
Ejemplo n.º 13
0
    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)
Ejemplo n.º 14
0
 def fixture(self, request, ifd_entry_, _IfdEntry_, _AsciiIfdEntry_,
             _ShortIfdEntry_, _LongIfdEntry_, _RationalIfdEntry_):
     bytes_, entry_type = request.param
     entry_cls_ = {
         'BYTE': _IfdEntry_,
         'ASCII': _AsciiIfdEntry_,
         'SHORT': _ShortIfdEntry_,
         'LONG': _LongIfdEntry_,
         'RATIONAL': _RationalIfdEntry_,
         'CUSTOM': _IfdEntry_,
     }[entry_type]
     stream_rdr = StreamReader(BytesIO(bytes_), BIG_ENDIAN)
     offset = 0
     return stream_rdr, offset, entry_cls_, ifd_entry_
Ejemplo n.º 15
0
 def fixture(
     self,
     request,
     ifd_entry_,
     _IfdEntry_,
     _AsciiIfdEntry_,
     _ShortIfdEntry_,
     _LongIfdEntry_,
     _RationalIfdEntry_,
 ):
     bytes_, entry_type = request.param
     entry_cls_ = {
         "BYTE": _IfdEntry_,
         "ASCII": _AsciiIfdEntry_,
         "SHORT": _ShortIfdEntry_,
         "LONG": _LongIfdEntry_,
         "RATIONAL": _RationalIfdEntry_,
         "CUSTOM": _IfdEntry_,
     }[entry_type]
     stream_rdr = StreamReader(BytesIO(bytes_), BIG_ENDIAN)
     offset = 0
     return stream_rdr, offset, entry_cls_, ifd_entry_
Ejemplo n.º 16
0
 def read_long_fixture(self, request):
     byte_order, bytes_, offset, expected_int = request.param
     stream = BytesIO(bytes_)
     stream_rdr = StreamReader(stream, byte_order)
     return stream_rdr, offset, expected_int
Ejemplo n.º 17
0
 def non_Exif_fixture(self, request, _App1Marker__init_):
     bytes_ = b'\x00\x42Foobar'
     stream_reader = StreamReader(BytesIO(bytes_), BIG_ENDIAN)
     marker_code, offset, length = JPEG_MARKER_CODE.APP1, 0, 66
     return stream_reader, marker_code, offset, _App1Marker__init_, length
Ejemplo n.º 18
0
 def it_can_parse_a_short_int_IFD_entry(self):
     bytes_ = b"foobaroo\x00\x2A"
     stream_rdr = StreamReader(BytesIO(bytes_), BIG_ENDIAN)
     val = _ShortIfdEntry._parse_value(stream_rdr, 0, 1, None)
     assert val == 42
Ejemplo n.º 19
0
 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
Ejemplo n.º 20
0
 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_)
Ejemplo n.º 21
0
 def read_str_fixture(self):
     stream = BytesIO(b'\x01\x02foobar\x03\x04')
     stream_rdr = StreamReader(stream, BIG_ENDIAN)
     expected_string = 'foobar'
     return stream_rdr, expected_string
Ejemplo n.º 22
0
 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
Ejemplo n.º 23
0
 def it_can_parse_a_rational_IFD_entry(self):
     bytes_ = b'\x00\x00\x00\x2A\x00\x00\x00\x54'
     stream_rdr = StreamReader(BytesIO(bytes_), BIG_ENDIAN)
     val = _RationalIfdEntry._parse_value(stream_rdr, None, 1, 0)
     assert val == 0.5
Ejemplo n.º 24
0
 def it_can_parse_a_long_int_IFD_entry(self):
     bytes_ = b'foobaroo\x00\x00\x00\x2A'
     stream_rdr = StreamReader(BytesIO(bytes_), BIG_ENDIAN)
     val = _LongIfdEntry._parse_value(stream_rdr, 0, 1, None)
     assert val == 42
Ejemplo n.º 25
0
 def it_can_parse_an_ascii_string_IFD_entry(self):
     bytes_ = b'foobar\x00'
     stream_rdr = StreamReader(BytesIO(bytes_), BIG_ENDIAN)
     val = _AsciiIfdEntry._parse_value(stream_rdr, None, 7, 0)
     assert val == 'foobar'