{
    "file_diffs": [
        {
            "old_file_content": "#\n# The Python Imaging Library.\n# $Id$\n#\n# IPTC/NAA file handling\n#\n# history:\n# 1995-10-01 fl   Created\n# 1998-03-09 fl   Cleaned up and added to PIL\n# 2002-06-18 fl   Added getiptcinfo helper\n#\n# Copyright (c) Secret Labs AB 1997-2002.\n# Copyright (c) Fredrik Lundh 1995.\n#\n# See the README file for information on usage and redistribution.\n#\n\nfrom __future__ import print_function\n\n__version__ = \"0.3\"\n\n\nfrom PIL import Image, ImageFile, _binary\nimport os\nimport tempfile\n\ni8 = _binary.i8\ni16 = _binary.i16be\ni32 = _binary.i32be\no8 = _binary.o8\n\nCOMPRESSION = {\n    1: \"raw\",\n    5: \"jpeg\"\n}\n\nPAD = o8(0) * 4\n\n\n#\n# Helpers\n\ndef i(c):\n    return i32((PAD + c)[-4:])\n\n\ndef dump(c):\n    for i in c:\n        print(\"%02x\" % i8(i), end=' ')\n    print()\n\n\n##\n# Image plugin for IPTC/NAA datastreams.  To read IPTC/NAA fields\n# from TIFF and JPEG files, use the <b>getiptcinfo</b> function.\n\nclass IptcImageFile(ImageFile.ImageFile):\n\n    format = \"IPTC\"\n    format_description = \"IPTC/NAA\"\n\n    def getint(self, key):\n        return i(self.info[key])\n\n    def field(self):\n        #\n        # get a IPTC field header\n        s = self.fp.read(5)\n        if not len(s):\n            return None, 0\n\n        tag = i8(s[1]), i8(s[2])\n\n        # syntax\n        if i8(s[0]) != 0x1C or tag[0] < 1 or tag[0] > 9:\n            raise SyntaxError(\"invalid IPTC/NAA file\")\n\n        # field size\n        size = i8(s[3])\n        if size > 132:\n            raise IOError(\"illegal field length in IPTC/NAA file\")\n        elif size == 128:\n            size = 0\n        elif size > 128:\n            size = i(self.fp.read(size-128))\n        else:\n            size = i16(s[3:])\n\n        return tag, size\n\n    def _is_raw(self, offset, size):\n        #\n        # check if the file can be mapped\n\n        # DISABLED: the following only slows things down...\n        return 0\n\n        self.fp.seek(offset)\n        t, sz = self.field()\n        if sz != size[0]:\n            return 0\n        y = 1\n        while True:\n            self.fp.seek(sz, 1)\n            t, s = self.field()\n            if t != (8, 10):\n                break\n            if s != sz:\n                return 0\n            y += 1\n        return y == size[1]\n\n    def _open(self):\n\n        # load descriptive fields\n        while True:\n            offset = self.fp.tell()\n            tag, size = self.field()\n            if not tag or tag == (8, 10):\n                break\n            if size:\n                tagdata = self.fp.read(size)\n            else:\n                tagdata = None\n            if tag in list(self.info.keys()):\n                if isinstance(self.info[tag], list):\n                    self.info[tag].append(tagdata)\n                else:\n                    self.info[tag] = [self.info[tag], tagdata]\n            else:\n                self.info[tag] = tagdata\n\n            # print tag, self.info[tag]\n\n        # mode\n        layers = i8(self.info[(3, 60)][0])\n        component = i8(self.info[(3, 60)][1])\n        if (3, 65) in self.info:\n            id = i8(self.info[(3, 65)][0])-1\n        else:\n            id = 0\n        if layers == 1 and not component:\n            self.mode = \"L\"\n        elif layers == 3 and component:\n            self.mode = \"RGB\"[id]\n        elif layers == 4 and component:\n            self.mode = \"CMYK\"[id]\n\n        # size\n        self.size = self.getint((3, 20)), self.getint((3, 30))\n\n        # compression\n        try:\n            compression = COMPRESSION[self.getint((3, 120))]\n        except KeyError:\n            raise IOError(\"Unknown IPTC image compression\")\n\n        # tile\n        if tag == (8, 10):\n            if compression == \"raw\" and self._is_raw(offset, self.size):\n                self.tile = [(compression, (offset, size + 5, -1),\n                             (0, 0, self.size[0], self.size[1]))]\n            else:\n                self.tile = [(\"iptc\", (compression, offset),\n                             (0, 0, self.size[0], self.size[1]))]\n\n    def load(self):\n\n        if len(self.tile) != 1 or self.tile[0][0] != \"iptc\":\n            return ImageFile.ImageFile.load(self)\n\n        type, tile, box = self.tile[0]\n\n        encoding, offset = tile\n\n        self.fp.seek(offset)\n\n        # Copy image data to temporary file\n        o_fd, outfile = tempfile.mkstemp(text=False)\n        o = os.fdopen(o_fd)\n        if encoding == \"raw\":\n            # To simplify access to the extracted file,\n            # prepend a PPM header\n            o.write(\"P5\\n%d %d\\n255\\n\" % self.size)\n        while True:\n            type, size = self.field()\n            if type != (8, 10):\n                break\n            while size > 0:\n                s = self.fp.read(min(size, 8192))\n                if not s:\n                    break\n                o.write(s)\n                size -= len(s)\n        o.close()\n\n        try:\n            try:\n                # fast\n                self.im = Image.core.open_ppm(outfile)\n            except:\n                # slightly slower\n                im = Image.open(outfile)\n                im.load()\n                self.im = im.im\n        finally:\n            try:\n                os.unlink(outfile)\n            except:\n                pass\n\n\nImage.register_open(\"IPTC\", IptcImageFile)\n\nImage.register_extension(\"IPTC\", \".iim\")\n\n\n##\n# Get IPTC information from TIFF, JPEG, or IPTC file.\n#\n# @param im An image containing IPTC data.\n# @return A dictionary containing IPTC information, or None if\n#     no IPTC information block was found.\n\ndef getiptcinfo(im):\n\n    from PIL import TiffImagePlugin, JpegImagePlugin\n    import io\n\n    data = None\n\n    if isinstance(im, IptcImageFile):\n        # return info dictionary right away\n        return im.info\n\n    elif isinstance(im, JpegImagePlugin.JpegImageFile):\n        # extract the IPTC/NAA resource\n        try:\n            app = im.app[\"APP13\"]\n            if app[:14] == \"Photoshop 3.0\\x00\":\n                app = app[14:]\n                # parse the image resource block\n                offset = 0\n                while app[offset:offset+4] == \"8BIM\":\n                    offset += 4\n                    # resource code\n                    code = JpegImagePlugin.i16(app, offset)\n                    offset += 2\n                    # resource name (usually empty)\n                    name_len = i8(app[offset])\n                    name = app[offset+1:offset+1+name_len]\n                    offset = 1 + offset + name_len\n                    if offset & 1:\n                        offset += 1\n                    # resource data block\n                    size = JpegImagePlugin.i32(app, offset)\n                    offset += 4\n                    if code == 0x0404:\n                        # 0x0404 contains IPTC/NAA data\n                        data = app[offset:offset+size]\n                        break\n                    offset = offset + size\n                    if offset & 1:\n                        offset += 1\n        except (AttributeError, KeyError):\n            pass\n\n    elif isinstance(im, TiffImagePlugin.TiffImageFile):\n        # get raw data from the IPTC/NAA tag (PhotoShop tags the data\n        # as 4-byte integers, so we cannot use the get method...)\n        try:\n            data = im.tag.tagdata[TiffImagePlugin.IPTC_NAA_CHUNK]\n        except (AttributeError, KeyError):\n            pass\n\n    if data is None:\n        return None  # no properties\n\n    # create an IptcImagePlugin object without initializing it\n    class FakeImage:\n        pass\n    im = FakeImage()\n    im.__class__ = IptcImageFile\n\n    # parse the IPTC information chunk\n    im.info = {}\n    im.fp = io.BytesIO(data)\n\n    try:\n        im._open()\n    except (IndexError, KeyError):\n        pass  # expected failure\n\n    return im.info\n",
            "new_file_content": "#\n# The Python Imaging Library.\n# $Id$\n#\n# IPTC/NAA file handling\n#\n# history:\n# 1995-10-01 fl   Created\n# 1998-03-09 fl   Cleaned up and added to PIL\n# 2002-06-18 fl   Added getiptcinfo helper\n#\n# Copyright (c) Secret Labs AB 1997-2002.\n# Copyright (c) Fredrik Lundh 1995.\n#\n# See the README file for information on usage and redistribution.\n#\n\nfrom __future__ import print_function\n\n__version__ = \"0.3\"\n\n\nfrom PIL import Image, ImageFile, _binary\nimport os\nimport tempfile\n\ni8 = _binary.i8\ni16 = _binary.i16be\ni32 = _binary.i32be\no8 = _binary.o8\n\nCOMPRESSION = {\n    1: \"raw\",\n    5: \"jpeg\"\n}\n\nPAD = o8(0) * 4\n\n\n#\n# Helpers\n\ndef i(c):\n    return i32((PAD + c)[-4:])\n\n\ndef dump(c):\n    for i in c:\n        print(\"%02x\" % i8(i), end=' ')\n    print()\n\n\n##\n# Image plugin for IPTC/NAA datastreams.  To read IPTC/NAA fields\n# from TIFF and JPEG files, use the <b>getiptcinfo</b> function.\n\nclass IptcImageFile(ImageFile.ImageFile):\n\n    format = \"IPTC\"\n    format_description = \"IPTC/NAA\"\n\n    def getint(self, key):\n        return i(self.info[key])\n\n    def field(self):\n        #\n        # get a IPTC field header\n        s = self.fp.read(5)\n        if not len(s):\n            return None, 0\n\n        tag = i8(s[1]), i8(s[2])\n\n        # syntax\n        if i8(s[0]) != 0x1C or tag[0] < 1 or tag[0] > 9:\n            raise SyntaxError(\"invalid IPTC/NAA file\")\n\n        # field size\n        size = i8(s[3])\n        if size > 132:\n            raise IOError(\"illegal field length in IPTC/NAA file\")\n        elif size == 128:\n            size = 0\n        elif size > 128:\n            size = i(self.fp.read(size-128))\n        else:\n            size = i16(s[3:])\n\n        return tag, size\n\n    def _is_raw(self, offset, size):\n        #\n        # check if the file can be mapped\n\n        # DISABLED: the following only slows things down...\n        return 0\n\n        self.fp.seek(offset)\n        t, sz = self.field()\n        if sz != size[0]:\n            return 0\n        y = 1\n        while True:\n            self.fp.seek(sz, 1)\n            t, s = self.field()\n            if t != (8, 10):\n                break\n            if s != sz:\n                return 0\n            y += 1\n        return y == size[1]\n\n    def _open(self):\n\n        # load descriptive fields\n        while True:\n            offset = self.fp.tell()\n            tag, size = self.field()\n            if not tag or tag == (8, 10):\n                break\n            if size:\n                tagdata = self.fp.read(size)\n            else:\n                tagdata = None\n            if tag in list(self.info.keys()):\n                if isinstance(self.info[tag], list):\n                    self.info[tag].append(tagdata)\n                else:\n                    self.info[tag] = [self.info[tag], tagdata]\n            else:\n                self.info[tag] = tagdata\n\n            # print tag, self.info[tag]\n\n        # mode\n        layers = i8(self.info[(3, 60)][0])\n        component = i8(self.info[(3, 60)][1])\n        if (3, 65) in self.info:\n            id = i8(self.info[(3, 65)][0])-1\n        else:\n            id = 0\n        if layers == 1 and not component:\n            self.mode = \"L\"\n        elif layers == 3 and component:\n            self.mode = \"RGB\"[id]\n        elif layers == 4 and component:\n            self.mode = \"CMYK\"[id]\n\n        # size\n        self.size = self.getint((3, 20)), self.getint((3, 30))\n\n        # compression\n        try:\n            compression = COMPRESSION[self.getint((3, 120))]\n        except KeyError:\n            raise IOError(\"Unknown IPTC image compression\")\n\n        # tile\n        if tag == (8, 10):\n            if compression == \"raw\" and self._is_raw(offset, self.size):\n                self.tile = [(compression, (offset, size + 5, -1),\n                             (0, 0, self.size[0], self.size[1]))]\n            else:\n                self.tile = [(\"iptc\", (compression, offset),\n                             (0, 0, self.size[0], self.size[1]))]\n\n    def load(self):\n\n        if len(self.tile) != 1 or self.tile[0][0] != \"iptc\":\n            return ImageFile.ImageFile.load(self)\n\n        type, tile, box = self.tile[0]\n\n        encoding, offset = tile\n\n        self.fp.seek(offset)\n\n        # Copy image data to temporary file\n        o_fd, outfile = tempfile.mkstemp(text=False)\n        o = os.fdopen(o_fd)\n        if encoding == \"raw\":\n            # To simplify access to the extracted file,\n            # prepend a PPM header\n            o.write(\"P5\\n%d %d\\n255\\n\" % self.size)\n        while True:\n            type, size = self.field()\n            if type != (8, 10):\n                break\n            while size > 0:\n                s = self.fp.read(min(size, 8192))\n                if not s:\n                    break\n                o.write(s)\n                size -= len(s)\n        o.close()\n\n        try:\n            try:\n                # fast\n                self.im = Image.core.open_ppm(outfile)\n            except:\n                # slightly slower\n                im = Image.open(outfile)\n                im.load()\n                self.im = im.im\n        finally:\n            try:\n                os.unlink(outfile)\n            except:\n                pass\n\n\nImage.register_open(\"IPTC\", IptcImageFile)\n\nImage.register_extension(\"IPTC\", \".iim\")\n\n\n##\n# Get IPTC information from TIFF, JPEG, or IPTC file.\n#\n# @param im An image containing IPTC data.\n# @return A dictionary containing IPTC information, or None if\n#     no IPTC information block was found.\n\ndef getiptcinfo(im):\n\n    from PIL import TiffImagePlugin, JpegImagePlugin\n    import io\n\n    data = None\n\n    if isinstance(im, IptcImageFile):\n        # return info dictionary right away\n        return im.info\n\n    elif isinstance(im, JpegImagePlugin.JpegImageFile):\n        # extract the IPTC/NAA resource\n        try:\n            app = im.app[\"APP13\"]\n            if app[:14] == b\"Photoshop 3.0\\x00\":\n                app = app[14:]\n                # parse the image resource block\n                offset = 0\n                while app[offset:offset+4] == b\"8BIM\":\n                    offset += 4\n                    # resource code\n                    code = JpegImagePlugin.i16(app, offset)\n                    offset += 2\n                    # resource name (usually empty)\n                    name_len = i8(app[offset])\n                    name = app[offset+1:offset+1+name_len]\n                    offset = 1 + offset + name_len\n                    if offset & 1:\n                        offset += 1\n                    # resource data block\n                    size = JpegImagePlugin.i32(app, offset)\n                    offset += 4\n                    if code == 0x0404:\n                        # 0x0404 contains IPTC/NAA data\n                        data = app[offset:offset+size]\n                        break\n                    offset = offset + size\n                    if offset & 1:\n                        offset += 1\n        except (AttributeError, KeyError):\n            pass\n\n    elif isinstance(im, TiffImagePlugin.TiffImageFile):\n        # get raw data from the IPTC/NAA tag (PhotoShop tags the data\n        # as 4-byte integers, so we cannot use the get method...)\n        try:\n            data = im.tag.tagdata[TiffImagePlugin.IPTC_NAA_CHUNK]\n        except (AttributeError, KeyError):\n            pass\n\n    if data is None:\n        return None  # no properties\n\n    # create an IptcImagePlugin object without initializing it\n    class FakeImage:\n        pass\n    im = FakeImage()\n    im.__class__ = IptcImageFile\n\n    # parse the IPTC information chunk\n    im.info = {}\n    im.fp = io.BytesIO(data)\n\n    try:\n        im._open()\n    except (IndexError, KeyError):\n        pass  # expected failure\n\n    return im.info\n",
            "header": {
                "file": {
                    "path": "PIL/IptcImagePlugin.py"
                },
                "misc_line": null
            },
            "index_line": {
                "old_commit_hash": "955afbbeb",
                "new_commit_hash": "a94fc7524",
                "mode": "100644"
            },
            "is_binary_file": false,
            "binary_line": null,
            "minus_file": {
                "path": "a/PIL/IptcImagePlugin.py"
            },
            "plus_file": {
                "path": "b/PIL/IptcImagePlugin.py"
            },
            "hunks": [
                {
                    "descriptor": {
                        "old_range": {
                            "start": 237,
                            "length": 11
                        },
                        "new_range": {
                            "start": 237,
                            "length": 11
                        },
                        "section": "def getiptcinfo(im):"
                    },
                    "line_group": {
                        "all_lines": [
                            {
                                "content": "        # extract the IPTC/NAA resource",
                                "type": "context"
                            },
                            {
                                "content": "        try:",
                                "type": "context"
                            },
                            {
                                "content": "            app = im.app[\"APP13\"]",
                                "type": "context"
                            },
                            {
                                "content": "            if app[:14] == \"Photoshop 3.0\\x00\":",
                                "type": "deleted"
                            },
                            {
                                "content": "            if app[:14] == b\"Photoshop 3.0\\x00\":",
                                "type": "added"
                            },
                            {
                                "content": "                app = app[14:]",
                                "type": "context"
                            },
                            {
                                "content": "                # parse the image resource block",
                                "type": "context"
                            },
                            {
                                "content": "                offset = 0",
                                "type": "context"
                            },
                            {
                                "content": "                while app[offset:offset+4] == \"8BIM\":",
                                "type": "deleted"
                            },
                            {
                                "content": "                while app[offset:offset+4] == b\"8BIM\":",
                                "type": "added"
                            },
                            {
                                "content": "                    offset += 4",
                                "type": "context"
                            },
                            {
                                "content": "                    # resource code",
                                "type": "context"
                            },
                            {
                                "content": "                    code = JpegImagePlugin.i16(app, offset)",
                                "type": "context"
                            }
                        ]
                    },
                    "modified_entities": [
                        {
                            "file_name": "PIL/IptcImagePlugin.py",
                            "type": "function",
                            "name": "getiptcinfo",
                            "content": "def getiptcinfo(im):\n\n    from PIL import TiffImagePlugin, JpegImagePlugin\n    import io\n\n    data = None\n\n    if isinstance(im, IptcImageFile):\n        # return info dictionary right away\n        return im.info\n\n    elif isinstance(im, JpegImagePlugin.JpegImageFile):\n        # extract the IPTC/NAA resource\n        try:\n            app = im.app[\"APP13\"]\n            if app[:14] == \"Photoshop 3.0\\x00\":\n                app = app[14:]\n                # parse the image resource block\n                offset = 0\n                while app[offset:offset+4] == \"8BIM\":\n                    offset += 4\n                    # resource code\n                    code = JpegImagePlugin.i16(app, offset)\n                    offset += 2\n                    # resource name (usually empty)\n                    name_len = i8(app[offset])\n                    name = app[offset+1:offset+1+name_len]\n                    offset = 1 + offset + name_len\n                    if offset & 1:\n                        offset += 1\n                    # resource data block\n                    size = JpegImagePlugin.i32(app, offset)\n                    offset += 4\n                    if code == 0x0404:\n                        # 0x0404 contains IPTC/NAA data\n                        data = app[offset:offset+size]\n                        break\n                    offset = offset + size\n                    if offset & 1:\n                        offset += 1\n        except (AttributeError, KeyError):\n            pass\n\n    elif isinstance(im, TiffImagePlugin.TiffImageFile):\n        # get raw data from the IPTC/NAA tag (PhotoShop tags the data\n        # as 4-byte integers, so we cannot use the get method...)\n        try:\n            data = im.tag.tagdata[TiffImagePlugin.IPTC_NAA_CHUNK]\n        except (AttributeError, KeyError):\n            pass\n\n    if data is None:\n        return None  # no properties\n\n    # create an IptcImagePlugin object without initializing it\n    class FakeImage:\n        pass\n    im = FakeImage()\n    im.__class__ = IptcImageFile\n\n    # parse the IPTC information chunk\n    im.info = {}\n    im.fp = io.BytesIO(data)\n\n    try:\n        im._open()\n    except (IndexError, KeyError):\n        pass  # expected failure\n\n    return im.info",
                            "ast_type_str": "FunctionDef",
                            "start_lineno": 225,
                            "end_lineno": 294,
                            "parent": null
                        }
                    ],
                    "added_entities": [],
                    "deleted_entities": []
                }
            ]
        },
        {
            "old_file_content": "from helper import unittest, PillowTestCase, lena\n\nfrom PIL import Image, IptcImagePlugin\n\nTEST_FILE = \"Tests/images/iptc.jpg\"\n\n\nclass TestFileIptc(PillowTestCase):\n\n    # Helpers\n\n    def dummy_IptcImagePlugin(self):\n        # Create an IptcImagePlugin object without initializing it\n        class FakeImage:\n            pass\n        im = FakeImage()\n        im.__class__ = IptcImagePlugin.IptcImageFile\n        return im\n\n    # Tests\n\n    def test_getiptcinfo_jpg_none(self):\n        # Arrange\n        im = lena()\n\n        # Act\n        iptc = IptcImagePlugin.getiptcinfo(im)\n\n        # Assert\n        self.assertIsNone(iptc)\n\n    def test_getiptcinfo_jpg_found(self):\n        # Arrange\n        im = Image.open(TEST_FILE)\n\n        # Act\n        iptc = IptcImagePlugin.getiptcinfo(im)\n\n        # Assert\n        self.assertIsInstance(iptc, dict)\n        self.assertEqual(iptc[(2, 90)], \"Budapest\")\n        self.assertEqual(iptc[(2, 101)], \"Hungary\")\n\n    # _FIXME: is_raw() is disabled. Should we remove it?\n    def test__is_raw_equal_zero(self):\n        # Arrange\n        im = self.dummy_IptcImagePlugin()\n        offset = 0\n        size = 4\n\n        # Act\n        ret = im._is_raw(offset, size)\n\n        # Assert\n        self.assertEqual(ret, 0)\n\n    def test_i(self):\n        # Arrange\n        c = \"a\"\n\n        # Act\n        ret = IptcImagePlugin.i(c)\n\n        # Assert\n        self.assertEqual(ret, 97)\n\n\nif __name__ == '__main__':\n    unittest.main()\n\n# End of file\n",
            "new_file_content": "from helper import unittest, PillowTestCase, lena\n\nfrom PIL import Image, IptcImagePlugin\n\nTEST_FILE = \"Tests/images/iptc.jpg\"\n\n\nclass TestFileIptc(PillowTestCase):\n\n    # Helpers\n\n    def dummy_IptcImagePlugin(self):\n        # Create an IptcImagePlugin object without initializing it\n        class FakeImage:\n            pass\n        im = FakeImage()\n        im.__class__ = IptcImagePlugin.IptcImageFile\n        return im\n\n    # Tests\n\n    def test_getiptcinfo_jpg_none(self):\n        # Arrange\n        im = lena()\n\n        # Act\n        iptc = IptcImagePlugin.getiptcinfo(im)\n\n        # Assert\n        self.assertIsNone(iptc)\n\n    def test_getiptcinfo_jpg_found(self):\n        # Arrange\n        im = Image.open(TEST_FILE)\n\n        # Act\n        iptc = IptcImagePlugin.getiptcinfo(im)\n\n        # Assert\n        self.assertIsInstance(iptc, dict)\n        self.assertEqual(iptc[(2, 90)], b\"Budapest\")\n        self.assertEqual(iptc[(2, 101)], b\"Hungary\")\n\n    # _FIXME: is_raw() is disabled. Should we remove it?\n    def test__is_raw_equal_zero(self):\n        # Arrange\n        im = self.dummy_IptcImagePlugin()\n        offset = 0\n        size = 4\n\n        # Act\n        ret = im._is_raw(offset, size)\n\n        # Assert\n        self.assertEqual(ret, 0)\n\n    def test_i(self):\n        # Arrange\n        c = b\"a\"\n\n        # Act\n        ret = IptcImagePlugin.i(c)\n\n        # Assert\n        self.assertEqual(ret, 97)\n\n\nif __name__ == '__main__':\n    unittest.main()\n\n# End of file\n",
            "header": {
                "file": {
                    "path": "Tests/test_file_iptc.py"
                },
                "misc_line": null
            },
            "index_line": {
                "old_commit_hash": "4ae85c66b",
                "new_commit_hash": "fd68e88b6",
                "mode": "100644"
            },
            "is_binary_file": false,
            "binary_line": null,
            "minus_file": {
                "path": "a/Tests/test_file_iptc.py"
            },
            "plus_file": {
                "path": "b/Tests/test_file_iptc.py"
            },
            "hunks": [
                {
                    "descriptor": {
                        "old_range": {
                            "start": 38,
                            "length": 8
                        },
                        "new_range": {
                            "start": 38,
                            "length": 8
                        },
                        "section": "class TestFileIptc(PillowTestCase):"
                    },
                    "line_group": {
                        "all_lines": [
                            {
                                "content": "",
                                "type": "context"
                            },
                            {
                                "content": "        # Assert",
                                "type": "context"
                            },
                            {
                                "content": "        self.assertIsInstance(iptc, dict)",
                                "type": "context"
                            },
                            {
                                "content": "        self.assertEqual(iptc[(2, 90)], \"Budapest\")",
                                "type": "deleted"
                            },
                            {
                                "content": "        self.assertEqual(iptc[(2, 101)], \"Hungary\")",
                                "type": "deleted"
                            },
                            {
                                "content": "        self.assertEqual(iptc[(2, 90)], b\"Budapest\")",
                                "type": "added"
                            },
                            {
                                "content": "        self.assertEqual(iptc[(2, 101)], b\"Hungary\")",
                                "type": "added"
                            },
                            {
                                "content": "",
                                "type": "context"
                            },
                            {
                                "content": "    # _FIXME: is_raw() is disabled. Should we remove it?",
                                "type": "context"
                            },
                            {
                                "content": "    def test__is_raw_equal_zero(self):",
                                "type": "context"
                            }
                        ]
                    },
                    "modified_entities": [
                        {
                            "file_name": "Tests/test_file_iptc.py",
                            "type": "class",
                            "name": "TestFileIptc",
                            "content": "class TestFileIptc(PillowTestCase):\n\n    # Helpers\n\n    def dummy_IptcImagePlugin(self):\n        # Create an IptcImagePlugin object without initializing it\n        class FakeImage:\n            pass\n        im = FakeImage()\n        im.__class__ = IptcImagePlugin.IptcImageFile\n        return im\n\n    # Tests\n\n    def test_getiptcinfo_jpg_none(self):\n        # Arrange\n        im = lena()\n\n        # Act\n        iptc = IptcImagePlugin.getiptcinfo(im)\n\n        # Assert\n        self.assertIsNone(iptc)\n\n    def test_getiptcinfo_jpg_found(self):\n        # Arrange\n        im = Image.open(TEST_FILE)\n\n        # Act\n        iptc = IptcImagePlugin.getiptcinfo(im)\n\n        # Assert\n        self.assertIsInstance(iptc, dict)\n        self.assertEqual(iptc[(2, 90)], \"Budapest\")\n        self.assertEqual(iptc[(2, 101)], \"Hungary\")\n\n    # _FIXME: is_raw() is disabled. Should we remove it?\n    def test__is_raw_equal_zero(self):\n        # Arrange\n        im = self.dummy_IptcImagePlugin()\n        offset = 0\n        size = 4\n\n        # Act\n        ret = im._is_raw(offset, size)\n\n        # Assert\n        self.assertEqual(ret, 0)\n\n    def test_i(self):\n        # Arrange\n        c = \"a\"\n\n        # Act\n        ret = IptcImagePlugin.i(c)\n\n        # Assert\n        self.assertEqual(ret, 97)",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 8,
                            "end_lineno": 65,
                            "parent": null
                        },
                        {
                            "file_name": "Tests/test_file_iptc.py",
                            "type": "method",
                            "name": "TestFileIptc.test_getiptcinfo_jpg_found",
                            "content": "class TestFileIptc(PillowTestCase):\n\n    # Helpers\n\n    def dummy_IptcImagePlugin(self):\n        # Create an IptcImagePlugin object without initializing it\n        class FakeImage:\n            pass\n        im = FakeImage()\n        im.__class__ = IptcImagePlugin.IptcImageFile\n        return im\n\n    # Tests\n\n    def test_getiptcinfo_jpg_none(self):\n        # Arrange\n        im = lena()\n\n        # Act\n        iptc = IptcImagePlugin.getiptcinfo(im)\n\n        # Assert\n        self.assertIsNone(iptc)\n\n    def test_getiptcinfo_jpg_found(self):\n        # Arrange\n        im = Image.open(TEST_FILE)\n\n        # Act\n        iptc = IptcImagePlugin.getiptcinfo(im)\n\n        # Assert\n        self.assertIsInstance(iptc, dict)\n        self.assertEqual(iptc[(2, 90)], \"Budapest\")\n        self.assertEqual(iptc[(2, 101)], \"Hungary\")\n\n    # _FIXME: is_raw() is disabled. Should we remove it?\n    def test__is_raw_equal_zero(self):\n        # Arrange\n        im = self.dummy_IptcImagePlugin()\n        offset = 0\n        size = 4\n\n        # Act\n        ret = im._is_raw(offset, size)\n\n        # Assert\n        self.assertEqual(ret, 0)\n\n    def test_i(self):\n        # Arrange\n        c = \"a\"\n\n        # Act\n        ret = IptcImagePlugin.i(c)\n\n        # Assert\n        self.assertEqual(ret, 97)",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 32,
                            "end_lineno": 42,
                            "parent": {
                                "file_name": "Tests/test_file_iptc.py",
                                "type": "class",
                                "name": "TestFileIptc",
                                "content": "class TestFileIptc(PillowTestCase):\n\n    # Helpers\n\n    def dummy_IptcImagePlugin(self):\n        # Create an IptcImagePlugin object without initializing it\n        class FakeImage:\n            pass\n        im = FakeImage()\n        im.__class__ = IptcImagePlugin.IptcImageFile\n        return im\n\n    # Tests\n\n    def test_getiptcinfo_jpg_none(self):\n        # Arrange\n        im = lena()\n\n        # Act\n        iptc = IptcImagePlugin.getiptcinfo(im)\n\n        # Assert\n        self.assertIsNone(iptc)\n\n    def test_getiptcinfo_jpg_found(self):\n        # Arrange\n        im = Image.open(TEST_FILE)\n\n        # Act\n        iptc = IptcImagePlugin.getiptcinfo(im)\n\n        # Assert\n        self.assertIsInstance(iptc, dict)\n        self.assertEqual(iptc[(2, 90)], \"Budapest\")\n        self.assertEqual(iptc[(2, 101)], \"Hungary\")\n\n    # _FIXME: is_raw() is disabled. Should we remove it?\n    def test__is_raw_equal_zero(self):\n        # Arrange\n        im = self.dummy_IptcImagePlugin()\n        offset = 0\n        size = 4\n\n        # Act\n        ret = im._is_raw(offset, size)\n\n        # Assert\n        self.assertEqual(ret, 0)\n\n    def test_i(self):\n        # Arrange\n        c = \"a\"\n\n        # Act\n        ret = IptcImagePlugin.i(c)\n\n        # Assert\n        self.assertEqual(ret, 97)",
                                "ast_type_str": "ClassDef",
                                "start_lineno": 8,
                                "end_lineno": 65,
                                "parent": null
                            }
                        }
                    ],
                    "added_entities": [],
                    "deleted_entities": []
                },
                {
                    "descriptor": {
                        "old_range": {
                            "start": 56,
                            "length": 7
                        },
                        "new_range": {
                            "start": 56,
                            "length": 7
                        },
                        "section": "class TestFileIptc(PillowTestCase):"
                    },
                    "line_group": {
                        "all_lines": [
                            {
                                "content": "",
                                "type": "context"
                            },
                            {
                                "content": "    def test_i(self):",
                                "type": "context"
                            },
                            {
                                "content": "        # Arrange",
                                "type": "context"
                            },
                            {
                                "content": "        c = \"a\"",
                                "type": "deleted"
                            },
                            {
                                "content": "        c = b\"a\"",
                                "type": "added"
                            },
                            {
                                "content": "",
                                "type": "context"
                            },
                            {
                                "content": "        # Act",
                                "type": "context"
                            },
                            {
                                "content": "        ret = IptcImagePlugin.i(c)",
                                "type": "context"
                            },
                            {
                                "content": "",
                                "type": "context"
                            }
                        ]
                    },
                    "modified_entities": [
                        {
                            "file_name": "Tests/test_file_iptc.py",
                            "type": "class",
                            "name": "TestFileIptc",
                            "content": "class TestFileIptc(PillowTestCase):\n\n    # Helpers\n\n    def dummy_IptcImagePlugin(self):\n        # Create an IptcImagePlugin object without initializing it\n        class FakeImage:\n            pass\n        im = FakeImage()\n        im.__class__ = IptcImagePlugin.IptcImageFile\n        return im\n\n    # Tests\n\n    def test_getiptcinfo_jpg_none(self):\n        # Arrange\n        im = lena()\n\n        # Act\n        iptc = IptcImagePlugin.getiptcinfo(im)\n\n        # Assert\n        self.assertIsNone(iptc)\n\n    def test_getiptcinfo_jpg_found(self):\n        # Arrange\n        im = Image.open(TEST_FILE)\n\n        # Act\n        iptc = IptcImagePlugin.getiptcinfo(im)\n\n        # Assert\n        self.assertIsInstance(iptc, dict)\n        self.assertEqual(iptc[(2, 90)], \"Budapest\")\n        self.assertEqual(iptc[(2, 101)], \"Hungary\")\n\n    # _FIXME: is_raw() is disabled. Should we remove it?\n    def test__is_raw_equal_zero(self):\n        # Arrange\n        im = self.dummy_IptcImagePlugin()\n        offset = 0\n        size = 4\n\n        # Act\n        ret = im._is_raw(offset, size)\n\n        # Assert\n        self.assertEqual(ret, 0)\n\n    def test_i(self):\n        # Arrange\n        c = \"a\"\n\n        # Act\n        ret = IptcImagePlugin.i(c)\n\n        # Assert\n        self.assertEqual(ret, 97)",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 8,
                            "end_lineno": 65,
                            "parent": null
                        },
                        {
                            "file_name": "Tests/test_file_iptc.py",
                            "type": "method",
                            "name": "TestFileIptc.test_i",
                            "content": "class TestFileIptc(PillowTestCase):\n\n    # Helpers\n\n    def dummy_IptcImagePlugin(self):\n        # Create an IptcImagePlugin object without initializing it\n        class FakeImage:\n            pass\n        im = FakeImage()\n        im.__class__ = IptcImagePlugin.IptcImageFile\n        return im\n\n    # Tests\n\n    def test_getiptcinfo_jpg_none(self):\n        # Arrange\n        im = lena()\n\n        # Act\n        iptc = IptcImagePlugin.getiptcinfo(im)\n\n        # Assert\n        self.assertIsNone(iptc)\n\n    def test_getiptcinfo_jpg_found(self):\n        # Arrange\n        im = Image.open(TEST_FILE)\n\n        # Act\n        iptc = IptcImagePlugin.getiptcinfo(im)\n\n        # Assert\n        self.assertIsInstance(iptc, dict)\n        self.assertEqual(iptc[(2, 90)], \"Budapest\")\n        self.assertEqual(iptc[(2, 101)], \"Hungary\")\n\n    # _FIXME: is_raw() is disabled. Should we remove it?\n    def test__is_raw_equal_zero(self):\n        # Arrange\n        im = self.dummy_IptcImagePlugin()\n        offset = 0\n        size = 4\n\n        # Act\n        ret = im._is_raw(offset, size)\n\n        # Assert\n        self.assertEqual(ret, 0)\n\n    def test_i(self):\n        # Arrange\n        c = \"a\"\n\n        # Act\n        ret = IptcImagePlugin.i(c)\n\n        # Assert\n        self.assertEqual(ret, 97)",
                            "ast_type_str": "ClassDef",
                            "start_lineno": 57,
                            "end_lineno": 65,
                            "parent": {
                                "file_name": "Tests/test_file_iptc.py",
                                "type": "class",
                                "name": "TestFileIptc",
                                "content": "class TestFileIptc(PillowTestCase):\n\n    # Helpers\n\n    def dummy_IptcImagePlugin(self):\n        # Create an IptcImagePlugin object without initializing it\n        class FakeImage:\n            pass\n        im = FakeImage()\n        im.__class__ = IptcImagePlugin.IptcImageFile\n        return im\n\n    # Tests\n\n    def test_getiptcinfo_jpg_none(self):\n        # Arrange\n        im = lena()\n\n        # Act\n        iptc = IptcImagePlugin.getiptcinfo(im)\n\n        # Assert\n        self.assertIsNone(iptc)\n\n    def test_getiptcinfo_jpg_found(self):\n        # Arrange\n        im = Image.open(TEST_FILE)\n\n        # Act\n        iptc = IptcImagePlugin.getiptcinfo(im)\n\n        # Assert\n        self.assertIsInstance(iptc, dict)\n        self.assertEqual(iptc[(2, 90)], \"Budapest\")\n        self.assertEqual(iptc[(2, 101)], \"Hungary\")\n\n    # _FIXME: is_raw() is disabled. Should we remove it?\n    def test__is_raw_equal_zero(self):\n        # Arrange\n        im = self.dummy_IptcImagePlugin()\n        offset = 0\n        size = 4\n\n        # Act\n        ret = im._is_raw(offset, size)\n\n        # Assert\n        self.assertEqual(ret, 0)\n\n    def test_i(self):\n        # Arrange\n        c = \"a\"\n\n        # Act\n        ret = IptcImagePlugin.i(c)\n\n        # Assert\n        self.assertEqual(ret, 97)",
                                "ast_type_str": "ClassDef",
                                "start_lineno": 8,
                                "end_lineno": 65,
                                "parent": null
                            }
                        }
                    ],
                    "added_entities": [],
                    "deleted_entities": []
                }
            ]
        }
    ],
    "old_commit_hash": "f5440cc3e1b0523b156a98ff311af61e003e95f9^",
    "new_commit_hash": "f5440cc3e1b0523b156a98ff311af61e003e95f9",
    "commit_message": "Fixes for Python 3",
    "commit_date": "2014-07-30T20:43:34+03:00",
    "metadata": {}
}
{
    "repo_name": "pillow",
    "new_commit_hash": "f5440cc3e1b0523b156a98ff311af61e003e95f9",
    "test_file_codes": [
        "from helper import unittest, PillowTestCase, lena\n\nfrom PIL import Image, IptcImagePlugin\n\nTEST_FILE = \"Tests/images/iptc.jpg\"\n\n\nclass TestFileIptc(PillowTestCase):\n\n    # Helpers\n\n    def dummy_IptcImagePlugin(self):\n        # Create an IptcImagePlugin object without initializing it\n        class FakeImage:\n            pass\n        im = FakeImage()\n        im.__class__ = IptcImagePlugin.IptcImageFile\n        return im\n\n    # Tests\n\n    def test_getiptcinfo_jpg_none(self):\n        # Arrange\n        im = lena()\n\n        # Act\n        iptc = IptcImagePlugin.getiptcinfo(im)\n\n        # Assert\n        self.assertIsNone(iptc)\n\n    def test_getiptcinfo_jpg_found(self):\n        # Arrange\n        im = Image.open(TEST_FILE)\n\n        # Act\n        iptc = IptcImagePlugin.getiptcinfo(im)\n\n        # Assert\n        self.assertIsInstance(iptc, dict)\n        self.assertEqual(iptc[(2, 90)], b\"Budapest\")\n        self.assertEqual(iptc[(2, 101)], b\"Hungary\")\n\n    # _FIXME: is_raw() is disabled. Should we remove it?\n    def test__is_raw_equal_zero(self):\n        # Arrange\n        im = self.dummy_IptcImagePlugin()\n        offset = 0\n        size = 4\n\n        # Act\n        ret = im._is_raw(offset, size)\n\n        # Assert\n        self.assertEqual(ret, 0)\n\n    def test_i(self):\n        # Arrange\n        c = b\"a\"\n\n        # Act\n        ret = IptcImagePlugin.i(c)\n\n        # Assert\n        self.assertEqual(ret, 97)\n\n\nif __name__ == '__main__':\n    unittest.main()\n\n# End of file\n",
        "#!/usr/bin/env python\nimport unittest\nimport sys\nimport time\nimport traceback\nimport platform\nimport os\n\n\nclass PytestLikeResult(unittest.TestResult):\n    def __init__(self, *args, **kwargs):\n        super().__init__(*args, **kwargs)\n        self.start_time = None\n        # Store (test, outcome, info) for each test:\n        #   outcome ∈ { \"passed\", \"failed\", \"error\", \"skipped\" }\n        #   info can hold the exception or skip reason, etc.\n        self.results = []\n\n    def startTestRun(self):\n        \"\"\"Called once before all tests.\"\"\"\n        self.start_time = time.time()\n        # Print a header similar to pytest\n        print(\"=\" * 29 + \" test session starts \" + \"=\" * 29)\n        # You can customize the platform/versions/paths as you like:\n        print(\n            f\"platform {platform.system().lower()} -- Python {platform.python_version()}\"\n        )\n        print(f\"rootdir: {os.path.abspath(os.curdir)}\")\n\n    def stopTestRun(self):\n        \"\"\"Called once after all tests are done.\"\"\"\n        elapsed = time.time() - self.start_time\n        print()  # blank line after final dot\n\n        # Summarize\n        ntests = len(self.results)\n        print(f\"collected {ntests} items\")\n\n        # Show details of failures/errors\n        failures = [r for r in self.results if r[1] == \"failed\"]\n        errors = [r for r in self.results if r[1] == \"error\"]\n\n        if failures:\n            print(\"\\n\" + \"=\" * 35 + \" FAILURES \" + \"=\" * 35)\n            for test, outcome, err_info in failures:\n                test = test.split(\"::\")\n                if len(test) == 3:\n                    test = f\"{test[1]}.{test[2]}\"\n                else:\n                    test = f\"{test[1]}\"\n                print(f\"__________ {test} __________\")\n                self._print_traceback(err_info)\n        if errors:\n            print(\"\\n\" + \"=\" * 35 + \" ERRORS \" + \"=\" * 37)\n            for test, outcome, err_info in errors:\n                test = test.split(\"::\")\n                if len(test) == 3:\n                    test = f\"{test[1]}.{test[2]}\"\n                else:\n                    test = f\"{test[1]}\"\n                print(f\"__________ {test} __________\")\n                self._print_traceback(err_info)\n\n        # Optional short summary lines for passes/fails/skips\n        print(\"\\n==================== short test summary info ====================\")\n        for test, outcome, info in self.results:\n            if outcome in (\"passed\", \"failed\", \"error\", \"skipped\"):\n                print(f\"{outcome.upper()} {test}\")\n\n        # Final one-line summary: “1 failed, 1 errors, 10 passed in 2.04s”\n        passed_count = sum(1 for r in self.results if r[1] == \"passed\")\n        failed_count = len(failures)\n        error_count = len(errors)\n        skipped_count = sum(1 for r in self.results if r[1] == \"skipped\")\n\n        summary_bits = []\n        if failed_count:\n            summary_bits.append(f\"{failed_count} failed\")\n        if error_count:\n            summary_bits.append(f\"{error_count} error{'s' if error_count != 1 else ''}\")\n        if passed_count:\n            summary_bits.append(f\"{passed_count} passed\")\n        if skipped_count:\n            summary_bits.append(f\"{skipped_count} skipped\")\n\n        summary_str = \", \".join(summary_bits) if summary_bits else \"no tests run\"\n        print(\n            f\"=================== {summary_str} in {elapsed:.2f}s ===================\"\n        )\n\n    def startTest(self, test):\n        \"\"\"Called right before each test method.\"\"\"\n        super().startTest(test)\n        # Print a dot or some indicator\n        print(\".\", end=\"\", flush=True)\n\n    def addSuccess(self, test):\n        super().addSuccess(test)\n        self.results.append((self._test_id(test), \"passed\", None))\n\n    def addFailure(self, test, err):\n        super().addFailure(test, err)\n        self.results.append((self._test_id(test), \"failed\", err))\n\n    def addError(self, test, err):\n        super().addError(test, err)\n        self.results.append((self._test_id(test), \"error\", err))\n\n    def addSkip(self, test, reason):\n        super().addSkip(test, reason)\n        self.results.append((self._test_id(test), \"skipped\", reason))\n\n    def _print_traceback(self, err_info):\n        \"\"\"Helper to print the traceback like pytest does.\"\"\"\n        if isinstance(err_info, tuple) and len(err_info) == 3:\n            exc_type, exc_value, tb = err_info\n            traceback.print_exception(exc_type, exc_value, tb, file=sys.stdout)\n        else:\n            print(str(err_info))\n\n    def _test_id(self, test):\n        try:\n            return f\"{test.__class__.__module__}::{test.__class__.__name__}::{test._testMethodName}\"\n        except AttributeError:\n            # Fallback for _ErrorHolder objects\n            return f\"{test.__class__.__module__}::{test.__class__.__name__}\"\n\n\nclass PytestLikeRunner(unittest.TextTestRunner):\n    \"\"\"A custom TextTestRunner that uses the PytestLikeResult.\"\"\"\n\n    resultclass = PytestLikeResult\n\n    def run(self, test):\n        result = self._makeResult()\n        # Overriding run to ensure we call startTestRun/stopTestRun\n        result.startTestRun()\n        test(result)\n        result.stopTestRun()\n        return result\n\n\ndef main():\n    loader = unittest.TestLoader()\n    suite = loader.discover(\"r2e_tests\")  # discover tests in r2e_tests/\n    runner = PytestLikeRunner(verbosity=0)\n    result = runner.run(suite)\n    # Exit with code 0 if all tests passed/skipped, 1 if there were fails/errors\n    sys.exit(not result.wasSuccessful())\n\n\nif __name__ == \"__main__\":\n    main()\n"
    ],
    "test_file_names": [
        "test_1.py",
        "unittest_custom_runner.py"
    ],
    "setup_res_code": 0,
    "setup_res_stdout": "Starting Pillow installation attempts...\nVerifying Pillow installation...\n✅ Pillow installation successful!\nSuccessfully installed Pillow\n",
    "setup_res_stderr": "Using CPython 3.9.21\nCreating virtual environment at: .venv\nActivate with: source .venv/bin/activate\nResolved 12 packages in 15ms\nInstalled 12 packages in 124ms\n + coverage==7.6.10\n + exceptiongroup==1.2.2\n + iniconfig==2.0.0\n + packaging==24.2\n + pluggy==1.5.0\n + pyqt5==5.15.11\n + pyqt5-qt5==5.15.16\n + pyqt5-sip==12.16.1\n + pytest==8.3.4\n + pytest-cov==6.0.0\n + setuptools==75.8.0\n + tomli==2.2.1\nResolved 1 package in 1.33s\nPrepared 1 package in 11.42s\nInstalled 1 package in 2ms\n + pillow==2.5.0 (from file:///home/gcpuser/buckets/local_repoeval_bucket/repos/pillow_f5440cc3e1b0523b156a98ff311af61e003e95f9)\n",
    "new_commit_res_code": 0,
    "new_commit_res_stdout": "============================= test session starts =============================\nplatform linux -- Python 3.9.21\nrootdir: /home/gcpuser/buckets/local_repoeval_bucket/repos/pillow_f5440cc3e1b0523b156a98ff311af61e003e95f9\n....\ncollected 4 items\n\n==================== short test summary info ====================\nPASSED test_1::TestFileIptc::test__is_raw_equal_zero\nPASSED test_1::TestFileIptc::test_getiptcinfo_jpg_found\nPASSED test_1::TestFileIptc::test_getiptcinfo_jpg_none\nPASSED test_1::TestFileIptc::test_i\n=================== 4 passed in 0.05s ===================\n",
    "new_commit_res_stderr": "",
    "old_commit_res_code": 1,
    "old_commit_res_stdout": "============================= test session starts =============================\nplatform linux -- Python 3.9.21\nrootdir: /home/gcpuser/buckets/local_repoeval_bucket/repos/pillow_f5440cc3e1b0523b156a98ff311af61e003e95f9\n....\ncollected 4 items\n\n=================================== FAILURES ===================================\n__________ TestFileIptc.test_getiptcinfo_jpg_found __________\nTraceback (most recent call last):\n  File \"/home/gcpuser/.local/share/uv/python/cpython-3.9.21-linux-x86_64-gnu/lib/python3.9/unittest/case.py\", line 59, in testPartExecutor\n    yield\n  File \"/home/gcpuser/.local/share/uv/python/cpython-3.9.21-linux-x86_64-gnu/lib/python3.9/unittest/case.py\", line 592, in run\n    self._callTestMethod(testMethod)\n  File \"/home/gcpuser/.local/share/uv/python/cpython-3.9.21-linux-x86_64-gnu/lib/python3.9/unittest/case.py\", line 550, in _callTestMethod\n    method()\n  File \"/home/gcpuser/buckets/local_repoeval_bucket/repos/pillow_f5440cc3e1b0523b156a98ff311af61e003e95f9/r2e_tests/test_1.py\", line 40, in test_getiptcinfo_jpg_found\n    self.assertIsInstance(iptc, dict)\nAssertionError: None is not an instance of <class 'dict'>\n\n==================== short test summary info ====================\nPASSED test_1::TestFileIptc::test__is_raw_equal_zero\nFAILED test_1::TestFileIptc::test_getiptcinfo_jpg_found\nPASSED test_1::TestFileIptc::test_getiptcinfo_jpg_none\nPASSED test_1::TestFileIptc::test_i\n=================== 1 failed, 3 passed in 0.01s ===================\n",
    "old_commit_res_stderr": ""
}
PIL/IptcImagePlugin.py Tests/test_file_iptc.py
We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[ISSUE]
**Title:** IPTC Information Not Parsed Correctly in Python 3, Returning None Instead of Dictionary

