We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
No way to add query parameters without a value
I occasionally need to put a hint in the query string for a URL, which is essentially a parameter without a value. This can be important to provide information to javascript or as a hint to GA. For example I may need to use `http://localhost/dashboard?new-user` as URL when I redirect a new user to the dashboard after completing registration.

Intuitively I expected this to work:

``` python
return HTTPFound(request.route_url('dashboard', _query={'new-user': None}))
```

but that returns `/dashboard?new-user=None` which is not very pretty.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `pyramid/encode.py`
Content:
```
1 from pyramid.compat import (
2     text_type,
3     binary_type,
4     is_nonstr_iter,
5     url_quote as _url_quote,
6     url_quote_plus as quote_plus, # bw compat api (dnr)
7     )
8 
9 def url_quote(s, safe=''): # bw compat api
10     return _url_quote(s, safe=safe)
11 
12 def urlencode(query, doseq=True):
13     """
14     An alternate implementation of Python's stdlib `urllib.urlencode
15     function <http://docs.python.org/library/urllib.html>`_ which
16     accepts unicode keys and values within the ``query``
17     dict/sequence; all Unicode keys and values are first converted to
18     UTF-8 before being used to compose the query string.
19 
20     The value of ``query`` must be a sequence of two-tuples
21     representing key/value pairs *or* an object (often a dictionary)
22     with an ``.items()`` method that returns a sequence of two-tuples
23     representing key/value pairs.
24 
25     For minimal calling convention backwards compatibility, this
26     version of urlencode accepts *but ignores* a second argument
27     conventionally named ``doseq``.  The Python stdlib version behaves
28     differently when ``doseq`` is False and when a sequence is
29     presented as one of the values.  This version always behaves in
30     the ``doseq=True`` mode, no matter what the value of the second
31     argument.
32 
33     See the Python stdlib documentation for ``urllib.urlencode`` for
34     more information.
35     """
36     try:
37         # presumed to be a dictionary
38         query = query.items()
39     except AttributeError:
40         pass
41 
42     result = ''
43     prefix = ''
44 
45     for (k, v) in query:
46         k = _enc(k)
47 
48         if is_nonstr_iter(v):
49             for x in v:
50                 x = _enc(x)
51                 result += '%s%s=%s' % (prefix, k, x)
52                 prefix = '&'
53         else:
54             v = _enc(v)
55             result += '%s%s=%s' % (prefix, k, v)
56 
57         prefix = '&'
58 
59     return result
60 
61 def _enc(val):
62     cls = val.__class__
63     if cls is text_type:
64         val = val.encode('utf-8')
65     elif cls is not binary_type:
66         val = str(val).encode('utf-8')
67     return quote_plus(val)
68 
69
```
--- 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/pyramid/encode.py b/pyramid/encode.py
--- a/pyramid/encode.py
+++ b/pyramid/encode.py
@@ -32,6 +32,10 @@
 
     See the Python stdlib documentation for ``urllib.urlencode`` for
     more information.
+
+    .. versionchanged:: 1.5
+       In a key/value pair, if the value is ``None`` then it will be
+       dropped from the resulting output.
     """
     try:
         # presumed to be a dictionary
@@ -50,6 +54,8 @@
                 x = _enc(x)
                 result += '%s%s=%s' % (prefix, k, x)
                 prefix = '&'
+        elif v is None:
+            result += '%s%s=' % (prefix, k)
         else:
             v = _enc(v)
             result += '%s%s=%s' % (prefix, k, v)

