We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
test: Add Unicode chars to logging test


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `falcon/request.py`
Content:
```
1 """Defines the Request class.
2 
3 Copyright 2013 by Rackspace Hosting, Inc.
4 
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8 
9    http://www.apache.org/licenses/LICENSE-2.0
10 
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
16 
17 """
18 
19 import sys
20 from datetime import datetime
21 
22 from falcon.request_helpers import *
23 from falcon.exceptions import *
24 import six
25 
26 
27 class Request(object):
28     """Represents a client's HTTP request"""
29 
30     __slots__ = (
31         'app',
32         'body',
33         '_headers',
34         'method',
35         '_params',
36         'path',
37         'protocol',
38         'query_string',
39         '_wsgierrors'
40     )
41 
42     def __init__(self, env):
43         """Initialize attributes based on a WSGI environment dict
44 
45         Note: Request is not meant to be instantiated directory by responders.
46 
47         Args:
48             env: A WSGI environment dict passed in from the server. See also
49                 the PEP-333 spec.
50 
51         """
52 
53         self.app = env['SCRIPT_NAME']
54         self.body = env['wsgi.input']
55         self.method = env['REQUEST_METHOD']
56         self.path = env['PATH_INFO'] or '/'
57         self.protocol = env['wsgi.url_scheme']
58         self.query_string = query_string = env['QUERY_STRING']
59         self._params = parse_query_string(query_string)
60         self._headers = parse_headers(env)
61         self._wsgierrors = env['wsgi.errors']
62 
63     def log_error(self, message):
64         """Log an error to wsgi.error
65 
66         Prepends timestamp and request info to message, and writes the result
67         out to the WSGI server's error stream (wsgi.error).
68 
69         Args:
70             message: A string describing the problem. If a byte-string and
71                 running under Python 2, the string is assumed to be encoded
72                 as UTF-8.
73 
74         """
75         u = six.text_type
76         log_line = (
77             u('{0:%Y-%m-%d %H:%M:%S} [FALCON] [ERROR] {1} {2}?{3} => {4}\n').
78             format(datetime.now(), self.method, self.path, self.query_string,
79                    message)
80         )
81 
82         self._wsgierrors.write(log_line)
83 
84     def client_accepts_json(self):
85         """Return True if the Accept header indicates JSON support"""
86 
87         accept = self.get_header('Accept')
88         if accept is not None:
89             return ('application/json' in accept) or ('*/*' in accept)
90 
91         return False
92 
93     def get_header(self, name, default=None, required=False):
94         """Return a header value as a string
95 
96         Args:
97             name: Header name, case-insensitive (e.g., 'Content-Type')
98             default: Value to return in case the header is not
99               found (default None)
100             required: Set to True to raise HttpBadRequest instead
101               of returning gracefully when the header is not found
102               (default False)
103 
104         """
105 
106         # Use try..except to optimize for the header existing in most cases
107         try:
108             # Don't take the time to cache beforehand, using HTTP naming.
109             # This will be faster, assuming that most headers are looked
110             # up only once, and not all headers will be requested.
111             return self._headers[name.upper().replace('-', '_')]
112         except KeyError:
113             if not required:
114                 return default
115 
116             raise HTTPBadRequest('Missing header',
117                                  'The "' + name + '" header is required.')
118 
119     def get_param(self, name, default=None, required=False):
120         """Return the value of a query string parameter as a string
121 
122         Args:
123             name: Parameter name, case-sensitive (e.g., 'sort')
124             default: Value to return in case the parameter is not found in the
125                 query string (default None)
126             required: Set to True to raise HTTPBadRequest instead of returning
127                 gracefully when the parameter is not found (default False)
128 
129         Returns:
130             The value of the param as a byte string, or the default value if
131             param is not found and is not required.
132 
133         Raises
134             HTTPBadRequest: The param was not found in the request, but was
135                 required.
136 
137         """
138 
139         # PERF: Use if..in since it is a good all-around performer; we don't
140         #       know how likely params are to be specified by clients.
141         if name in self._params:
142             return self._params[name]
143 
144         if not required:
145             return default
146 
147         raise HTTPBadRequest('Missing query parameter',
148                              'The "' + name + '" query parameter is required.')
149 
150     def get_param_as_int(self, name, default=None, required=False):
151         """Return the value of a query string parameter as an int
152 
153         Args:
154             name: Parameter name, case-sensitive (e.g., 'limit')
155             default: Value to return in case the parameter is not found in the
156                 query string, or it is not an integer (default None)
157             required: Set to True to raise HTTPBadRequest instead of returning
158                 gracefully when the parameter is not found or is not an
159                 integer (default False)
160 
161         Returns:
162             The value of the param if it is found and can be converted to an
163             integer. Otherwise, returns the default value unless required is
164             True.
165 
166         Raises
167             HTTPBadRequest: The param was not found in the request, but was
168                 required.
169 
170         """
171 
172         # PERF: Use if..in since it is a good all-around performer; we don't
173         #       know how likely params are to be specified by clients.
174         if name in self._params:
175             val = self._params[name]
176             try:
177                 return int(val)
178             except ValueError:
179                 pass
180 
181         if not required:
182             return default
183 
184         raise HTTPBadRequest('Missing query parameter',
185                              'The "' + name + '" query parameter is required.')
186
```
--- 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/falcon/request.py b/falcon/request.py
--- a/falcon/request.py
+++ b/falcon/request.py
@@ -16,12 +16,15 @@
 
 """
 
-import sys
 from datetime import datetime
 
+import six
+
 from falcon.request_helpers import *
 from falcon.exceptions import *
-import six
+
+DEFAULT_ERROR_LOG_FORMAT = ('{0:%Y-%m-%d %H:%M:%S} [FALCON] [ERROR]'
+                            ' {1} {2}?{3} => {4}\n')
 
 
 class Request(object):
@@ -50,21 +53,23 @@
 
         """
 