**Description:**
When processing JPEG images with IPTC metadata using Python 3, the IPTC information fails to parse correctly. Instead of returning a dictionary containing the IPTC tags, the function returns `None`. This prevents access to essential metadata like location information.

**Example Code:**
```python
from PIL import Image, IptcImagePlugin

im = Image.open(TEST_FILE)
iptc = IptcImagePlugin.getiptcinfo(im)
print(iptc)  # Expected: Dictionary with IPTC tags, Actual: None
```

**Expected Behavior:**
The `getiptcinfo` function should parse the IPTC data and return it as a dictionary with byte string values for each tag, such as:
```python
{
    (2, 90): b'Budapest',
    (2, 101): b'Hungary'
}
```

**Actual Behavior:**
The `getiptcinfo` function returns `None` instead of a dictionary, leading to failures when attempting to access IPTC tags.

[/ISSUE]
--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.

--- BEGIN FILE ---
```
### PIL/IptcImagePlugin.py
#
# The Python Imaging Library.
# $Id$
#
# IPTC/NAA file handling
#
# history:
# 1995-10-01 fl   Created
# 1998-03-09 fl   Cleaned up and added to PIL
# 2002-06-18 fl   Added getiptcinfo helper
#
# Copyright (c) Secret Labs AB 1997-2002.
# Copyright (c) Fredrik Lundh 1995.
#
# See the README file for information on usage and redistribution.
#

from __future__ import print_function

__version__ = "0.3"


from PIL import Image, ImageFile, _binary
import os
import tempfile

i8 = _binary.i8
i16 = _binary.i16be
i32 = _binary.i32be
o8 = _binary.o8

COMPRESSION = {
    1: "raw",
    5: "jpeg"
}

PAD = o8(0) * 4


#
# Helpers

def i(c):
    return i32((PAD + c)[-4:])


def dump(c):
    for i in c:
        print("%02x" % i8(i), end=' ')
    print()


##
# Image plugin for IPTC/NAA datastreams.  To read IPTC/NAA fields
# from TIFF and JPEG files, use the <b>getiptcinfo</b> function.

class IptcImageFile(ImageFile.ImageFile):

    format = "IPTC"
    format_description = "IPTC/NAA"

    def getint(self, key):
        return i(self.info[key])

    def field(self):
        #
        # get a IPTC field header
        s = self.fp.read(5)
        if not len(s):
            return None, 0

        tag = i8(s[1]), i8(s[2])

        # syntax
        if i8(s[0]) != 0x1C or tag[0] < 1 or tag[0] > 9:
            raise SyntaxError("invalid IPTC/NAA file")

        # field size
        size = i8(s[3])
        if size > 132:
            raise IOError("illegal field length in IPTC/NAA file")
        elif size == 128:
            size = 0
        elif size > 128:
            size = i(self.fp.read(size-128))
        else:
            size = i16(s[3:])

        return tag, size

    def _is_raw(self, offset, size):
        #
        # check if the file can be mapped

        # DISABLED: the following only slows things down...
        return 0

        self.fp.seek(offset)
        t, sz = self.field()
        if sz != size[0]:
            return 0
        y = 1
        while True:
            self.fp.seek(sz, 1)
            t, s = self.field()
            if t != (8, 10):
                break
            if s != sz:
                return 0
            y += 1
        return y == size[1]

    def _open(self):

        # load descriptive fields
        while True:
            offset = self.fp.tell()
            tag, size = self.field()
            if not tag or tag == (8, 10):
                break
            if size:
                tagdata = self.fp.read(size)
            else:
                tagdata = None
            if tag in list(self.info.keys()):
                if isinstance(self.info[tag], list):
                    self.info[tag].append(tagdata)
                else:
                    self.info[tag] = [self.info[tag], tagdata]
            else:
                self.info[tag] = tagdata

            # print tag, self.info[tag]

        # mode
        layers = i8(self.info[(3, 60)][0])
        component = i8(self.info[(3, 60)][1])
        if (3, 65) in self.info:
            id = i8(self.info[(3, 65)][0])-1
        else:
            id = 0
        if layers == 1 and not component:
            self.mode = "L"
        elif layers == 3 and component:
            self.mode = "RGB"[id]
        elif layers == 4 and component:
            self.mode = "CMYK"[id]

        # size
        self.size = self.getint((3, 20)), self.getint((3, 30))

        # compression
        try:
            compression = COMPRESSION[self.getint((3, 120))]
        except KeyError:
            raise IOError("Unknown IPTC image compression")

        # tile
        if tag == (8, 10):
            if compression == "raw" and self._is_raw(offset, self.size):
                self.tile = [(compression, (offset, size + 5, -1),
                             (0, 0, self.size[0], self.size[1]))]
            else:
                self.tile = [("iptc", (compression, offset),
                             (0, 0, self.size[0], self.size[1]))]

    def load(self):

        if len(self.tile) != 1 or self.tile[0][0] != "iptc":
            return ImageFile.ImageFile.load(self)

        type, tile, box = self.tile[0]

        encoding, offset = tile

        self.fp.seek(offset)

        # Copy image data to temporary file
        o_fd, outfile = tempfile.mkstemp(text=False)
        o = os.fdopen(o_fd)
        if encoding == "raw":
            # To simplify access to the extracted file,
            # prepend a PPM header
            o.write("P5\n%d %d\n255\n" % self.size)
        while True:
            type, size = self.field()
            if type != (8, 10):
                break
            while size > 0:
                s = self.fp.read(min(size, 8192))
                if not s:
                    break
                o.write(s)
                size -= len(s)
        o.close()

        try:
            try:
                # fast
                self.im = Image.core.open_ppm(outfile)
            except:
                # slightly slower
                im = Image.open(outfile)
                im.load()
                self.im = im.im
        finally:
            try:
                os.unlink(outfile)
            except:
                pass


Image.register_open("IPTC", IptcImageFile)

Image.register_extension("IPTC", ".iim")


##
# Get IPTC information from TIFF, JPEG, or IPTC file.
#
# @param im An image containing IPTC data.
# @return A dictionary containing IPTC information, or None if
#     no IPTC information block was found.

def getiptcinfo(im):

    from PIL import TiffImagePlugin, JpegImagePlugin
    import io

    data = None

    if isinstance(im, IptcImageFile):
        # return info dictionary right away
        return im.info

    elif isinstance(im, JpegImagePlugin.JpegImageFile):
        # extract the IPTC/NAA resource
        try:
            app = im.app["APP13"]
            if app[:14] == "Photoshop 3.0\x00":
                app = app[14:]
                # parse the image resource block
                offset = 0
                while app[offset:offset+4] == "8BIM":
                    offset += 4
                    # resource code
                    code = JpegImagePlugin.i16(app, offset)
                    offset += 2
                    # resource name (usually empty)
                    name_len = i8(app[offset])
                    name = app[offset+1:offset+1+name_len]
                    offset = 1 + offset + name_len
                    if offset & 1:
                        offset += 1
                    # resource data block
                    size = JpegImagePlugin.i32(app, offset)
                    offset += 4
                    if code == 0x0404:
                        # 0x0404 contains IPTC/NAA data
                        data = app[offset:offset+size]
                        break
                    offset = offset + size
                    if offset & 1:
                        offset += 1
        except (AttributeError, KeyError):
            pass

    elif isinstance(im, TiffImagePlugin.TiffImageFile):
        # get raw data from the IPTC/NAA tag (PhotoShop tags the data
        # as 4-byte integers, so we cannot use the get method...)
        try:
            data = im.tag.tagdata[TiffImagePlugin.IPTC_NAA_CHUNK]
        except (AttributeError, KeyError):
            pass

    if data is None:
        return None  # no properties

    # create an IptcImagePlugin object without initializing it
    class FakeImage:
        pass
    im = FakeImage()
    im.__class__ = IptcImageFile

    # parse the IPTC information chunk
    im.info = {}
    im.fp = io.BytesIO(data)

    try:
        im._open()
    except (IndexError, KeyError):
        pass  # expected failure

    return im.info

```
--- END FILE ---