{"golden_diff": "diff --git a/pyramid/encode.py b/pyramid/encode.py\n--- a/pyramid/encode.py\n+++ b/pyramid/encode.py\n@@ -32,6 +32,10 @@\n \n     See the Python stdlib documentation for ``urllib.urlencode`` for\n     more information.\n+\n+    .. versionchanged:: 1.5\n+       In a key/value pair, if the value is ``None`` then it will be\n+       dropped from the resulting output.\n     \"\"\"\n     try:\n         # presumed to be a dictionary\n@@ -50,6 +54,8 @@\n                 x = _enc(x)\n                 result += '%s%s=%s' % (prefix, k, x)\n                 prefix = '&'\n+        elif v is None:\n+            result += '%s%s=' % (prefix, k)\n         else:\n             v = _enc(v)\n             result += '%s%s=%s' % (prefix, k, v)\n", "issue": "No way to add query parameters without a value\nI occasionally need to put a hint in the query string for a URL, which is essentially a parameter without a value. This can be important to provide information to javascript or as a hint to GA. For example I may need to use `http://localhost/dashboard?new-user` as URL when I redirect a new user to the dashboard after completing registration.\n\nIntuitively I expected this to work:\n\n``` python\nreturn HTTPFound(request.route_url('dashboard', _query={'new-user': None}))\n```\n\nbut that returns `/dashboard?new-user=None` which is not very pretty.\n\n", "before_files": [{"content": "from pyramid.compat import (\n    text_type,\n    binary_type,\n    is_nonstr_iter,\n    url_quote as _url_quote,\n    url_quote_plus as quote_plus, # bw compat api (dnr)\n    )\n\ndef url_quote(s, safe=''): # bw compat api\n    return _url_quote(s, safe=safe)\n\ndef urlencode(query, doseq=True):\n    \"\"\"\n    An alternate implementation of Python's stdlib `urllib.urlencode\n    function <http://docs.python.org/library/urllib.html>`_ which\n    accepts unicode keys and values within the ``query``\n    dict/sequence; all Unicode keys and values are first converted to\n    UTF-8 before being used to compose the query string.\n\n    The value of ``query`` must be a sequence of two-tuples\n    representing key/value pairs *or* an object (often a dictionary)\n    with an ``.items()`` method that returns a sequence of two-tuples\n    representing key/value pairs.\n\n    For minimal calling convention backwards compatibility, this\n    version of urlencode accepts *but ignores* a second argument\n    conventionally named ``doseq``.  The Python stdlib version behaves\n    differently when ``doseq`` is False and when a sequence is\n    presented as one of the values.  This version always behaves in\n    the ``doseq=True`` mode, no matter what the value of the second\n    argument.\n\n    See the Python stdlib documentation for ``urllib.urlencode`` for\n    more information.\n    \"\"\"\n    try:\n        # presumed to be a dictionary\n        query = query.items()\n    except AttributeError:\n        pass\n\n    result = ''\n    prefix = ''\n\n    for (k, v) in query:\n        k = _enc(k)\n\n        if is_nonstr_iter(v):\n            for x in v:\n                x = _enc(x)\n                result += '%s%s=%s' % (prefix, k, x)\n                prefix = '&'\n        else:\n            v = _enc(v)\n            result += '%s%s=%s' % (prefix, k, v)\n\n        prefix = '&'\n\n    return result\n\ndef _enc(val):\n    cls = val.__class__\n    if cls is text_type:\n        val = val.encode('utf-8')\n    elif cls is not binary_type:\n        val = str(val).encode('utf-8')\n    return quote_plus(val)\n\n", "path": "pyramid/encode.py"}], "after_files": [{"content": "from pyramid.compat import (\n    text_type,\n    binary_type,\n    is_nonstr_iter,\n    url_quote as _url_quote,\n    url_quote_plus as quote_plus, # bw compat api (dnr)\n    )\n\ndef url_quote(s, safe=''): # bw compat api\n    return _url_quote(s, safe=safe)\n\ndef urlencode(query, doseq=True):\n    \"\"\"\n    An alternate implementation of Python's stdlib `urllib.urlencode\n    function <http://docs.python.org/library/urllib.html>`_ which\n    accepts unicode keys and values within the ``query``\n    dict/sequence; all Unicode keys and values are first converted to\n    UTF-8 before being used to compose the query string.\n\n    The value of ``query`` must be a sequence of two-tuples\n    representing key/value pairs *or* an object (often a dictionary)\n    with an ``.items()`` method that returns a sequence of two-tuples\n    representing key/value pairs.\n\n    For minimal calling convention backwards compatibility, this\n    version of urlencode accepts *but ignores* a second argument\n    conventionally named ``doseq``.  The Python stdlib version behaves\n    differently when ``doseq`` is False and when a sequence is\n    presented as one of the values.  This version always behaves in\n    the ``doseq=True`` mode, no matter what the value of the second\n    argument.\n\n    See the Python stdlib documentation for ``urllib.urlencode`` for\n    more information.\n\n    .. versionchanged:: 1.5\n       In a key/value pair, if the value is ``None`` then it will be\n       dropped from the resulting output.\n    \"\"\"\n    try:\n        # presumed to be a dictionary\n        query = query.items()\n    except AttributeError:\n        pass\n\n    result = ''\n    prefix = ''\n\n    for (k, v) in query:\n        k = _enc(k)\n\n        if is_nonstr_iter(v):\n            for x in v:\n                x = _enc(x)\n                result += '%s%s=%s' % (prefix, k, x)\n                prefix = '&'\n        elif v is None:\n            result += '%s%s=' % (prefix, k)\n        else:\n            v = _enc(v)\n            result += '%s%s=%s' % (prefix, k, v)\n\n        prefix = '&'\n\n    return result\n\ndef _enc(val):\n    cls = val.__class__\n    if cls is text_type:\n        val = val.encode('utf-8')\n    elif cls is not binary_type:\n        val = str(val).encode('utf-8')\n    return quote_plus(val)\n\n", "path": "pyramid/encode.py"}]}