-        self.app = env['SCRIPT_NAME']
+        self._wsgierrors = env['wsgi.errors']
         self.body = env['wsgi.input']
+
+        self.protocol = env['wsgi.url_scheme']
+        self.app = env['SCRIPT_NAME']
         self.method = env['REQUEST_METHOD']
         self.path = env['PATH_INFO'] or '/'
-        self.protocol = env['wsgi.url_scheme']
         self.query_string = query_string = env['QUERY_STRING']
+
         self._params = parse_query_string(query_string)
         self._headers = parse_headers(env)
-        self._wsgierrors = env['wsgi.errors']
 
     def log_error(self, message):
         """Log an error to wsgi.error
 
-        Prepends timestamp and request info to message, and writes the result
-        out to the WSGI server's error stream (wsgi.error).
+        Prepends timestamp and request info to message, and writes the
+        result out to the WSGI server's error stream (wsgi.error).
 
         Args:
             message: A string describing the problem. If a byte-string and
@@ -72,11 +77,13 @@
                 as UTF-8.
 
         """
-        u = six.text_type
+        if not six.PY3 and isinstance(message, unicode):
+            message = message.encode('utf-8')
+
         log_line = (
-            u('{0:%Y-%m-%d %H:%M:%S} [FALCON] [ERROR] {1} {2}?{3} => {4}\n').
-            format(datetime.now(), self.method, self.path, self.query_string,
-                   message)
+            DEFAULT_ERROR_LOG_FORMAT.
+            format(datetime.now(), self.method, self.path,
+                   self.query_string, message)
         )
 
         self._wsgierrors.write(log_line)

