We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Fix output in multi result pagination (build_full_result)
Because we use izip_longest you can get a response like this:

```
{"CommonPrefixes": [null, null, null, null],
 "Content": [{...}, {...}, {...}, {...}
}
```

When really if the null we shouldn't add it to the list.  Then our response _should_ look like:

```
{"CommonPrefixes": [],
 "Content":  [{...}, {...}, {...}, {...}
}
```


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `botocore/paginate.py`
Content:
```
1 # Copyright (c) 2013 Amazon.com, Inc. or its affiliates.  All Rights Reserved
2 #
3 # Permission is hereby granted, free of charge, to any person obtaining a
4 # copy of this software and associated documentation files (the
5 # "Software"), to deal in the Software without restriction, including
6 # without limitation the rights to use, copy, modify, merge, publish, dis-
7 # tribute, sublicense, and/or sell copies of the Software, and to permit
8 # persons to whom the Software is furnished to do so, subject to the fol-
9 # lowing conditions:
10 #
11 # The above copyright notice and this permission notice shall be included
12 # in all copies or substantial portions of the Software.
13 #
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
16 # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
17 # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20 # IN THE SOFTWARE.
21 #
22 from itertools import tee
23 from collections import defaultdict
24 try:
25     from itertools import zip_longest
26 except ImportError:
27     # Python2.x is izip_longest.
28     from itertools import izip_longest as zip_longest
29 
30 try:
31     zip
32 except NameError:
33     # Python2.x is izip.
34     from itertools import izip as zip
35 
36 import jmespath
37 from botocore.exceptions import PaginationError
38 
39 
40 class Paginator(object):
41     def __init__(self, operation):
42         self._operation = operation
43         self._pagination_cfg = operation.pagination
44         self._output_token = self._get_output_tokens(self._pagination_cfg)
45         self._input_token = self._get_input_tokens(self._pagination_cfg)
46         self._more_results = self._get_more_results_token(self._pagination_cfg)
47         self._result_key = self._get_result_key(self._pagination_cfg)
48 
49     def _get_output_tokens(self, config):
50         output = []
51         output_token = config['output_token']
52         if not isinstance(output_token, list):
53             output_token = [output_token]
54         for config in output_token:
55             output.append(jmespath.compile(config))
56         return output
57 
58     def _get_input_tokens(self, config):
59         input_token = self._pagination_cfg['py_input_token']
60         if not isinstance(input_token, list):
61             input_token = [input_token]
62         return input_token
63 
64     def _get_more_results_token(self, config):
65         more_results = config.get('more_results')
66         if more_results is not None:
67             return jmespath.compile(more_results)
68 
69     def _get_result_key(self, config):
70         result_key = config.get('result_key')
71         if result_key is not None:
72             if not isinstance(result_key, list):
73                 result_key = [result_key]
74             return result_key
75 
76     def paginate(self, endpoint, **kwargs):
77         """Paginate responses to an operation.
78 
79         The responses to some operations are too large for a single response.
80         When this happens, the service will indicate that there are more
81         results in its response.  This method handles the details of how
82         to detect when this happens and how to retrieve more results.
83 
84         This method returns an iterator.  Each element in the iterator
85         is the result of an ``Operation.call`` call, so each element is
86         a tuple of (``http_response``, ``parsed_result``).
87 
88         """
89         return PageIterator(self._operation, self._input_token,
90                             self._output_token, self._more_results,
91                             self._result_key, endpoint, kwargs)
92 
93 
94 
95 class PageIterator(object):
96     def __init__(self, operation, input_token, output_token, more_results,
97                  result_key, endpoint, op_kwargs):
98         self._operation = operation
99         self._input_token = input_token
100         self._output_token = output_token
101         self._more_results = more_results
102         self._result_key = result_key
103         self._endpoint = endpoint
104         self._op_kwargs = op_kwargs
105         self._http_responses = []
106 
107     @property
108     def http_responses(self):
109         return self._http_responses
110 
111     def __iter__(self):
112         current_kwargs = self._op_kwargs
113         endpoint = self._endpoint
114         previous_next_token = None
115         while True:
116             http_response, parsed = self._operation.call(endpoint,
117                                                          **current_kwargs)
118             self._http_responses.append(http_response)
119             yield http_response, parsed
120             next_token = self._get_next_token(parsed)
121             if all(t is None for t in next_token):
122                 break
123             if previous_next_token is not None and \
124                     previous_next_token == next_token:
125                 message = ("The same next token was received "
126                            "twice: %s" % next_token)
127                 raise PaginationError(message=message)
128             for name, token in zip(self._input_token, next_token):
129                 current_kwargs[name] = token
130             previous_next_token = next_token
131 
132     def _get_next_token(self, parsed):
133         if self._more_results is not None:
134             if not self._more_results.search(parsed):
135                 return [None]
136         next_tokens = []
137         for token in self._output_token:
138             next_tokens.append(token.search(parsed))
139         return next_tokens
140 
141     def result_key_iters(self):
142         teed_results = tee(self, len(self._result_key))
143         return [ResultKeyIterator(i, result_key) for i, result_key
144                 in zip(teed_results, self._result_key)]
145 
146     def build_full_result(self):
147         iterators = self.result_key_iters()
148         if len(iterators) > 1:
149            response = defaultdict(list)
150            key_names = [i.result_key for i in iterators]
151            for vals in zip_longest(*iterators):
152                for k, val in zip(key_names, vals):
153                    response[k].append(val)
154         else:
155             response = list(iterators[0])
156         return response
157 
158 
159 class ResultKeyIterator(object):
160     """Iterates over the results of paginated responses."""
161     def __init__(self, pages_iterator, result_key):
162         self._pages_iterator = pages_iterator
163         self.result_key = result_key
164 
165     def __iter__(self):
166         for _, page in self._pages_iterator:
167             for result in page.get(self.result_key, []):
168                 yield result
169
```
--- 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/botocore/paginate.py b/botocore/paginate.py
--- a/botocore/paginate.py
+++ b/botocore/paginate.py
@@ -20,7 +20,6 @@
 # IN THE SOFTWARE.
 #
 from itertools import tee
