prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Repeated looping over image stack shows last frame in place of first frame
  When looping through the frames in an animation or TIFF stack with `ImageSequence.Iterator`, the frame pointer is not reset for the first frame. Consequently, if the loop is run through a second time the final frame is shown again instead of the first frame.
  ### Demo
  
  Code
  
  ``` python
  from PIL import Image, ImageSequence
  import os
  # Make a test image
  os.system((
      "convert -depth 8 -size 1x1 xc:'rgb(100,100,100)' xc:'rgb(121,121,121)'"
      " xc:'rgb(142,142,142)' xc:'rgb(163,163,163)' image.tif"
  ))
  # Open the image
  im = Image.open('image.tif')
  # Run through the image
  print('First run')
  for frame in ImageSequence.Iterator(im):
      print(list(frame.getdata()))
  # Run through the image again
  print('Second run')
  for frame in ImageSequence.Iterator(im):
      print(list(frame.getdata()))
  ```
  
  Output
  
  ```
  First run
  [100]
  [121]
  [142]
  [163]
  Second run
  [163]
  [121]
  [142]
  [163]
  ```
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `PIL/ImageSequence.py`
  Content:
  ```
  1 #
  2 # The Python Imaging Library.
  3 # $Id$
  4 #
  5 # sequence support classes
  6 #
  7 # history:
  8 # 1997-02-20 fl     Created
  9 #
  10 # Copyright (c) 1997 by Secret Labs AB.
  11 # Copyright (c) 1997 by Fredrik Lundh.
  12 #
  13 # See the README file for information on usage and redistribution.
  14 #
  15 
  16 ##
  17 
  18 
  19 class Iterator(object):
  20     """
  21     This class implements an iterator object that can be used to loop
  22     over an image sequence.
  23 
  24     You can use the ``[]`` operator to access elements by index. This operator
  25     will raise an :py:exc:`IndexError` if you try to access a nonexistent
  26     frame.
  27 
  28     :param im: An image object.
  29     """
  30 
  31     def __init__(self, im):
  32         if not hasattr(im, "seek"):
  33             raise AttributeError("im must have seek method")
  34         self.im = im
  35 
  36     def __getitem__(self, ix):
  37         try:
  38             if ix:
  39                 self.im.seek(ix)
  40             return self.im
  41         except EOFError:
  42             raise IndexError  # end of sequence
  43
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/PIL/ImageSequence.py b/PIL/ImageSequence.py
  --- a/PIL/ImageSequence.py
  +++ b/PIL/ImageSequence.py
  @@ -35,8 +35,7 @@
   
       def __getitem__(self, ix):
           try:
  -            if ix:
  -                self.im.seek(ix)
  +            self.im.seek(ix)
               return self.im
           except EOFError:
               raise IndexError  # end of sequence
  
verification_info: {"golden_diff": "diff --git a/PIL/ImageSequence.py b/PIL/ImageSequence.py\n--- a/PIL/ImageSequence.py\n+++ b/PIL/ImageSequence.py\n@@ -35,8 +35,7 @@\n \n     def __getitem__(self, ix):\n         try:\n-            if ix:\n-                self.im.seek(ix)\n+            self.im.seek(ix)\n             return self.im\n         except EOFError:\n             raise IndexError  # end of sequence\n", "issue": "Repeated looping over image stack shows last frame in place of first frame\nWhen looping through the frames in an animation or TIFF stack with `ImageSequence.Iterator`, the frame pointer is not reset for the first frame. Consequently, if the loop is run through a second time the final frame is shown again instead of the first frame.\n### Demo\n\nCode\n\n``` python\nfrom PIL import Image, ImageSequence\nimport os\n# Make a test image\nos.system((\n    \"convert -depth 8 -size 1x1 xc:'rgb(100,100,100)' xc:'rgb(121,121,121)'\"\n    \" xc:'rgb(142,142,142)' xc:'rgb(163,163,163)' image.tif\"\n))\n# Open the image\nim = Image.open('image.tif')\n# Run through the image\nprint('First run')\nfor frame in ImageSequence.Iterator(im):\n    print(list(frame.getdata()))\n# Run through the image again\nprint('Second run')\nfor frame in ImageSequence.Iterator(im):\n    print(list(frame.getdata()))\n```\n\nOutput\n\n```\nFirst run\n[100]\n[121]\n[142]\n[163]\nSecond run\n[163]\n[121]\n[142]\n[163]\n```\n\n", "before_files": [{"content": "#\n# The Python Imaging Library.\n# $Id$\n#\n# sequence support classes\n#\n# history:\n# 1997-02-20 fl     Created\n#\n# Copyright (c) 1997 by Secret Labs AB.\n# Copyright (c) 1997 by Fredrik Lundh.\n#\n# See the README file for information on usage and redistribution.\n#\n\n##\n\n\nclass Iterator(object):\n    \"\"\"\n    This class implements an iterator object that can be used to loop\n    over an image sequence.\n\n    You can use the ``[]`` operator to access elements by index. This operator\n    will raise an :py:exc:`IndexError` if you try to access a nonexistent\n    frame.\n\n    :param im: An image object.\n    \"\"\"\n\n    def __init__(self, im):\n        if not hasattr(im, \"seek\"):\n            raise AttributeError(\"im must have seek method\")\n        self.im = im\n\n    def __getitem__(self, ix):\n        try:\n            if ix:\n                self.im.seek(ix)\n            return self.im\n        except EOFError:\n            raise IndexError  # end of sequence\n", "path": "PIL/ImageSequence.py"}], "after_files": [{"content": "#\n# The Python Imaging Library.\n# $Id$\n#\n# sequence support classes\n#\n# history:\n# 1997-02-20 fl     Created\n#\n# Copyright (c) 1997 by Secret Labs AB.\n# Copyright (c) 1997 by Fredrik Lundh.\n#\n# See the README file for information on usage and redistribution.\n#\n\n##\n\n\nclass Iterator(object):\n    \"\"\"\n    This class implements an iterator object that can be used to loop\n    over an image sequence.\n\n    You can use the ``[]`` operator to access elements by index. This operator\n    will raise an :py:exc:`IndexError` if you try to access a nonexistent\n    frame.\n\n    :param im: An image object.\n    \"\"\"\n\n    def __init__(self, im):\n        if not hasattr(im, \"seek\"):\n            raise AttributeError(\"im must have seek method\")\n        self.im = im\n\n    def __getitem__(self, ix):\n        try:\n            self.im.seek(ix)\n            return self.im\n        except EOFError:\n            raise IndexError  # end of sequence\n", "path": "PIL/ImageSequence.py"}]}