internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: falconry/falcon

Issue:
Hoist HTTPStatus into falcon top-level namespace
I.e., add an import line to `falcon/__init__.py`



Discussion:

Resolving patch:
diff --git a/falcon/__init__.py b/falcon/__init__.py
--- a/falcon/__init__.py
+++ b/falcon/__init__.py
@@ -34,6 +34,7 @@
 from falcon.errors import *  # NOQA
 from falcon.redirects import *  # NOQA
 from falcon.http_error import HTTPError  # NOQA
+from falcon.http_status import HTTPStatus  # NOQA
 from falcon.util import *  # NOQA
 from falcon.hooks import before, after  # NOQA
 from falcon.request import Request, RequestOptions  # NOQA


Test patch:
Repository: falconry/falcon

Issue:
Adding HTTP_422, Unprocessable Entity
I guess we need such response support.



Discussion:
I'd like to learn more about how this is used in the wild. Are there other frameworks / guides making use of it outside WebDAV?

That being said, it would be straightforward to add support for this to Falcon (via `status_codes.py` and `errors.py`). If someone would like to submit a PR, I'd be happy to review it.

I don't know of any other frameworks use it or not (I only know Web2py does), But I needed it.  I just add it here cause I think falcon should handle this.

Hey, here is an example of how GitHub uses it...https://developer.github.com/v3/#client-errors

Ah, cool. Thanks @billyshambrook for the example. Someone on IRC just asked about this as well, so it seems like it would be useful to have. Anyone have some bandwidth to work on this?

I can get a pull request out later tonight. Thanks

@billyshambrook still on your track or should I go for it? :)


Resolving patch:
diff --git a/falcon/errors.py b/falcon/errors.py
--- a/falcon/errors.py
+++ b/falcon/errors.py
@@ -306,6 +306,24 @@ def __init__(self, resource_length):
                                                       headers=headers)
 
 