{"golden_diff": "diff --git a/falcon/request.py b/falcon/request.py\n--- a/falcon/request.py\n+++ b/falcon/request.py\n@@ -16,12 +16,15 @@\n \n \"\"\"\n \n-import sys\n from datetime import datetime\n \n+import six\n+\n from falcon.request_helpers import *\n from falcon.exceptions import *\n-import six\n+\n+DEFAULT_ERROR_LOG_FORMAT = ('{0:%Y-%m-%d %H:%M:%S} [FALCON] [ERROR]'\n+                            ' {1} {2}?{3} => {4}\\n')\n \n \n class Request(object):\n@@ -50,21 +53,23 @@\n \n         \"\"\"\n \n-        self.app = env['SCRIPT_NAME']\n+        self._wsgierrors = env['wsgi.errors']\n         self.body = env['wsgi.input']\n+\n+        self.protocol = env['wsgi.url_scheme']\n+        self.app = env['SCRIPT_NAME']\n         self.method = env['REQUEST_METHOD']\n         self.path = env['PATH_INFO'] or '/'\n-        self.protocol = env['wsgi.url_scheme']\n         self.query_string = query_string = env['QUERY_STRING']\n+\n         self._params = parse_query_string(query_string)\n         self._headers = parse_headers(env)\n-        self._wsgierrors = env['wsgi.errors']\n \n     def log_error(self, message):\n         \"\"\"Log an error to wsgi.error\n \n-        Prepends timestamp and request info to message, and writes the result\n-        out to the WSGI server's error stream (wsgi.error).\n+        Prepends timestamp and request info to message, and writes the\n+        result out to the WSGI server's error stream (wsgi.error).\n \n         Args:\n             message: A string describing the problem. If a byte-string and\n@@ -72,11 +77,13 @@\n                 as UTF-8.\n \n         \"\"\"\n-        u = six.text_type\n+        if not six.PY3 and isinstance(message, unicode):\n+            message = message.encode('utf-8')\n+\n         log_line = (\n-            u('{0:%Y-%m-%d %H:%M:%S} [FALCON] [ERROR] {1} {2}?{3} => {4}\\n').\n-            format(datetime.now(), self.method, self.path, self.query_string,\n-                   message)\n+            DEFAULT_ERROR_LOG_FORMAT.\n+            format(datetime.now(), self.method, self.path,\n+                   self.query_string, message)\n         )\n \n         self._wsgierrors.write(log_line)\n", "issue": "test: Add Unicode chars to logging test\n\n", "before_files": [{"content": "\"\"\"Defines the Request class.\n\nCopyright 2013 by Rackspace Hosting, Inc.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n   http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n\n\"\"\"\n\nimport sys\nfrom datetime import datetime\n\nfrom falcon.request_helpers import *\nfrom falcon.exceptions import *\nimport six\n\n\nclass Request(object):\n    \"\"\"Represents a client's HTTP request\"\"\"\n\n    __slots__ = (\n        'app',\n        'body',\n        '_headers',\n        'method',\n        '_params',\n        'path',\n        'protocol',\n        'query_string',\n        '_wsgierrors'\n    )\n\n    def __init__(self, env):\n        \"\"\"Initialize attributes based on a WSGI environment dict\n\n        Note: Request is not meant to be instantiated directory by responders.\n\n        Args:\n            env: A WSGI environment dict passed in from the server. See also\n                the PEP-333 spec.\n\n        \"\"\"\n\n        self.app = env['SCRIPT_NAME']\n        self.body = env['wsgi.input']\n        self.method = env['REQUEST_METHOD']\n        self.path = env['PATH_INFO'] or '/'\n        self.protocol = env['wsgi.url_scheme']\n        self.query_string = query_string = env['QUERY_STRING']\n        self._params = parse_query_string(query_string)\n        self._headers = parse_headers(env)\n        self._wsgierrors = env['wsgi.errors']\n\n    def log_error(self, message):\n        \"\"\"Log an error to wsgi.error\n\n        Prepends timestamp and request info to message, and writes the result\n        out to the WSGI server's error stream (wsgi.error).\n\n        Args:\n            message: A string describing the problem. If a byte-string and\n                running under Python 2, the string is assumed to be encoded\n                as UTF-8.\n\n        \"\"\"\n        u = six.text_type\n        log_line = (\n            u('{0:%Y-%m-%d %H:%M:%S} [FALCON] [ERROR] {1} {2}?{3} => {4}\\n').\n            format(datetime.now(), self.method, self.path, self.query_string,\n                   message)\n        )\n\n        self._wsgierrors.write(log_line)\n\n    def client_accepts_json(self):\n        \"\"\"Return True if the Accept header indicates JSON support\"\"\"\n\n        accept = self.get_header('Accept')\n        if accept is not None:\n            return ('application/json' in accept) or ('*/*' in accept)\n\n        return False\n\n    def get_header(self, name, default=None, required=False):\n        \"\"\"Return a header value as a string\n\n        Args:\n            name: Header name, case-insensitive (e.g., 'Content-Type')\n            default: Value to return in case the header is not\n              found (default None)\n            required: Set to True to raise HttpBadRequest instead\n              of returning gracefully when the header is not found\n              (default False)\n\n        \"\"\"\n\n        # Use try..except to optimize for the header existing in most cases\n        try:\n            # Don't take the time to cache beforehand, using HTTP naming.\n            # This will be faster, assuming that most headers are looked\n            # up only once, and not all headers will be requested.\n            return self._headers[name.upper().replace('-', '_')]\n        except KeyError:\n            if not required:\n                return default\n\n            raise HTTPBadRequest('Missing header',\n                                 'The \"' + name + '\" header is required.')\n\n    def get_param(self, name, default=None, required=False):\n        \"\"\"Return the value of a query string parameter as a string\n\n        Args:\n            name: Parameter name, case-sensitive (e.g., 'sort')\n            default: Value to return in case the parameter is not found in the\n                query string (default None)\n            required: Set to True to raise HTTPBadRequest instead of returning\n                gracefully when the parameter is not found (default False)\n\n        Returns:\n            The value of the param as a byte string, or the default value if\n            param is not found and is not required.\n\n        Raises\n            HTTPBadRequest: The param was not found in the request, but was\n                required.\n\n        \"\"\"\n\n        # PERF: Use if..in since it is a good all-around performer; we don't\n        #       know how likely params are to be specified by clients.\n        if name in self._params:\n            return self._params[name]\n\n        if not required:\n            return default\n\n        raise HTTPBadRequest('Missing query parameter',\n                             'The \"' + name + '\" query parameter is required.')\n\n    def get_param_as_int(self, name, default=None, required=False):\n        \"\"\"Return the value of a query string parameter as an int\n\n        Args:\n            name: Parameter name, case-sensitive (e.g., 'limit')\n            default: Value to return in case the parameter is not found in the\n                query string, or it is not an integer (default None)\n            required: Set to True to raise HTTPBadRequest instead of returning\n                gracefully when the parameter is not found or is not an\n                integer (default False)\n\n        Returns:\n            The value of the param if it is found and can be converted to an\n            integer. Otherwise, returns the default value unless required is\n            True.\n\n        Raises\n            HTTPBadRequest: The param was not found in the request, but was\n                required.\n\n        \"\"\"\n\n        # PERF: Use if..in since it is a good all-around performer; we don't\n        #       know how likely params are to be specified by clients.\n        if name in self._params:\n            val = self._params[name]\n            try:\n                return int(val)\n            except ValueError:\n                pass\n\n        if not required:\n            return default\n\n        raise HTTPBadRequest('Missing query parameter',\n                             'The \"' + name + '\" query parameter is required.')\n", "path": "falcon/request.py"}], "after_files": [{"content": "\"\"\"Defines the Request class.\n\nCopyright 2013 by Rackspace Hosting, Inc.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n   http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n\n\"\"\"\n\nfrom datetime import datetime\n\nimport six\n\nfrom falcon.request_helpers import *\nfrom falcon.exceptions import *\n\nDEFAULT_ERROR_LOG_FORMAT = ('{0:%Y-%m-%d %H:%M:%S} [FALCON] [ERROR]'\n                            ' {1} {2}?{3} => {4}\\n')\n\n\nclass Request(object):\n    \"\"\"Represents a client's HTTP request\"\"\"\n\n    __slots__ = (\n        'app',\n        'body',\n        '_headers',\n        'method',\n        '_params',\n        'path',\n        'protocol',\n        'query_string',\n        '_wsgierrors'\n    )\n\n    def __init__(self, env):\n        \"\"\"Initialize attributes based on a WSGI environment dict\n\n        Note: Request is not meant to be instantiated directory by responders.\n\n        Args:\n            env: A WSGI environment dict passed in from the server. See also\n                the PEP-333 spec.\n\n        \"\"\"\n\n        self._wsgierrors = env['wsgi.errors']\n        self.body = env['wsgi.input']\n\n        self.protocol = env['wsgi.url_scheme']\n        self.app = env['SCRIPT_NAME']\n        self.method = env['REQUEST_METHOD']\n        self.path = env['PATH_INFO'] or '/'\n        self.query_string = query_string = env['QUERY_STRING']\n\n        self._params = parse_query_string(query_string)\n        self._headers = parse_headers(env)\n\n    def log_error(self, message):\n        \"\"\"Log an error to wsgi.error\n\n        Prepends timestamp and request info to message, and writes the\n        result out to the WSGI server's error stream (wsgi.error).\n\n        Args:\n            message: A string describing the problem. If a byte-string and\n                running under Python 2, the string is assumed to be encoded\n                as UTF-8.\n\n        \"\"\"\n        if not six.PY3 and isinstance(message, unicode):\n            message = message.encode('utf-8')\n\n        log_line = (\n            DEFAULT_ERROR_LOG_FORMAT.\n            format(datetime.now(), self.method, self.path,\n                   self.query_string, message)\n        )\n\n        self._wsgierrors.write(log_line)\n\n    def client_accepts_json(self):\n        \"\"\"Return True if the Accept header indicates JSON support\"\"\"\n\n        accept = self.get_header('Accept')\n        if accept is not None:\n            return ('application/json' in accept) or ('*/*' in accept)\n\n        return False\n\n    def get_header(self, name, default=None, required=False):\n        \"\"\"Return a header value as a string\n\n        Args:\n            name: Header name, case-insensitive (e.g., 'Content-Type')\n            default: Value to return in case the header is not\n              found (default None)\n            required: Set to True to raise HttpBadRequest instead\n              of returning gracefully when the header is not found\n              (default False)\n\n        \"\"\"\n\n        # Use try..except to optimize for the header existing in most cases\n        try:\n            # Don't take the time to cache beforehand, using HTTP naming.\n            # This will be faster, assuming that most headers are looked\n            # up only once, and not all headers will be requested.\n            return self._headers[name.upper().replace('-', '_')]\n        except KeyError:\n            if not required:\n                return default\n\n            raise HTTPBadRequest('Missing header',\n                                 'The \"' + name + '\" header is required.')\n\n    def get_param(self, name, default=None, required=False):\n        \"\"\"Return the value of a query string parameter as a string\n\n        Args:\n            name: Parameter name, case-sensitive (e.g., 'sort')\n            default: Value to return in case the parameter is not found in the\n                query string (default None)\n            required: Set to True to raise HTTPBadRequest instead of returning\n                gracefully when the parameter is not found (default False)\n\n        Returns:\n            The value of the param as a byte string, or the default value if\n            param is not found and is not required.\n\n        Raises\n            HTTPBadRequest: The param was not found in the request, but was\n                required.\n\n        \"\"\"\n\n        # PERF: Use if..in since it is a good all-around performer; we don't\n        #       know how likely params are to be specified by clients.\n        if name in self._params:\n            return self._params[name]\n\n        if not required:\n            return default\n\n        raise HTTPBadRequest('Missing query parameter',\n                             'The \"' + name + '\" query parameter is required.')\n\n    def get_param_as_int(self, name, default=None, required=False):\n        \"\"\"Return the value of a query string parameter as an int\n\n        Args:\n            name: Parameter name, case-sensitive (e.g., 'limit')\n            default: Value to return in case the parameter is not found in the\n                query string, or it is not an integer (default None)\n            required: Set to True to raise HTTPBadRequest instead of returning\n                gracefully when the parameter is not found or is not an\n                integer (default False)\n\n        Returns:\n            The value of the param if it is found and can be converted to an\n            integer. Otherwise, returns the default value unless required is\n            True.\n\n        Raises\n            HTTPBadRequest: The param was not found in the request, but was\n                required.\n\n        \"\"\"\n\n        # PERF: Use if..in since it is a good all-around performer; we don't\n        #       know how likely params are to be specified by clients.\n        if name in self._params:\n            val = self._params[name]\n            try:\n                return int(val)\n            except ValueError:\n                pass\n\n        if not required:\n            return default\n\n        raise HTTPBadRequest('Missing query parameter',\n                             'The \"' + name + '\" query parameter is required.')\n", "path": "falcon/request.py"}]}