Please first localize the bug based on the issue statement, and then generate *SEARCH/REPLACE* edits to fix the issue.

Every *SEARCH/REPLACE* edit must use this format:
1. The file path
2. The start of search block: <<<<<<< SEARCH
3. A contiguous chunk of lines to search for in the existing source code
4. The dividing line: =======
5. The lines to replace into the source code
6. The end of the replace block: >>>>>>> REPLACE

Here is an example:

```python
### mathweb/flask/app.py
<<<<<<< SEARCH
from flask import Flask
=======
import math
from flask import Flask
>>>>>>> REPLACE
```
</solution>

Please note that the *SEARCH/REPLACE* edit REQUIRES PROPER INDENTATION. If you would like to add the line '        print(x)', you must fully write that out, with all those spaces before the code!
Wrap each *SEARCH/REPLACE* edit in a code block as shown in the example above. If you have multiple *SEARCH/REPLACE* edits, use a separate code block for each one.
[ISSUE]
**Title:** IPTC Information Not Parsed Correctly in Python 3, Returning None Instead of Dictionary

**Description:**
When processing JPEG images with IPTC metadata using Python 3, the IPTC information fails to parse correctly. Instead of returning a dictionary containing the IPTC tags, the function returns `None`. This prevents access to essential metadata like location information.