+class HTTPUnprocessableEntity(HTTPError):
+    """422 Unprocessable Entity.
+
+    The request was well-formed but was unable to be followed due to semantic
+    errors. See also: http://www.ietf.org/rfc/rfc4918.
+
+    Args:
+        title (str): Error title (e.g., 'Missing title field').
+        description (str): Human-friendly description of the error, along with
+            a helpful suggestion or two.
+        kwargs (optional): Same as for ``HTTPError``.
+    """
+
+    def __init__(self, title, description, **kwargs):
+        super(HTTPUnprocessableEntity, self).__init__(status.HTTP_422, title,
+                                                      description, **kwargs)
+
+
 class HTTPInternalServerError(HTTPError):
     """500 Internal Server Error.
 
diff --git a/falcon/status_codes.py b/falcon/status_codes.py
--- a/falcon/status_codes.py
+++ b/falcon/status_codes.py
@@ -90,6 +90,8 @@
 HTTP_EXPECTATION_FAILED = HTTP_417
 HTTP_418 = "418 I'm a teapot"
 HTTP_IM_A_TEAPOT = HTTP_418
+HTTP_422 = "422 Unprocessable Entity"
+HTTP_UNPROCESSABLE_ENTITY = HTTP_422
 HTTP_426 = '426 Upgrade Required'
 HTTP_UPGRADE_REQUIRED = HTTP_426
 HTTP_428 = '428 Precondition Required'


Test patch:
diff --git a/tests/test_httperror.py b/tests/test_httperror.py
--- a/tests/test_httperror.py
+++ b/tests/test_httperror.py
@@ -676,5 +676,6 @@ def test_misc(self):
         self._misc_test(falcon.HTTPPreconditionFailed, falcon.HTTP_412)
         self._misc_test(falcon.HTTPUnsupportedMediaType, falcon.HTTP_415,
                         needs_title=False)
+        self._misc_test(falcon.HTTPUnprocessableEntity, falcon.HTTP_422)
         self._misc_test(falcon.HTTPInternalServerError, falcon.HTTP_500)
         self._misc_test(falcon.HTTPBadGateway, falcon.HTTP_502)
Repository: falconry/falcon

Issue:
Request.client_accepts_msgpack only supports 'application/x-msgpack'
The use of the 'x-' prefix is now discouraged for media types. We should update this Request property to also return True for 'application/msgpack', and verify the change with additional tests.



Discussion:

Resolving patch:
diff --git a/falcon/request.py b/falcon/request.py
--- a/falcon/request.py
+++ b/falcon/request.py
@@ -353,7 +353,8 @@ def client_accepts_json(self):
 
     @property
     def client_accepts_msgpack(self):
-        return self.client_accepts('application/x-msgpack')
+        return (self.client_accepts('application/x-msgpack')
+                or self.client_accepts('application/msgpack'))
 
     @property
     def client_accepts_xml(self):


Test patch:
diff --git a/tests/test_req_vars.py b/tests/test_req_vars.py
--- a/tests/test_req_vars.py
+++ b/tests/test_req_vars.py
@@ -348,6 +348,12 @@ def test_client_accepts_props(self):
         self.assertFalse(req.client_accepts_json)
         self.assertTrue(req.client_accepts_msgpack)
 
+        headers = {'Accept': 'application/msgpack'}
+        req = Request(testing.create_environ(headers=headers))
+        self.assertFalse(req.client_accepts_xml)
+        self.assertFalse(req.client_accepts_json)
+        self.assertTrue(req.client_accepts_msgpack)
+
         headers = {
             'Accept': 'application/json,application/xml,application/x-msgpack'
         }
Repository: falconry/falcon

Issue:
Refactor setup.py external module selection for Cython
Reduce complexity and duplication of the external module selection for Cython in setup.py.

At the time of this issue, this cruft was located in: 
https://github.com/kgriffs/falcon/blob/routing/setup.py#L35



Discussion:

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -52,21 +52,15 @@ def list_modules(dirname):
 
         return module_names
 
+    package_names = ['falcon', 'falcon.util', 'falcon.routing']
     ext_modules = [
-        Extension('falcon.' + ext, [path.join('falcon', ext + '.py')])
-        for ext in list_modules(path.join(MYDIR, 'falcon'))]
-
-    ext_modules += [
-        Extension('falcon.util.' + ext,
-                  [path.join('falcon', 'util', ext + '.py')])
-
-        for ext in list_modules(path.join(MYDIR, 'falcon', 'util'))]
-
-    ext_modules += [
-        Extension('falcon.routing.' + ext,
-                  [path.join('falcon', 'routing', ext + '.py')])
-
-        for ext in list_modules(path.join(MYDIR, 'falcon', 'routing'))]
+        Extension(
+            package + '.' + module,
+            [path.join(*(package.split('.') + [module + '.py']))]
+        )
+        for package in package_names
+        for module in list_modules(path.join(MYDIR, *package.split('.')))
+    ]
 
     cmdclass = {'build_ext': build_ext}
 


Test patch:
Repository: falconry/falcon

Issue:
Milddleware process_resource() requires four arguments
Undocumented by http://falcon.readthedocs.org/en/latest/api/middleware.html a middleware component's `process_resource()` method requires a fourth argument which is the `params`.



Discussion:
I think I ran into this issue as well. I tried to get the [more complex example](https://falcon.readthedocs.org/en/stable/user/quickstart.html#more-features) working and encountered the following error on any request:

```
2016-04-16 18:23:44 +0200] [13566] [ERROR] Error handling request /
Traceback (most recent call last):
  File "/Library/Python/2.7/site-packages/gunicorn/workers/sync.py", line 130, in handle
    self.handle_request(listener, req, client, addr)
  File "/Library/Python/2.7/site-packages/gunicorn/workers/sync.py", line 171, in handle_request
    respiter = self.wsgi(environ, resp.start_response)
  File "/Library/Python/2.7/site-packages/falcon/api.py", line 167, in __call__
    self._call_req_mw(middleware_stack, req, resp)
  File "/Library/Python/2.7/site-packages/falcon/api.py", line 535, in _call_req_mw
    process_request(req, resp)
  File "/Users/gigi/Development/newspaper3k-api-using-falcon/more-complex-example.py", line 61, in process_request
    href='http://docs.example.com/auth')
TypeError: __init__() takes exactly 4 arguments (3 given)
```

Any hints on how I might resolve this?

@warsaw Looks like this slipped through the cracks. It was mentioned in the changelog, but the docs didn't get updated to reflect the new param. I'll fix this up pronto. Thanks!

@Gigi33 This looks to be a separate problem with HTTPUnauthorized. Would you mind creating a new issue for this? Might be a breaking change that was not documented, but I'll have to dig into it further to be sure.


Resolving patch:
diff --git a/falcon/api.py b/falcon/api.py
--- a/falcon/api.py
+++ b/falcon/api.py
@@ -50,7 +50,7 @@ def process_request(self, req, resp):
                                 the on_* responder.
                         \"""
 
-                    def process_resource(self, req, resp, resource):
+                    def process_resource(self, req, resp, resource, params):
                         \"""Process the request and resource *after* routing.
 
                         Note:
@@ -65,6 +65,11 @@ def process_resource(self, req, resp, resource):
                             resource: Resource object to which the request was
                                 routed. May be None if no route was found for
                                 the request.
+                            params: A dict-like object representing any
+                                additional params derived from the route's URI
+                                template fields, that will be passed to the
+                                resource's responder method as keyword
+                                arguments.
                         \"""
 
                     def process_response(self, req, resp, resource)


Test patch:
Repository: falconry/falcon

Issue:
Default OPTIONS responder does not set Content-Length to "0"
Per RFC 7231:

> A server MUST generate a Content-Length field with a value of "0" if no payload body is to be sent in the response.



Discussion:
@kgriffs Can you tell me how to reproduce this bug ?

For the script below, I am getting the correct `Content-Length` ie "0".

``` python
import falcon

class ThingsResource(object):
    def on_get(self, req, resp):
        resp.status = falcon.HTTP_200
        resp.body = ('Hello World\n')

app = falcon.API()
app.add_route('/things', ThingsResource)
```

Is there anything I am missing ? ( I am running the latest falcon dev version)

```
$ curl -XOPTIONS -i localhost:8000/things
HTTP/1.0 204 No Content
Date: Thu, 26 May 2016 20:32:55 GMT
Server: WSGIServer/0.1 Python/2.7.9
allow: GET
Content-Length: 0
```

Hi @yashmehrotra, thanks for taking a look! Perhaps the web server is adding that header? The framework isn't adding it per the repo below:

``` py
import falcon
from falcon import testing

class ThingsResource(object):
    def on_get(self, req, resp):
        resp.status = falcon.HTTP_200
        resp.body = ('Hello World\n')

app = falcon.API()
app.add_route('/things', ThingsResource)

env = testing.create_environ('/things', method='OPTIONS')
srmock = testing.StartResponseMock()

app(env, srmock)
print(srmock.headers)
```


Resolving patch:
diff --git a/falcon/responders.py b/falcon/responders.py
--- a/falcon/responders.py
+++ b/falcon/responders.py
@@ -58,5 +58,6 @@ def create_default_options(allowed_methods):
     def on_options(req, resp, **kwargs):
         resp.status = HTTP_204
         resp.set_header('Allow', allowed)
+        resp.set_header('Content-Length', '0')
 
     return on_options


Test patch:
diff --git a/tests/test_headers.py b/tests/test_headers.py
--- a/tests/test_headers.py
+++ b/tests/test_headers.py
@@ -534,6 +534,12 @@ def test_add_link_complex(self):
 
         self._check_link_header(resource, expected_value)
 
+    def test_content_length_options(self):
+        result = self.simulate_options()
+
+        content_length = '0'
+        self.assertEqual(result.headers['Content-Length'], content_length)
+
     # ----------------------------------------------------------------------
     # Helpers
     # ----------------------------------------------------------------------
Repository: falconry/falcon

Issue:
Response href headers are double escaped
#135 makes an attempt to simplify things for developers, but unfortunately it actually breaks well-formed URIs by double escaping them.

I may never have noticed this were I not trying to pass a signed URI where the double escaping broke the signature. Signed S3 URLs that are double escaped definitely don't work!

Of course, the workaround is easy enough — just use `Response.set_header()` directly — I just wanted to flag this as behaviour that was quite surprising and may not be desirable in the long run. 



Discussion:
Hi @natedub, thanks for the report! I'm guessing all the `'%'` characters are being replaced with `'%25'`? urllib behaves in the same way, but that isn't to say Falcon can't be a little bit smarter about this. A fast heuristic would be to include `'%'` in the list of allowed characters. However, that doesn't handle the edge case of a URL containing a percent sign that isn't actually used for escaping. Not sure how common that is...

Possibly related to #687 


Resolving patch:
diff --git a/falcon/response.py b/falcon/response.py
--- a/falcon/response.py
+++ b/falcon/response.py
@@ -474,7 +474,12 @@ def add_link(self, target, rel, title=None, title_star=None,
 
     content_location = header_property(
         'Content-Location',
-        'Sets the Content-Location header.',
+        """Sets the Content-Location header.
+
+        This value will be URI encoded per RFC 3986. If the value that is
+        being set is already URI encoded it should be decoded first or the
+        header should be set manually using the set_header method.
+        """,
         uri_encode)
 
     content_range = header_property(
@@ -516,7 +521,12 @@ def add_link(self, target, rel, title=None, title_star=None,
 
     location = header_property(
         'Location',
-        'Sets the Location header.',
+        """Sets the Location header.
+
+        This value will be URI encoded per RFC 3986. If the value that is
+        being set is already URI encoded it should be decoded first or the
+        header should be set manually using the set_header method.
+        """,
         uri_encode)
 
     retry_after = header_property(


Test patch:
Repository: falconry/falcon

Issue:
Make it easier to add custom attributes to slotted classes 
Users of the framework sometimes want to assign additional variables to the `Request`, `Response`, or other "slotted" classes. This can be allowed without hurting efficiency by adding a `'__dict__'` string to the `__slots__` declarations.

From the Python [data model docs](https://docs.python.org/2/reference/datamodel.html#slots): 

> Without a **dict** variable, instances cannot be assigned new variables not listed in the **slots** definition. Attempts to assign to an unlisted variable name raises AttributeError. If dynamic assignment of new variables is desired, then add '**dict**' to the sequence of strings in the **slots** declaration.

I did a quick test and adding '**dict**' does not decrease performance for accessing the other slotted variables in 2.7 and 3.5. 

Question: Does this enable an anti-pattern? Would we rather that apps use `req.context`? Would it be better to have a context type that supports attribute-based access? (e.g., `req.context.foo` == `req.context['foo']`)?



Discussion:

Resolving patch:
diff --git a/falcon/request.py b/falcon/request.py
--- a/falcon/request.py
+++ b/falcon/request.py
@@ -243,6 +243,7 @@ class Request(object):
         'options',
         '_cookies',
         '_cached_access_route',
+        '__dict__',
     )
 
     # Child classes may override this
diff --git a/falcon/response.py b/falcon/response.py
--- a/falcon/response.py
+++ b/falcon/response.py
@@ -116,6 +116,7 @@ class Response(object):
         'stream',
         'stream_len',
         'context',
+        '__dict__',
     )
 
     # Child classes may override this


Test patch:
diff --git a/tests/test_slots.py b/tests/test_slots.py
new file mode 100644
--- /dev/null
+++ b/tests/test_slots.py
@@ -0,0 +1,22 @@
+from falcon import Request, Response
+import falcon.testing as testing
+
+
+class TestSlots(testing.TestBase):
+
+    def test_slots_request(self):
+        env = testing.create_environ()
+        req = Request(env)
+
+        try:
+            req.doesnt = 'exist'
+        except AttributeError:
+            self.fail('Unable to add additional variables dynamically')
+
+    def test_slots_response(self):
+        resp = Response()
+
+        try:
+            resp.doesnt = 'exist'
+        except AttributeError:
+            self.fail('Unable to add additional variables dynamically')
Repository: falconry/falcon

Issue:
Add support to Response for the Accept-Ranges header
Should be fairly straightforward (see also: https://tools.ietf.org/html/rfc7233#section-2.3)



Discussion:
I will be working on this :) 


Resolving patch:
diff --git a/falcon/response.py b/falcon/response.py
--- a/falcon/response.py
+++ b/falcon/response.py
@@ -625,6 +625,24 @@ def add_link(self, target, rel, title=None, title_star=None,
         """,
         lambda v: ', '.join(v))
 
