We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN 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


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `praw/models/listing/generator.py`
Content:
```
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 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()

```

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

{"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"}], "after_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 and\n                self._listing.after != self.params.get('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"}]}