**Example Code:**
```python
from PIL import Image, IptcImagePlugin

im = Image.open(TEST_FILE)
iptc = IptcImagePlugin.getiptcinfo(im)
print(iptc)  # Expected: Dictionary with IPTC tags, Actual: None
```

**Expected Behavior:**
The `getiptcinfo` function should parse the IPTC data and return it as a dictionary with byte string values for each tag, such as:
```python
{
    (2, 90): b'Budapest',
    (2, 101): b'Hungary'
}
```

**Actual Behavior:**
The `getiptcinfo` function returns `None` instead of a dictionary, leading to failures when attempting to access IPTC tags.

[/ISSUE]
{
    "TestFileIptc.test__is_raw_equal_zero": "PASSED",
    "TestFileIptc.test_getiptcinfo_jpg_found": "PASSED",
    "TestFileIptc.test_getiptcinfo_jpg_none": "PASSED",
    "TestFileIptc.test_i": "PASSED"
}
diff --git a/PIL/IptcImagePlugin.py b/PIL/IptcImagePlugin.py
index 955afbbeb..a94fc7524 100644
--- a/PIL/IptcImagePlugin.py
+++ b/PIL/IptcImagePlugin.py
@@ -237,11 +237,11 @@ def getiptcinfo(im):
         # extract the IPTC/NAA resource
         try:
             app = im.app["APP13"]