+    accept_ranges = header_property(
+        'Accept-Ranges',
+        """Sets the Accept-Ranges header.
+
+        The Accept-Ranges header field indicates to the client which
+        range units are supported (e.g. "bytes") for the target
+        resource.
+
+        If range requests are not supported for the target resource,
+        the header may be set to "none" to advise the client not to
+        attempt any such requests.
+
+        Note:
+            "none" is the literal string, not Python's built-in ``None``
+            type.
+
+        """)
+
     def _encode_header(self, name, value, py2=PY2):
         if py2:
             if isinstance(name, unicode):


Test patch:
diff --git a/tests/test_headers.py b/tests/test_headers.py
--- a/tests/test_headers.py
+++ b/tests/test_headers.py
@@ -50,6 +50,8 @@ def on_get(self, req, resp):
         else:
             resp.content_range = (0, 25, 100, req.range_unit)
 
+        resp.accept_ranges = 'bytes'
+
         self.resp = resp
 
     def on_head(self, req, resp):
@@ -322,6 +324,9 @@ def test_response_header_helpers_on_get(self):
         resp.content_range = (1, 499, 10 * 1024, 'bytes')
         self.assertEqual(resp.content_range, 'bytes 1-499/10240')
 
+        self.assertEqual(resp.accept_ranges, 'bytes')
+        self.assertEqual(result.headers['Accept-Ranges'], 'bytes')
+
         req_headers = {'Range': 'items=0-25'}
         result = self.simulate_get(headers=req_headers)
         self.assertEqual(result.headers['Content-Range'], 'items 0-25/100')
