prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Cookie secure option not encoded properly
  When `Cookies.encode` encounters `response.cookies["<cookie>"]["secure"] = False` then it outputs:
  
  `b'Domain=xad.com; Path=/; Secure=False'`
  
  where it should output:
  
  `b'Domain=xad.com; Path=/;'` when `response.cookies["<cookie>"]["secure"] = False`
  
  and
  
  `b'Domain=xad.com; Path=/; Secure;'` when `response.cookies["<cookie>"]["secure"] = True`
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `sanic/cookies.py`
  Content:
  ```
  1 import re
  2 import string
  3 
  4 # ------------------------------------------------------------ #
  5 #  SimpleCookie
  6 # ------------------------------------------------------------ #
  7 
  8 # Straight up copied this section of dark magic from SimpleCookie
  9 
  10 _LegalChars = string.ascii_letters + string.digits + "!#$%&'*+-.^_`|~:"
  11 _UnescapedChars = _LegalChars + ' ()/<=>?@[]{}'
  12 
  13 _Translator = {n: '\\%03o' % n
  14                for n in set(range(256)) - set(map(ord, _UnescapedChars))}
  15 _Translator.update({
  16     ord('"'): '\\"',
  17     ord('\\'): '\\\\',
  18 })
  19 
  20 
  21 def _quote(str):
  22     """Quote a string for use in a cookie header.
  23     If the string does not need to be double-quoted, then just return the
  24     string.  Otherwise, surround the string in doublequotes and quote
  25     (with a \) special characters.
  26     """
  27     if str is None or _is_legal_key(str):
  28         return str
  29     else:
  30         return '"' + str.translate(_Translator) + '"'
  31 
  32 
  33 _is_legal_key = re.compile('[%s]+' % re.escape(_LegalChars)).fullmatch
  34 
  35 # ------------------------------------------------------------ #
  36 #  Custom SimpleCookie
  37 # ------------------------------------------------------------ #
  38 
  39 
  40 class CookieJar(dict):
  41     """CookieJar dynamically writes headers as cookies are added and removed
  42     It gets around the limitation of one header per name by using the
  43     MultiHeader class to provide a unique key that encodes to Set-Cookie.
  44     """
  45 
  46     def __init__(self, headers):
  47         super().__init__()
  48         self.headers = headers
  49         self.cookie_headers = {}
  50 
  51     def __setitem__(self, key, value):
  52         # If this cookie doesn't exist, add it to the header keys
  53         cookie_header = self.cookie_headers.get(key)
  54         if not cookie_header:
  55             cookie = Cookie(key, value)
  56             cookie['path'] = '/'
  57             cookie_header = MultiHeader("Set-Cookie")
  58             self.cookie_headers[key] = cookie_header
  59             self.headers[cookie_header] = cookie
  60             return super().__setitem__(key, cookie)
  61         else:
  62             self[key].value = value
  63 
  64     def __delitem__(self, key):
  65         if key not in self.cookie_headers:
  66             self[key] = ''
  67             self[key]['max-age'] = 0
  68         else:
  69             cookie_header = self.cookie_headers[key]
  70             del self.headers[cookie_header]
  71             del self.cookie_headers[key]
  72             return super().__delitem__(key)
  73 
  74 
  75 class Cookie(dict):
  76     """A stripped down version of Morsel from SimpleCookie #gottagofast"""
  77     _keys = {
  78         "expires": "expires",
  79         "path": "Path",
  80         "comment": "Comment",
  81         "domain": "Domain",
  82         "max-age": "Max-Age",
  83         "secure": "Secure",
  84         "httponly": "HttpOnly",
  85         "version": "Version",
  86     }
  87     _flags = {'secure', 'httponly'}
  88 
  89     def __init__(self, key, value):
  90         if key in self._keys:
  91             raise KeyError("Cookie name is a reserved word")
  92         if not _is_legal_key(key):
  93             raise KeyError("Cookie key contains illegal characters")
  94         self.key = key
  95         self.value = value
  96         super().__init__()
  97 
  98     def __setitem__(self, key, value):
  99         if key not in self._keys:
  100             raise KeyError("Unknown cookie property")
  101         return super().__setitem__(key, value)
  102 
  103     def encode(self, encoding):
  104         output = ['%s=%s' % (self.key, _quote(self.value))]
  105         for key, value in self.items():
  106             if key == 'max-age':
  107                 try:
  108                     output.append('%s=%d' % (self._keys[key], value))
  109                 except TypeError:
  110                     output.append('%s=%s' % (self._keys[key], value))
  111             elif key == 'expires':
  112                 try:
  113                     output.append('%s=%s' % (
  114                         self._keys[key],
  115                         value.strftime("%a, %d-%b-%Y %T GMT")
  116                     ))
  117                 except AttributeError:
  118                     output.append('%s=%s' % (self._keys[key], value))
  119             elif key in self._flags and self[key]:
  120                 output.append(self._keys[key])
  121             else:
  122                 output.append('%s=%s' % (self._keys[key], value))
  123 
  124         return "; ".join(output).encode(encoding)
  125 
  126 # ------------------------------------------------------------ #
  127 #  Header Trickery
  128 # ------------------------------------------------------------ #
  129 
  130 
  131 class MultiHeader:
  132     """String-holding object which allow us to set a header within response
  133     that has a unique key, but may contain duplicate header names
  134     """
  135     def __init__(self, name):
  136         self.name = name
  137 
  138     def encode(self):
  139         return self.name.encode()
  140
  ```
  --- 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()
  
  ```
  