-            if app[:14] == "Photoshop 3.0\x00":
+            if app[:14] == b"Photoshop 3.0\x00":
                 app = app[14:]
                 # parse the image resource block
                 offset = 0
-                while app[offset:offset+4] == "8BIM":
+                while app[offset:offset+4] == b"8BIM":
                     offset += 4
                     # resource code
                     code = JpegImagePlugin.i16(app, offset)

{"PIL/IptcImagePlugin.py": "#\n# The Python Imaging Library.\n# $Id$\n#\n# IPTC/NAA file handling\n#\n# history:\n# 1995-10-01 fl   Created\n# 1998-03-09 fl   Cleaned up and added to PIL\n# 2002-06-18 fl   Added getiptcinfo helper\n#\n# Copyright (c) Secret Labs AB 1997-2002.\n# Copyright (c) Fredrik Lundh 1995.\n#\n# See the README file for information on usage and redistribution.\n#\n\nfrom __future__ import print_function\n\n__version__ = \"0.3\"\n\n\nfrom PIL import Image, ImageFile, _binary\nimport os\nimport tempfile\n\ni8 = _binary.i8\ni16 = _binary.i16be\ni32 = _binary.i32be\no8 = _binary.o8\n\nCOMPRESSION = {\n    1: \"raw\",\n    5: \"jpeg\"\n}\n\nPAD = o8(0) * 4\n\n\n#\n# Helpers\n\ndef i(c):\n    return i32((PAD + c)[-4:])\n\n\ndef dump(c):\n    for i in c:\n        print(\"%02x\" % i8(i), end=' ')\n    print()\n\n\n##\n# Image plugin for IPTC/NAA datastreams.  To read IPTC/NAA fields\n# from TIFF and JPEG files, use the <b>getiptcinfo</b> function.\n\nclass IptcImageFile(ImageFile.ImageFile):\n\n    format = \"IPTC\"\n    format_description = \"IPTC/NAA\"\n\n    def getint(self, key):\n        return i(self.info[key])\n\n    def field(self):\n        #\n        # get a IPTC field header\n        s = self.fp.read(5)\n        if not len(s):\n            return None, 0\n\n        tag = i8(s[1]), i8(s[2])\n\n        # syntax\n        if i8(s[0]) != 0x1C or tag[0] < 1 or tag[0] > 9:\n            raise SyntaxError(\"invalid IPTC/NAA file\")\n\n        # field size\n        size = i8(s[3])\n        if size > 132:\n            raise IOError(\"illegal field length in IPTC/NAA file\")\n        elif size == 128:\n            size = 0\n        elif size > 128:\n            size = i(self.fp.read(size-128))\n        else:\n            size = i16(s[3:])\n\n        return tag, size\n\n    def _is_raw(self, offset, size):\n        #\n        # check if the file can be mapped\n\n        # DISABLED: the following only slows things down...\n        return 0\n\n        self.fp.seek(offset)\n        t, sz = self.field()\n        if sz != size[0]:\n            return 0\n        y = 1\n        while True:\n            self.fp.seek(sz, 1)\n            t, s = self.field()\n            if t != (8, 10):\n                break\n            if s != sz:\n                return 0\n            y += 1\n        return y == size[1]\n\n    def _open(self):\n\n        # load descriptive fields\n        while True:\n            offset = self.fp.tell()\n            tag, size = self.field()\n            if not tag or tag == (8, 10):\n                break\n            if size:\n                tagdata = self.fp.read(size)\n            else:\n                tagdata = None\n            if tag in list(self.info.keys()):\n                if isinstance(self.info[tag], list):\n                    self.info[tag].append(tagdata)\n                else:\n                    self.info[tag] = [self.info[tag], tagdata]\n            else:\n                self.info[tag] = tagdata\n\n            # print tag, self.info[tag]\n\n        # mode\n        layers = i8(self.info[(3, 60)][0])\n        component = i8(self.info[(3, 60)][1])\n        if (3, 65) in self.info:\n            id = i8(self.info[(3, 65)][0])-1\n        else:\n            id = 0\n        if layers == 1 and not component:\n            self.mode = \"L\"\n        elif layers == 3 and component:\n            self.mode = \"RGB\"[id]\n        elif layers == 4 and component:\n            self.mode = \"CMYK\"[id]\n\n        # size\n        self.size = self.getint((3, 20)), self.getint((3, 30))\n\n        # compression\n        try:\n            compression = COMPRESSION[self.getint((3, 120))]\n        except KeyError:\n            raise IOError(\"Unknown IPTC image compression\")\n\n        # tile\n        if tag == (8, 10):\n            if compression == \"raw\" and self._is_raw(offset, self.size):\n                self.tile = [(compression, (offset, size + 5, -1),\n                             (0, 0, self.size[0], self.size[1]))]\n            else:\n                self.tile = [(\"iptc\", (compression, offset),\n                             (0, 0, self.size[0], self.size[1]))]\n\n    def load(self):\n\n        if len(self.tile) != 1 or self.tile[0][0] != \"iptc\":\n            return ImageFile.ImageFile.load(self)\n\n        type, tile, box = self.tile[0]\n\n        encoding, offset = tile\n\n        self.fp.seek(offset)\n\n        # Copy image data to temporary file\n        o_fd, outfile = tempfile.mkstemp(text=False)\n        o = os.fdopen(o_fd)\n        if encoding == \"raw\":\n            # To simplify access to the extracted file,\n            # prepend a PPM header\n            o.write(\"P5\\n%d %d\\n255\\n\" % self.size)\n        while True:\n            type, size = self.field()\n            if type != (8, 10):\n                break\n            while size > 0:\n                s = self.fp.read(min(size, 8192))\n                if not s:\n                    break\n                o.write(s)\n                size -= len(s)\n        o.close()\n\n        try:\n            try:\n                # fast\n                self.im = Image.core.open_ppm(outfile)\n            except:\n                # slightly slower\n                im = Image.open(outfile)\n                im.load()\n                self.im = im.im\n        finally:\n            try:\n                os.unlink(outfile)\n            except:\n                pass\n\n\nImage.register_open(\"IPTC\", IptcImageFile)\n\nImage.register_extension(\"IPTC\", \".iim\")\n\n\n##\n# Get IPTC information from TIFF, JPEG, or IPTC file.\n#\n# @param im An image containing IPTC data.\n# @return A dictionary containing IPTC information, or None if\n#     no IPTC information block was found.\n\ndef getiptcinfo(im):\n\n    from PIL import TiffImagePlugin, JpegImagePlugin\n    import io\n\n    data = None\n\n    if isinstance(im, IptcImageFile):\n        # return info dictionary right away\n        return im.info\n\n    elif isinstance(im, JpegImagePlugin.JpegImageFile):\n        # extract the IPTC/NAA resource\n        try:\n            app = im.app[\"APP13\"]\n            if app[:14] == \"Photoshop 3.0\\x00\":\n                app = app[14:]\n                # parse the image resource block\n                offset = 0\n                while app[offset:offset+4] == \"8BIM\":\n                    offset += 4\n                    # resource code\n                    code = JpegImagePlugin.i16(app, offset)\n                    offset += 2\n                    # resource name (usually empty)\n                    name_len = i8(app[offset])\n                    name = app[offset+1:offset+1+name_len]\n                    offset = 1 + offset + name_len\n                    if offset & 1:\n                        offset += 1\n                    # resource data block\n                    size = JpegImagePlugin.i32(app, offset)\n                    offset += 4\n                    if code == 0x0404:\n                        # 0x0404 contains IPTC/NAA data\n                        data = app[offset:offset+size]\n                        break\n                    offset = offset + size\n                    if offset & 1:\n                        offset += 1\n        except (AttributeError, KeyError):\n            pass\n\n    elif isinstance(im, TiffImagePlugin.TiffImageFile):\n        # get raw data from the IPTC/NAA tag (PhotoShop tags the data\n        # as 4-byte integers, so we cannot use the get method...)\n        try:\n            data = im.tag.tagdata[TiffImagePlugin.IPTC_NAA_CHUNK]\n        except (AttributeError, KeyError):\n            pass\n\n    if data is None:\n        return None  # no properties\n\n    # create an IptcImagePlugin object without initializing it\n    class FakeImage:\n        pass\n    im = FakeImage()\n    im.__class__ = IptcImageFile\n\n    # parse the IPTC information chunk\n    im.info = {}\n    im.fp = io.BytesIO(data)\n\n    try:\n        im._open()\n    except (IndexError, KeyError):\n        pass  # expected failure\n\n    return im.info\n"}
A user will ask you to solve a task. You should first draft your thinking process (inner monologue). Then, generate the solution.

