prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  ImageSequence.Iterator name is misleading
  Hi Pillow developers,
  
  I found this error message to be rather hilarious:
  
  ```
  TypeError: 'Iterator' object is not an iterator
  ```
  
  which was produced by this code:
  
  ``` python
  from PIL import Image, ImageSequence
  
  with Image.open('multipage.tiff', mode='r') as tif:
      i = ImageSequence.Iterator(tif)
      next(i)
  ```
  
  It seems that `ImageSequence.Iterator` does not define an `__iter__()` method, which means that it is a sequence type but not an iterator type. In my opinion, this is misleading and I suggest that a proper `__iter__()` method should be added to the class definition.
  
  Thanks.
  
  
  </issue>
  <code>
  [start of PIL/ImageSequence.py]
  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 of PIL/ImageSequence.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/PIL/ImageSequence.py b/PIL/ImageSequence.py
  --- a/PIL/ImageSequence.py
  +++ b/PIL/ImageSequence.py
  @@ -32,6 +32,7 @@
           if not hasattr(im, "seek"):
               raise AttributeError("im must have seek method")
           self.im = im
  +        self.position = 0
   
       def __getitem__(self, ix):
           try:
  @@ -40,3 +41,17 @@
               return self.im
           except EOFError:
               raise IndexError  # end of sequence
  +
  +    def __iter__(self):
  +        return self
  +
  +    def __next__(self):
  +        try:
  +            self.im.seek(self.position)
  +            self.position += 1
  +            return self.im
  +        except EOFError:
  +            raise StopIteration
  +
  +    def next(self):
  +        return self.__next__()
  
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@@ -32,6 +32,7 @@\n         if not hasattr(im, \"seek\"):\n             raise AttributeError(\"im must have seek method\")\n         self.im = im\n+        self.position = 0\n \n     def __getitem__(self, ix):\n         try:\n@@ -40,3 +41,17 @@\n             return self.im\n         except EOFError:\n             raise IndexError  # end of sequence\n+\n+    def __iter__(self):\n+        return self\n+\n+    def __next__(self):\n+        try:\n+            self.im.seek(self.position)\n+            self.position += 1\n+            return self.im\n+        except EOFError:\n+            raise StopIteration\n+\n+    def next(self):\n+        return self.__next__()\n", "issue": "ImageSequence.Iterator name is misleading\nHi Pillow developers,\n\nI found this error message to be rather hilarious:\n\n```\nTypeError: 'Iterator' object is not an iterator\n```\n\nwhich was produced by this code:\n\n``` python\nfrom PIL import Image, ImageSequence\n\nwith Image.open('multipage.tiff', mode='r') as tif:\n    i = ImageSequence.Iterator(tif)\n    next(i)\n```\n\nIt seems that `ImageSequence.Iterator` does not define an `__iter__()` method, which means that it is a sequence type but not an iterator type. In my opinion, this is misleading and I suggest that a proper `__iter__()` method should be added to the class definition.\n\nThanks.\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"}]}