-from collections import defaultdict
 try:
     from itertools import zip_longest
 except ImportError:
@@ -146,11 +145,14 @@
     def build_full_result(self):
         iterators = self.result_key_iters()
         if len(iterators) > 1:
-           response = defaultdict(list)
+           response = {}
            key_names = [i.result_key for i in iterators]
+           for key in key_names:
+               response[key] = []
            for vals in zip_longest(*iterators):
                for k, val in zip(key_names, vals):
-                   response[k].append(val)
+                   if val is not None:
+                       response[k].append(val)
         else:
             response = list(iterators[0])
         return response

{"golden_diff": "diff --git a/botocore/paginate.py b/botocore/paginate.py\n--- a/botocore/paginate.py\n+++ b/botocore/paginate.py\n@@ -20,7 +20,6 @@\n # IN THE SOFTWARE.\n #\n from itertools import tee\n-from collections import defaultdict\n try:\n     from itertools import zip_longest\n except ImportError:\n@@ -146,11 +145,14 @@\n     def build_full_result(self):\n         iterators = self.result_key_iters()\n         if len(iterators) > 1:\n-           response = defaultdict(list)\n+           response = {}\n            key_names = [i.result_key for i in iterators]\n+           for key in key_names:\n+               response[key] = []\n            for vals in zip_longest(*iterators):\n                for k, val in zip(key_names, vals):\n-                   response[k].append(val)\n+                   if val is not None:\n+                       response[k].append(val)\n         else:\n             response = list(iterators[0])\n         return response\n", "issue": "Fix output in multi result pagination (build_full_result)\nBecause we use izip_longest you can get a response like this:\n\n```\n{\"CommonPrefixes\": [null, null, null, null],\n \"Content\": [{...}, {...}, {...}, {...}\n}\n```\n\nWhen really if the null we shouldn't add it to the list.  Then our response _should_ look like:\n\n```\n{\"CommonPrefixes\": [],\n \"Content\":  [{...}, {...}, {...}, {...}\n}\n```\n\n", "before_files": [{"content": "# Copyright (c) 2013 Amazon.com, Inc. or its affiliates.  All Rights Reserved\n#\n# Permission is hereby granted, free of charge, to any person obtaining a\n# copy of this software and associated documentation files (the\n# \"Software\"), to deal in the Software without restriction, including\n# without limitation the rights to use, copy, modify, merge, publish, dis-\n# tribute, sublicense, and/or sell copies of the Software, and to permit\n# persons to whom the Software is furnished to do so, subject to the fol-\n# lowing conditions:\n#\n# The above copyright notice and this permission notice shall be included\n# in all copies or substantial portions of the Software.\n#\n# THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\n# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-\n# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT\n# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\n# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n# IN THE SOFTWARE.\n#\nfrom itertools import tee\nfrom collections import defaultdict\ntry:\n    from itertools import zip_longest\nexcept ImportError:\n    # Python2.x is izip_longest.\n    from itertools import izip_longest as zip_longest\n\ntry:\n    zip\nexcept NameError:\n    # Python2.x is izip.\n    from itertools import izip as zip\n\nimport jmespath\nfrom botocore.exceptions import PaginationError\n\n\nclass Paginator(object):\n    def __init__(self, operation):\n        self._operation = operation\n        self._pagination_cfg = operation.pagination\n        self._output_token = self._get_output_tokens(self._pagination_cfg)\n        self._input_token = self._get_input_tokens(self._pagination_cfg)\n        self._more_results = self._get_more_results_token(self._pagination_cfg)\n        self._result_key = self._get_result_key(self._pagination_cfg)\n\n    def _get_output_tokens(self, config):\n        output = []\n        output_token = config['output_token']\n        if not isinstance(output_token, list):\n            output_token = [output_token]\n        for config in output_token:\n            output.append(jmespath.compile(config))\n        return output\n\n    def _get_input_tokens(self, config):\n        input_token = self._pagination_cfg['py_input_token']\n        if not isinstance(input_token, list):\n            input_token = [input_token]\n        return input_token\n\n    def _get_more_results_token(self, config):\n        more_results = config.get('more_results')\n        if more_results is not None:\n            return jmespath.compile(more_results)\n\n    def _get_result_key(self, config):\n        result_key = config.get('result_key')\n        if result_key is not None:\n            if not isinstance(result_key, list):\n                result_key = [result_key]\n            return result_key\n\n    def paginate(self, endpoint, **kwargs):\n        \"\"\"Paginate responses to an operation.\n\n        The responses to some operations are too large for a single response.\n        When this happens, the service will indicate that there are more\n        results in its response.  This method handles the details of how\n        to detect when this happens and how to retrieve more results.\n\n        This method returns an iterator.  Each element in the iterator\n        is the result of an ``Operation.call`` call, so each element is\n        a tuple of (``http_response``, ``parsed_result``).\n\n        \"\"\"\n        return PageIterator(self._operation, self._input_token,\n                            self._output_token, self._more_results,\n                            self._result_key, endpoint, kwargs)\n\n\n\nclass PageIterator(object):\n    def __init__(self, operation, input_token, output_token, more_results,\n                 result_key, endpoint, op_kwargs):\n        self._operation = operation\n        self._input_token = input_token\n        self._output_token = output_token\n        self._more_results = more_results\n        self._result_key = result_key\n        self._endpoint = endpoint\n        self._op_kwargs = op_kwargs\n        self._http_responses = []\n\n    @property\n    def http_responses(self):\n        return self._http_responses\n\n    def __iter__(self):\n        current_kwargs = self._op_kwargs\n        endpoint = self._endpoint\n        previous_next_token = None\n        while True:\n            http_response, parsed = self._operation.call(endpoint,\n                                                         **current_kwargs)\n            self._http_responses.append(http_response)\n            yield http_response, parsed\n            next_token = self._get_next_token(parsed)\n            if all(t is None for t in next_token):\n                break\n            if previous_next_token is not None and \\\n                    previous_next_token == next_token:\n                message = (\"The same next token was received \"\n                           \"twice: %s\" % next_token)\n                raise PaginationError(message=message)\n            for name, token in zip(self._input_token, next_token):\n                current_kwargs[name] = token\n            previous_next_token = next_token\n\n    def _get_next_token(self, parsed):\n        if self._more_results is not None:\n            if not self._more_results.search(parsed):\n                return [None]\n        next_tokens = []\n        for token in self._output_token:\n            next_tokens.append(token.search(parsed))\n        return next_tokens\n\n    def result_key_iters(self):\n        teed_results = tee(self, len(self._result_key))\n        return [ResultKeyIterator(i, result_key) for i, result_key\n                in zip(teed_results, self._result_key)]\n\n    def build_full_result(self):\n        iterators = self.result_key_iters()\n        if len(iterators) > 1:\n           response = defaultdict(list)\n           key_names = [i.result_key for i in iterators]\n           for vals in zip_longest(*iterators):\n               for k, val in zip(key_names, vals):\n                   response[k].append(val)\n        else:\n            response = list(iterators[0])\n        return response\n\n\nclass ResultKeyIterator(object):\n    \"\"\"Iterates over the results of paginated responses.\"\"\"\n    def __init__(self, pages_iterator, result_key):\n        self._pages_iterator = pages_iterator\n        self.result_key = result_key\n\n    def __iter__(self):\n        for _, page in self._pages_iterator:\n            for result in page.get(self.result_key, []):\n                yield result\n", "path": "botocore/paginate.py"}], "after_files": [{"content": "# Copyright (c) 2013 Amazon.com, Inc. or its affiliates.  All Rights Reserved\n#\n# Permission is hereby granted, free of charge, to any person obtaining a\n# copy of this software and associated documentation files (the\n# \"Software\"), to deal in the Software without restriction, including\n# without limitation the rights to use, copy, modify, merge, publish, dis-\n# tribute, sublicense, and/or sell copies of the Software, and to permit\n# persons to whom the Software is furnished to do so, subject to the fol-\n# lowing conditions:\n#\n# The above copyright notice and this permission notice shall be included\n# in all copies or substantial portions of the Software.\n#\n# THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\n# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-\n# ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT\n# SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\n# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS\n# IN THE SOFTWARE.\n#\nfrom itertools import tee\ntry:\n    from itertools import zip_longest\nexcept ImportError:\n    # Python2.x is izip_longest.\n    from itertools import izip_longest as zip_longest\n\ntry:\n    zip\nexcept NameError:\n    # Python2.x is izip.\n    from itertools import izip as zip\n\nimport jmespath\nfrom botocore.exceptions import PaginationError\n\n\nclass Paginator(object):\n    def __init__(self, operation):\n        self._operation = operation\n        self._pagination_cfg = operation.pagination\n        self._output_token = self._get_output_tokens(self._pagination_cfg)\n        self._input_token = self._get_input_tokens(self._pagination_cfg)\n        self._more_results = self._get_more_results_token(self._pagination_cfg)\n        self._result_key = self._get_result_key(self._pagination_cfg)\n\n    def _get_output_tokens(self, config):\n        output = []\n        output_token = config['output_token']\n        if not isinstance(output_token, list):\n            output_token = [output_token]\n        for config in output_token:\n            output.append(jmespath.compile(config))\n        return output\n\n    def _get_input_tokens(self, config):\n        input_token = self._pagination_cfg['py_input_token']\n        if not isinstance(input_token, list):\n            input_token = [input_token]\n        return input_token\n\n    def _get_more_results_token(self, config):\n        more_results = config.get('more_results')\n        if more_results is not None:\n            return jmespath.compile(more_results)\n\n    def _get_result_key(self, config):\n        result_key = config.get('result_key')\n        if result_key is not None:\n            if not isinstance(result_key, list):\n                result_key = [result_key]\n            return result_key\n\n    def paginate(self, endpoint, **kwargs):\n        \"\"\"Paginate responses to an operation.\n\n        The responses to some operations are too large for a single response.\n        When this happens, the service will indicate that there are more\n        results in its response.  This method handles the details of how\n        to detect when this happens and how to retrieve more results.\n\n        This method returns an iterator.  Each element in the iterator\n        is the result of an ``Operation.call`` call, so each element is\n        a tuple of (``http_response``, ``parsed_result``).\n\n        \"\"\"\n        return PageIterator(self._operation, self._input_token,\n                            self._output_token, self._more_results,\n                            self._result_key, endpoint, kwargs)\n\n\n\nclass PageIterator(object):\n    def __init__(self, operation, input_token, output_token, more_results,\n                 result_key, endpoint, op_kwargs):\n        self._operation = operation\n        self._input_token = input_token\n        self._output_token = output_token\n        self._more_results = more_results\n        self._result_key = result_key\n        self._endpoint = endpoint\n        self._op_kwargs = op_kwargs\n        self._http_responses = []\n\n    @property\n    def http_responses(self):\n        return self._http_responses\n\n    def __iter__(self):\n        current_kwargs = self._op_kwargs\n        endpoint = self._endpoint\n        previous_next_token = None\n        while True:\n            http_response, parsed = self._operation.call(endpoint,\n                                                         **current_kwargs)\n            self._http_responses.append(http_response)\n            yield http_response, parsed\n            next_token = self._get_next_token(parsed)\n            if all(t is None for t in next_token):\n                break\n            if previous_next_token is not None and \\\n                    previous_next_token == next_token:\n                message = (\"The same next token was received \"\n                           \"twice: %s\" % next_token)\n                raise PaginationError(message=message)\n            for name, token in zip(self._input_token, next_token):\n                current_kwargs[name] = token\n            previous_next_token = next_token\n\n    def _get_next_token(self, parsed):\n        if self._more_results is not None:\n            if not self._more_results.search(parsed):\n                return [None]\n        next_tokens = []\n        for token in self._output_token:\n            next_tokens.append(token.search(parsed))\n        return next_tokens\n\n    def result_key_iters(self):\n        teed_results = tee(self, len(self._result_key))\n        return [ResultKeyIterator(i, result_key) for i, result_key\n                in zip(teed_results, self._result_key)]\n\n    def build_full_result(self):\n        iterators = self.result_key_iters()\n        if len(iterators) > 1:\n           response = {}\n           key_names = [i.result_key for i in iterators]\n           for key in key_names:\n               response[key] = []\n           for vals in zip_longest(*iterators):\n               for k, val in zip(key_names, vals):\n                   if val is not None:\n                       response[k].append(val)\n        else:\n            response = list(iterators[0])\n        return response\n\n\nclass ResultKeyIterator(object):\n    \"\"\"Iterates over the results of paginated responses.\"\"\"\n    def __init__(self, pages_iterator, result_key):\n        self._pages_iterator = pages_iterator\n        self.result_key = result_key\n\n    def __iter__(self):\n        for _, page in self._pages_iterator:\n            for result in page.get(self.result_key, []):\n                yield result\n", "path": "botocore/paginate.py"}]}