Repository: falconry/falcon

Issue:
Add additional values on get_param_as_bool like ON, OFF
Hello,

How about add to get_param_as_bool values 

TRUE_STRINGS = [ ... , "on" ]
FALSE_STRINGS = [..., "off" ]

This is related to default value in checkbox on Internet Explorer.

Thanx.



Discussion:
How about '1'/'0' ?

'1' and '0' have been implemented. We can add 'on' and 'off' as well, no problem. Thanks for the suggestion!


Resolving patch:
diff --git a/falcon/request.py b/falcon/request.py
--- a/falcon/request.py
+++ b/falcon/request.py
@@ -46,8 +46,8 @@
 DEFAULT_ERROR_LOG_FORMAT = (u'{0:%Y-%m-%d %H:%M:%S} [FALCON] [ERROR]'
                             u' {1} {2}{3} => ')
 
-TRUE_STRINGS = ('true', 'True', 'yes', '1')
-FALSE_STRINGS = ('false', 'False', 'no', '0')
+TRUE_STRINGS = ('true', 'True', 'yes', '1', 'on')
+FALSE_STRINGS = ('false', 'False', 'no', '0', 'off')
 WSGI_CONTENT_HEADERS = ('CONTENT_TYPE', 'CONTENT_LENGTH')
 
 # PERF(kgriffs): Avoid an extra namespace lookup when using these functions