Your response format must follow the template below:
<think>
Your thoughts or/and draft, like working through an exercise on scratch paper. Be as casual and as long as you want until you are confident to generate a correct solution.
</think>
<solution>
Final solution presented to the user.
</solution>
system
We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[ISSUE]
**Title:** IPTC Information Not Parsed Correctly in Python 3, Returning None Instead of Dictionary

**Description:**
When processing JPEG images with IPTC metadata using Python 3, the IPTC information fails to parse correctly. Instead of returning a dictionary containing the IPTC tags, the function returns `None`. This prevents access to essential metadata like location information.

**Example Code:**
```python
from PIL import Image, IptcImagePlugin

im = Image.open(TEST_FILE)
iptc = IptcImagePlugin.getiptcinfo(im)
print(iptc)  # Expected: Dictionary with IPTC tags, Actual: None
```

**Expected Behavior:**
The `getiptcinfo` function should parse the IPTC data and return it as a dictionary with byte string values for each tag, such as:
```python
{
    (2, 90): b'Budapest',
    (2, 101): b'Hungary'
}
```

**Actual Behavior:**
The `getiptcinfo` function returns `None` instead of a dictionary, leading to failures when attempting to access IPTC tags.

[/ISSUE]
--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.

--- BEGIN FILE ---
```
### PIL/IptcImagePlugin.py
#
# The Python Imaging Library.
# $Id$
#
# IPTC/NAA file handling
#
# history:
# 1995-10-01 fl   Created
# 1998-03-09 fl   Cleaned up and added to PIL
# 2002-06-18 fl   Added getiptcinfo helper
#
# Copyright (c) Secret Labs AB 1997-2002.
# Copyright (c) Fredrik Lundh 1995.
#
# See the README file for information on usage and redistribution.
#

from __future__ import print_function

__version__ = "0.3"


from PIL import Image, ImageFile, _binary
import os
import tempfile

i8 = _binary.i8
i16 = _binary.i16be
i32 = _binary.i32be
o8 = _binary.o8

COMPRESSION = {
    1: "raw",
    5: "jpeg"
}

PAD = o8(0) * 4


#
# Helpers

def i(c):
    return i32((PAD + c)[-4:])


def dump(c):
    for i in c:
        print("%02x" % i8(i), end=' ')
    print()


##
# Image plugin for IPTC/NAA datastreams.  To read IPTC/NAA fields
# from TIFF and JPEG files, use the <b>getiptcinfo</b> function.

class IptcImageFile(ImageFile.ImageFile):

    format = "IPTC"
    format_description = "IPTC/NAA"

    def getint(self, key):
        return i(self.info[key])

    def field(self):
        #
        # get a IPTC field header
        s = self.fp.read(5)
        if not len(s):
            return None, 0

        tag = i8(s[1]), i8(s[2])

        # syntax
        if i8(s[0]) != 0x1C or tag[0] < 1 or tag[0] > 9:
            raise SyntaxError("invalid IPTC/NAA file")

        # field size
        size = i8(s[3])
        if size > 132:
            raise IOError("illegal field length in IPTC/NAA file")
        elif size == 128:
            size = 0
        elif size > 128:
            size = i(self.fp.read(size-128))
        else:
            size = i16(s[3:])

        return tag, size

    def _is_raw(self, offset, size):
        #
        # check if the file can be mapped

        # DISABLED: the following only slows things down...
        return 0

        self.fp.seek(offset)
        t, sz = self.field()
        if sz != size[0]:
            return 0
        y = 1
        while True:
            self.fp.seek(sz, 1)
            t, s = self.field()
            if t != (8, 10):
                break
            if s != sz:
                return 0
            y += 1
        return y == size[1]

    def _open(self):

        # load descriptive fields
        while True:
            offset = self.fp.tell()
            tag, size = self.field()
            if not tag or tag == (8, 10):
                break
            if size:
                tagdata = self.fp.read(size)
            else:
                tagdata = None
            if tag in list(self.info.keys()):
                if isinstance(self.info[tag], list):
                    self.info[tag].append(tagdata)
                else:
                    self.info[tag] = [self.info[tag], tagdata]
            else:
                self.info[tag] = tagdata

            # print tag, self.info[tag]

        # mode
        layers = i8(self.info[(3, 60)][0])
        component = i8(self.info[(3, 60)][1])
        if (3, 65) in self.info:
            id = i8(self.info[(3, 65)][0])-1
        else:
            id = 0
        if layers == 1 and not component:
            self.mode = "L"
        elif layers == 3 and component:
            self.mode = "RGB"[id]
        elif layers == 4 and component:
            self.mode = "CMYK"[id]

        # size
        self.size = self.getint((3, 20)), self.getint((3, 30))

        # compression
        try:
            compression = COMPRESSION[self.getint((3, 120))]
        except KeyError:
            raise IOError("Unknown IPTC image compression")

        # tile
        if tag == (8, 10):
            if compression == "raw" and self._is_raw(offset, self.size):
                self.tile = [(compression, (offset, size + 5, -1),
                             (0, 0, self.size[0], self.size[1]))]
            else:
                self.tile = [("iptc", (compression, offset),
                             (0, 0, self.size[0], self.size[1]))]

    def load(self):

        if len(self.tile) != 1 or self.tile[0][0] != "iptc":
            return ImageFile.ImageFile.load(self)

        type, tile, box = self.tile[0]

        encoding, offset = tile

        self.fp.seek(offset)

        # Copy image data to temporary file
        o_fd, outfile = tempfile.mkstemp(text=False)
        o = os.fdopen(o_fd)
        if encoding == "raw":
            # To simplify access to the extracted file,
            # prepend a PPM header
            o.write("P5\n%d %d\n255\n" % self.size)
        while True:
            type, size = self.field()
            if type != (8, 10):
                break
            while size > 0:
                s = self.fp.read(min(size, 8192))
                if not s:
                    break
                o.write(s)
                size -= len(s)
        o.close()

        try:
            try:
                # fast
                self.im = Image.core.open_ppm(outfile)
            except:
                # slightly slower
                im = Image.open(outfile)
                im.load()
                self.im = im.im
        finally:
            try:
                os.unlink(outfile)
            except:
                pass


Image.register_open("IPTC", IptcImageFile)

Image.register_extension("IPTC", ".iim")


##
# Get IPTC information from TIFF, JPEG, or IPTC file.
#
# @param im An image containing IPTC data.
# @return A dictionary containing IPTC information, or None if
#     no IPTC information block was found.

def getiptcinfo(im):

    from PIL import TiffImagePlugin, JpegImagePlugin
    import io

    data = None

    if isinstance(im, IptcImageFile):
        # return info dictionary right away
        return im.info

    elif isinstance(im, JpegImagePlugin.JpegImageFile):
        # extract the IPTC/NAA resource
        try:
            app = im.app["APP13"]
            if app[:14] == "Photoshop 3.0\x00":
                app = app[14:]
                # parse the image resource block
                offset = 0
                while app[offset:offset+4] == "8BIM":
                    offset += 4
                    # resource code
                    code = JpegImagePlugin.i16(app, offset)
                    offset += 2
                    # resource name (usually empty)
                    name_len = i8(app[offset])
                    name = app[offset+1:offset+1+name_len]
                    offset = 1 + offset + name_len
                    if offset & 1:
                        offset += 1
                    # resource data block
                    size = JpegImagePlugin.i32(app, offset)
                    offset += 4
                    if code == 0x0404:
                        # 0x0404 contains IPTC/NAA data
                        data = app[offset:offset+size]
                        break
                    offset = offset + size
                    if offset & 1:
                        offset += 1
        except (AttributeError, KeyError):
            pass

    elif isinstance(im, TiffImagePlugin.TiffImageFile):
        # get raw data from the IPTC/NAA tag (PhotoShop tags the data
        # as 4-byte integers, so we cannot use the get method...)
        try:
            data = im.tag.tagdata[TiffImagePlugin.IPTC_NAA_CHUNK]
        except (AttributeError, KeyError):
            pass

    if data is None:
        return None  # no properties

    # create an IptcImagePlugin object without initializing it
    class FakeImage:
        pass
    im = FakeImage()
    im.__class__ = IptcImageFile

    # parse the IPTC information chunk
    im.info = {}
    im.fp = io.BytesIO(data)

    try:
        im._open()
    except (IndexError, KeyError):
        pass  # expected failure

    return im.info

```
--- END FILE ---

Please first localize the bug based on the issue statement, and then generate *SEARCH/REPLACE* edits to fix the issue.

Every *SEARCH/REPLACE* edit must use this format:
1. The file path
2. The start of search block: <<<<<<< SEARCH
3. A contiguous chunk of lines to search for in the existing source code
4. The dividing line: =======
5. The lines to replace into the source code
6. The end of the replace block: >>>>>>> REPLACE

Here is an example:

```python
### mathweb/flask/app.py
<<<<<<< SEARCH
from flask import Flask
=======
import math
from flask import Flask
>>>>>>> REPLACE
```
</solution>

Please note that the *SEARCH/REPLACE* edit REQUIRES PROPER INDENTATION. If you would like to add the line '        print(x)', you must fully write that out, with all those spaces before the code!
Wrap each *SEARCH/REPLACE* edit in a code block as shown in the example above. If you have multiple *SEARCH/REPLACE* edits, use a separate code block for each one.
user