prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  ListingGenerator gets stuck in loop when 'before' parameter is supplied.
  ## Issue Description
  
  When retrieving submissions and supplying the 'before' parameter, the ListingGenerator gets stuck in a loop where the same 'after' parameter is submitted to reddit infinitely.  I'm submitting a pull request with a fix.  Additional details can be found in the pull request.
  
  Example:
  ``reddit.subreddit(subreddit).new(limit=1024,params={'before': 't3_7xxxxx', 'count': 1024 })``
  
  ## System Information
  
      PRAW Version: 5.3.0
    Python Version: 3.5.3
  Operating System: Debian 9.3
  
  
  </issue>
  <code>
  [start of praw/models/listing/generator.py]
  1 """Provide the ListingGenerator class."""
  2 from copy import deepcopy
  3 
  4 from .listing import FlairListing
  5 from ..base import PRAWBase
  6 
  7 
  8 class ListingGenerator(PRAWBase):
  9     """Instances of this class generate :class:`.RedditBase` instances.
  10 
  11     .. warning:: This class should not be directly utilized. Instead you will
  12        find a number of methods that return instances of the class:
  13 
  14        http://praw.readthedocs.io/en/latest/search.html?q=ListingGenerator
  15 
  16     """
  17 
  18     def __init__(self, reddit, url, limit=100, params=None):
  19         """Initialize a ListingGenerator instance.
  20 
  21         :param reddit: An instance of :class:`.Reddit`.
  22         :param url: A URL returning a reddit listing.
  23         :param limit: The number of content entries to fetch. If ``limit`` is
  24             None, then fetch as many entries as possible. Most of reddit's
  25             listings contain a maximum of 1000 items, and are returned 100 at a
  26             time. This class will automatically issue all necessary
  27             requests (default: 100).
  28         :param params: A dictionary containing additional query string
  29             parameters to send with the request.
  30 
  31         """
  32         super(ListingGenerator, self).__init__(reddit, None)
  33         self._exhausted = False
  34         self._listing = None
  35         self._list_index = None
  36         self.limit = limit
  37         self.params = deepcopy(params) if params else {}
  38         self.params['limit'] = limit or 1024
  39         self.url = url
  40         self.yielded = 0
  41 
  42     def __iter__(self):
  43         """Permit ListingGenerator to operate as an iterator."""
  44         return self
  45 
  46     def __next__(self):
  47         """Permit ListingGenerator to operate as a generator in py3."""
  48         if self.limit is not None and self.yielded >= self.limit:
  49             raise StopIteration()
  50 
  51         if self._listing is None or self._list_index >= len(self._listing):
  52             self._next_batch()
  53 
  54         self._list_index += 1
  55         self.yielded += 1
  56         return self._listing[self._list_index - 1]
  57 
  58     def _next_batch(self):
  59         if self._exhausted:
  60             raise StopIteration()
  61 
  62         self._listing = self._reddit.get(self.url, params=self.params)
  63         if isinstance(self._listing, list):
  64             self._listing = self._listing[1]  # for submission duplicates
  65         elif isinstance(self._listing, dict):
  66             self._listing = FlairListing(self._reddit, self._listing)
  67         self._list_index = 0
  68 
  69         if not self._listing:
  70             raise StopIteration()
  71 
  72         if self._listing.after:
  73             self.params['after'] = self._listing.after
  74         else:
  75             self._exhausted = True
  76 
  77     def next(self):
  78         """Permit ListingGenerator to operate as a generator in py2."""
  79         return self.__next__()
  80
  [end of praw/models/listing/generator.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/praw/models/listing/generator.py b/praw/models/listing/generator.py
  --- a/praw/models/listing/generator.py
  +++ b/praw/models/listing/generator.py
  @@ -69,7 +69,8 @@
           if not self._listing:
               raise StopIteration()
   
  -        if self._listing.after:
  +        if (self._listing.after and
  +                self._listing.after != self.params.get('after')):
               self.params['after'] = self._listing.after
           else:
               self._exhausted = True
  
verification_info: {"golden_diff": "diff --git a/praw/models/listing/generator.py b/praw/models/listing/generator.py\n--- a/praw/models/listing/generator.py\n+++ b/praw/models/listing/generator.py\n@@ -69,7 +69,8 @@\n         if not self._listing:\n             raise StopIteration()\n \n-        if self._listing.after:\n+        if (self._listing.after and\n+                self._listing.after != self.params.get('after')):\n             self.params['after'] = self._listing.after\n         else:\n             self._exhausted = True\n", "issue": "ListingGenerator gets stuck in loop when 'before' parameter is supplied.\n## Issue Description\r\n\r\nWhen retrieving submissions and supplying the 'before' parameter, the ListingGenerator gets stuck in a loop where the same 'after' parameter is submitted to reddit infinitely.  I'm submitting a pull request with a fix.  Additional details can be found in the pull request.\r\n\r\nExample:\r\n``reddit.subreddit(subreddit).new(limit=1024,params={'before': 't3_7xxxxx', 'count': 1024 })``\r\n\r\n## System Information\r\n\r\n    PRAW Version: 5.3.0\r\n  Python Version: 3.5.3\r\nOperating System: Debian 9.3\r\n\n", "before_files": [{"content": "\"\"\"Provide the ListingGenerator class.\"\"\"\nfrom copy import deepcopy\n\nfrom .listing import FlairListing\nfrom ..base import PRAWBase\n\n\nclass ListingGenerator(PRAWBase):\n    \"\"\"Instances of this class generate :class:`.RedditBase` instances.\n\n    .. warning:: This class should not be directly utilized. Instead you will\n       find a number of methods that return instances of the class:\n\n       http://praw.readthedocs.io/en/latest/search.html?q=ListingGenerator\n\n    \"\"\"\n\n    def __init__(self, reddit, url, limit=100, params=None):\n        \"\"\"Initialize a ListingGenerator instance.\n\n        :param reddit: An instance of :class:`.Reddit`.\n        :param url: A URL returning a reddit listing.\n        :param limit: The number of content entries to fetch. If ``limit`` is\n            None, then fetch as many entries as possible. Most of reddit's\n            listings contain a maximum of 1000 items, and are returned 100 at a\n            time. This class will automatically issue all necessary\n            requests (default: 100).\n        :param params: A dictionary containing additional query string\n            parameters to send with the request.\n\n        \"\"\"\n        super(ListingGenerator, self).__init__(reddit, None)\n        self._exhausted = False\n        self._listing = None\n        self._list_index = None\n        self.limit = limit\n        self.params = deepcopy(params) if params else {}\n        self.params['limit'] = limit or 1024\n        self.url = url\n        self.yielded = 0\n\n    def __iter__(self):\n        \"\"\"Permit ListingGenerator to operate as an iterator.\"\"\"\n        return self\n\n    def __next__(self):\n        \"\"\"Permit ListingGenerator to operate as a generator in py3.\"\"\"\n        if self.limit is not None and self.yielded >= self.limit:\n            raise StopIteration()\n\n        if self._listing is None or self._list_index >= len(self._listing):\n            self._next_batch()\n\n        self._list_index += 1\n        self.yielded += 1\n        return self._listing[self._list_index - 1]\n\n    def _next_batch(self):\n        if self._exhausted:\n            raise StopIteration()\n\n        self._listing = self._reddit.get(self.url, params=self.params)\n        if isinstance(self._listing, list):\n            self._listing = self._listing[1]  # for submission duplicates\n        elif isinstance(self._listing, dict):\n            self._listing = FlairListing(self._reddit, self._listing)\n        self._list_index = 0\n\n        if not self._listing:\n            raise StopIteration()\n\n        if self._listing.after:\n            self.params['after'] = self._listing.after\n        else:\n            self._exhausted = True\n\n    def next(self):\n        \"\"\"Permit ListingGenerator to operate as a generator in py2.\"\"\"\n        return self.__next__()\n", "path": "praw/models/listing/generator.py"}]}