@@ -948,8 +948,8 @@ def get_param_as_bool(self, name, required=False, store=None,
 
         The following boolean strings are supported::
 
-            TRUE_STRINGS = ('true', 'True', 'yes', '1')
-            FALSE_STRINGS = ('false', 'False', 'no', '0')
+            TRUE_STRINGS = ('true', 'True', 'yes', '1', 'on')
+            FALSE_STRINGS = ('false', 'False', 'no', '0', 'off')
 
         Args:
             name (str): Parameter name, case-sensitive (e.g., 'detailed').


Test patch:
diff --git a/tests/test_query_params.py b/tests/test_query_params.py
--- a/tests/test_query_params.py
+++ b/tests/test_query_params.py
@@ -257,7 +257,8 @@ def test_int_neg(self):
 
     def test_boolean(self):
         query_string = ('echo=true&doit=false&bogus=bar&bogus2=foo&'
-                        't1=True&f1=False&t2=yes&f2=no&blank&one=1&zero=0')
+                        't1=True&f1=False&t2=yes&f2=no&blank&one=1&zero=0&'
+                        'checkbox1=on&checkbox2=off')
         self.simulate_request('/', query_string=query_string)
 
         req = self.resource.captured_req
@@ -285,6 +286,9 @@ def test_boolean(self):
         self.assertEqual(req.get_param_as_bool('zero'), False)
         self.assertEqual(req.get_param('blank'), None)
 