golden_diff: diff --git a/sanic/cookies.py b/sanic/cookies.py
  --- a/sanic/cookies.py
  +++ b/sanic/cookies.py
  @@ -98,7 +98,8 @@
       def __setitem__(self, key, value):
           if key not in self._keys:
               raise KeyError("Unknown cookie property")
  -        return super().__setitem__(key, value)
  +        if value is not False:
  +            return super().__setitem__(key, value)
   
       def encode(self, encoding):
           output = ['%s=%s' % (self.key, _quote(self.value))]
  
verification_info: {"golden_diff": "diff --git a/sanic/cookies.py b/sanic/cookies.py\n--- a/sanic/cookies.py\n+++ b/sanic/cookies.py\n@@ -98,7 +98,8 @@\n     def __setitem__(self, key, value):\n         if key not in self._keys:\n             raise KeyError(\"Unknown cookie property\")\n-        return super().__setitem__(key, value)\n+        if value is not False:\n+            return super().__setitem__(key, value)\n \n     def encode(self, encoding):\n         output = ['%s=%s' % (self.key, _quote(self.value))]\n", "issue": "Cookie secure option not encoded properly\nWhen `Cookies.encode` encounters `response.cookies[\"<cookie>\"][\"secure\"] = False` then it outputs:\r\n\r\n`b'Domain=xad.com; Path=/; Secure=False'`\r\n\r\nwhere it should output:\r\n\r\n`b'Domain=xad.com; Path=/;'` when `response.cookies[\"<cookie>\"][\"secure\"] = False`\r\n\r\nand\r\n\r\n`b'Domain=xad.com; Path=/; Secure;'` when `response.cookies[\"<cookie>\"][\"secure\"] = True`\n", "before_files": [{"content": "import re\nimport string\n\n# ------------------------------------------------------------ #\n#  SimpleCookie\n# ------------------------------------------------------------ #\n\n# Straight up copied this section of dark magic from SimpleCookie\n\n_LegalChars = string.ascii_letters + string.digits + \"!#$%&'*+-.^_`|~:\"\n_UnescapedChars = _LegalChars + ' ()/<=>?@[]{}'\n\n_Translator = {n: '\\\\%03o' % n\n               for n in set(range(256)) - set(map(ord, _UnescapedChars))}\n_Translator.update({\n    ord('\"'): '\\\\\"',\n    ord('\\\\'): '\\\\\\\\',\n})\n\n\ndef _quote(str):\n    \"\"\"Quote a string for use in a cookie header.\n    If the string does not need to be double-quoted, then just return the\n    string.  Otherwise, surround the string in doublequotes and quote\n    (with a \\) special characters.\n    \"\"\"\n    if str is None or _is_legal_key(str):\n        return str\n    else:\n        return '\"' + str.translate(_Translator) + '\"'\n\n\n_is_legal_key = re.compile('[%s]+' % re.escape(_LegalChars)).fullmatch\n\n# ------------------------------------------------------------ #\n#  Custom SimpleCookie\n# ------------------------------------------------------------ #\n\n\nclass CookieJar(dict):\n    \"\"\"CookieJar dynamically writes headers as cookies are added and removed\n    It gets around the limitation of one header per name by using the\n    MultiHeader class to provide a unique key that encodes to Set-Cookie.\n    \"\"\"\n\n    def __init__(self, headers):\n        super().__init__()\n        self.headers = headers\n        self.cookie_headers = {}\n\n    def __setitem__(self, key, value):\n        # If this cookie doesn't exist, add it to the header keys\n        cookie_header = self.cookie_headers.get(key)\n        if not cookie_header:\n            cookie = Cookie(key, value)\n            cookie['path'] = '/'\n            cookie_header = MultiHeader(\"Set-Cookie\")\n            self.cookie_headers[key] = cookie_header\n            self.headers[cookie_header] = cookie\n            return super().__setitem__(key, cookie)\n        else:\n            self[key].value = value\n\n    def __delitem__(self, key):\n        if key not in self.cookie_headers:\n            self[key] = ''\n            self[key]['max-age'] = 0\n        else:\n            cookie_header = self.cookie_headers[key]\n            del self.headers[cookie_header]\n            del self.cookie_headers[key]\n            return super().__delitem__(key)\n\n\nclass Cookie(dict):\n    \"\"\"A stripped down version of Morsel from SimpleCookie #gottagofast\"\"\"\n    _keys = {\n        \"expires\": \"expires\",\n        \"path\": \"Path\",\n        \"comment\": \"Comment\",\n        \"domain\": \"Domain\",\n        \"max-age\": \"Max-Age\",\n        \"secure\": \"Secure\",\n        \"httponly\": \"HttpOnly\",\n        \"version\": \"Version\",\n    }\n    _flags = {'secure', 'httponly'}\n\n    def __init__(self, key, value):\n        if key in self._keys:\n            raise KeyError(\"Cookie name is a reserved word\")\n        if not _is_legal_key(key):\n            raise KeyError(\"Cookie key contains illegal characters\")\n        self.key = key\n        self.value = value\n        super().__init__()\n\n    def __setitem__(self, key, value):\n        if key not in self._keys:\n            raise KeyError(\"Unknown cookie property\")\n        return super().__setitem__(key, value)\n\n    def encode(self, encoding):\n        output = ['%s=%s' % (self.key, _quote(self.value))]\n        for key, value in self.items():\n            if key == 'max-age':\n                try:\n                    output.append('%s=%d' % (self._keys[key], value))\n                except TypeError:\n                    output.append('%s=%s' % (self._keys[key], value))\n            elif key == 'expires':\n                try:\n                    output.append('%s=%s' % (\n                        self._keys[key],\n                        value.strftime(\"%a, %d-%b-%Y %T GMT\")\n                    ))\n                except AttributeError:\n                    output.append('%s=%s' % (self._keys[key], value))\n            elif key in self._flags and self[key]:\n                output.append(self._keys[key])\n            else:\n                output.append('%s=%s' % (self._keys[key], value))\n\n        return \"; \".join(output).encode(encoding)\n\n# ------------------------------------------------------------ #\n#  Header Trickery\n# ------------------------------------------------------------ #\n\n\nclass MultiHeader:\n    \"\"\"String-holding object which allow us to set a header within response\n    that has a unique key, but may contain duplicate header names\n    \"\"\"\n    def __init__(self, name):\n        self.name = name\n\n    def encode(self):\n        return self.name.encode()\n", "path": "sanic/cookies.py"}], "after_files": [{"content": "import re\nimport string\n\n# ------------------------------------------------------------ #\n#  SimpleCookie\n# ------------------------------------------------------------ #\n\n# Straight up copied this section of dark magic from SimpleCookie\n\n_LegalChars = string.ascii_letters + string.digits + \"!#$%&'*+-.^_`|~:\"\n_UnescapedChars = _LegalChars + ' ()/<=>?@[]{}'\n\n_Translator = {n: '\\\\%03o' % n\n               for n in set(range(256)) - set(map(ord, _UnescapedChars))}\n_Translator.update({\n    ord('\"'): '\\\\\"',\n    ord('\\\\'): '\\\\\\\\',\n})\n\n\ndef _quote(str):\n    \"\"\"Quote a string for use in a cookie header.\n    If the string does not need to be double-quoted, then just return the\n    string.  Otherwise, surround the string in doublequotes and quote\n    (with a \\) special characters.\n    \"\"\"\n    if str is None or _is_legal_key(str):\n        return str\n    else:\n        return '\"' + str.translate(_Translator) + '\"'\n\n\n_is_legal_key = re.compile('[%s]+' % re.escape(_LegalChars)).fullmatch\n\n# ------------------------------------------------------------ #\n#  Custom SimpleCookie\n# ------------------------------------------------------------ #\n\n\nclass CookieJar(dict):\n    \"\"\"CookieJar dynamically writes headers as cookies are added and removed\n    It gets around the limitation of one header per name by using the\n    MultiHeader class to provide a unique key that encodes to Set-Cookie.\n    \"\"\"\n\n    def __init__(self, headers):\n        super().__init__()\n        self.headers = headers\n        self.cookie_headers = {}\n\n    def __setitem__(self, key, value):\n        # If this cookie doesn't exist, add it to the header keys\n        cookie_header = self.cookie_headers.get(key)\n        if not cookie_header:\n            cookie = Cookie(key, value)\n            cookie['path'] = '/'\n            cookie_header = MultiHeader(\"Set-Cookie\")\n            self.cookie_headers[key] = cookie_header\n            self.headers[cookie_header] = cookie\n            return super().__setitem__(key, cookie)\n        else:\n            self[key].value = value\n\n    def __delitem__(self, key):\n        if key not in self.cookie_headers:\n            self[key] = ''\n            self[key]['max-age'] = 0\n        else:\n            cookie_header = self.cookie_headers[key]\n            del self.headers[cookie_header]\n            del self.cookie_headers[key]\n            return super().__delitem__(key)\n\n\nclass Cookie(dict):\n    \"\"\"A stripped down version of Morsel from SimpleCookie #gottagofast\"\"\"\n    _keys = {\n        \"expires\": \"expires\",\n        \"path\": \"Path\",\n        \"comment\": \"Comment\",\n        \"domain\": \"Domain\",\n        \"max-age\": \"Max-Age\",\n        \"secure\": \"Secure\",\n        \"httponly\": \"HttpOnly\",\n        \"version\": \"Version\",\n    }\n    _flags = {'secure', 'httponly'}\n\n    def __init__(self, key, value):\n        if key in self._keys:\n            raise KeyError(\"Cookie name is a reserved word\")\n        if not _is_legal_key(key):\n            raise KeyError(\"Cookie key contains illegal characters\")\n        self.key = key\n        self.value = value\n        super().__init__()\n\n    def __setitem__(self, key, value):\n        if key not in self._keys:\n            raise KeyError(\"Unknown cookie property\")\n        if value is not False:\n            return super().__setitem__(key, value)\n\n    def encode(self, encoding):\n        output = ['%s=%s' % (self.key, _quote(self.value))]\n        for key, value in self.items():\n            if key == 'max-age':\n                try:\n                    output.append('%s=%d' % (self._keys[key], value))\n                except TypeError:\n                    output.append('%s=%s' % (self._keys[key], value))\n            elif key == 'expires':\n                try:\n                    output.append('%s=%s' % (\n                        self._keys[key],\n                        value.strftime(\"%a, %d-%b-%Y %T GMT\")\n                    ))\n                except AttributeError:\n                    output.append('%s=%s' % (self._keys[key], value))\n            elif key in self._flags and self[key]:\n                output.append(self._keys[key])\n            else:\n                output.append('%s=%s' % (self._keys[key], value))\n\n        return \"; \".join(output).encode(encoding)\n\n# ------------------------------------------------------------ #\n#  Header Trickery\n# ------------------------------------------------------------ #\n\n\nclass MultiHeader:\n    \"\"\"String-holding object which allow us to set a header within response\n    that has a unique key, but may contain duplicate header names\n    \"\"\"\n    def __init__(self, name):\n        self.name = name\n\n    def encode(self):\n        return self.name.encode()\n", "path": "sanic/cookies.py"}]}