+        self.assertEqual(req.get_param_as_bool('checkbox1'), True)
+        self.assertEqual(req.get_param_as_bool('checkbox2'), False)
+
         store = {}
         self.assertEqual(req.get_param_as_bool('echo', store=store), True)
         self.assertEqual(store['echo'], True)
Repository: falconry/falcon

Issue:
Doc site: On small screen height, sidebar ("Navigation") clips at bottom.
Using a laptop with 768 pixels height resolution.
![sidebar_clip](https://cloud.githubusercontent.com/assets/13870149/21928904/8a6fef78-d9b3-11e6-847f-af666a42c113.png)



Discussion:

Resolving patch:
diff --git a/docs/conf.py b/docs/conf.py
--- a/docs/conf.py
+++ b/docs/conf.py
@@ -152,7 +152,7 @@
     'github_repo': 'falcon',
     'github_button': False,
     'github_banner': True,
-    'fixed_sidebar': True,
+    'fixed_sidebar': False,
     'show_powered_by': False,
     'extra_nav_links': {
       'Falcon Home': 'http://falconframework.org/',


Test patch:
Repository: falconry/falcon

Issue:
Drop support for Python 3.3



Discussion:

Resolving patch:
diff --git a/falcon/media/msgpack.py b/falcon/media/msgpack.py
--- a/falcon/media/msgpack.py
+++ b/falcon/media/msgpack.py
@@ -19,9 +19,6 @@ class MessagePackHandler(BaseHandler):
         .. code::
 
             $ pip install msgpack
-
-        Python 2.6 users will need to use the deprecated ``msgpack-python``
-        package instead, pinned to version 0.4.8.
     """
 
     def __init__(self):
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -107,8 +107,9 @@ def load_description():
         'Programming Language :: Python',
         'Programming Language :: Python :: Implementation :: CPython',
         'Programming Language :: Python :: Implementation :: PyPy',
+        'Programming Language :: Python :: 2',
         'Programming Language :: Python :: 2.7',
-        'Programming Language :: Python :: 3.3',
+        'Programming Language :: Python :: 3',
         'Programming Language :: Python :: 3.4',
         'Programming Language :: Python :: 3.5',
         'Programming Language :: Python :: 3.6',
@@ -121,7 +122,7 @@ def load_description():
     packages=find_packages(exclude=['tests']),
     include_package_data=True,
     zip_safe=False,
-    python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*',
+    python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*',
     install_requires=REQUIRES,
     cmdclass=cmdclass,
     ext_modules=ext_modules,


Test patch:
diff --git a/requirements/tests b/requirements/tests
new file mode 100644
--- /dev/null
+++ b/requirements/tests
@@ -0,0 +1,10 @@
+coverage>=4.1
+pytest
+pyyaml
+requests
+six
+testtools
+
+# Handler Specific
+msgpack
+