From a8c3f8fc46f8d83fc0318b3e963d8f02388d5d37 Mon Sep 17 00:00:00 2001 From: taoufik07 Date: Tue, 23 Oct 2018 19:52:30 +0100 Subject: [PATCH 1/6] Fix Route.is_function --- responder/api.py | 1 + responder/routes.py | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/responder/api.py b/responder/api.py index 406cb89..e376237 100644 --- a/responder/api.py +++ b/responder/api.py @@ -328,6 +328,7 @@ class API: if default: self.default_endpoint = endpoint + # Can we remove it ? try: if callable(endpoint): endpoint.is_routed = True diff --git a/responder/routes.py b/responder/routes.py index 1183a99..d5b6485 100644 --- a/responder/routes.py +++ b/responder/routes.py @@ -77,8 +77,10 @@ class Route: def is_class_based(self): return hasattr(self.endpoint, "__class__") + @property def is_function(self): + # TODO: Should we remove is_routed ? routed = hasattr(self.endpoint, "is_routed") code = hasattr(self.endpoint, "__code__") kwdefaults = hasattr(self.endpoint, "__kwdefaults__") - return all((routed, code, kwdefaults)) + return all((callable(self.endpoint), code, kwdefaults)) From 880d29c5a937620207f4ded0ec75a5e2f18560ec Mon Sep 17 00:00:00 2001 From: Jayjeet Chakraborty Date: Wed, 24 Oct 2018 02:46:33 +0530 Subject: [PATCH 2/6] Fix Typo in api.py --- responder/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/responder/api.py b/responder/api.py index 1b04783..be99543 100644 --- a/responder/api.py +++ b/responder/api.py @@ -335,7 +335,7 @@ class API: pass self.routes[route] = Route(route, endpoint, websocket=websocket) - # TODO: A better datastructer or sort it once the app is loaded + # TODO: A better data structure or sort it once the app is loaded self.routes = dict( sorted(self.routes.items(), key=lambda item: item[1]._weight()) ) From e50828093d9436d882554ac770e1dfa2b891c448 Mon Sep 17 00:00:00 2001 From: Jayjeet Chakraborty Date: Wed, 24 Oct 2018 02:56:43 +0530 Subject: [PATCH 3/6] Clean print statement --- responder/api.py | 1 - 1 file changed, 1 deletion(-) diff --git a/responder/api.py b/responder/api.py index be99543..cbc5ccb 100644 --- a/responder/api.py +++ b/responder/api.py @@ -201,7 +201,6 @@ class API: return route def _prepare_cookies(self, resp): - # print(resp.cookies) if resp.cookies: header = " ".join([f"{k}={v}" for k, v in resp.cookies.items()]) resp.headers["Set-Cookie"] = header From 29830455edac41e2cdd192f31d9b2e65c89a3323 Mon Sep 17 00:00:00 2001 From: Taoufik Date: Wed, 24 Oct 2018 00:11:27 +0100 Subject: [PATCH 4/6] Typo --- docs/source/tour.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/tour.rst b/docs/source/tour.rst index 2f94d20..1abc640 100644 --- a/docs/source/tour.rst +++ b/docs/source/tour.rst @@ -159,7 +159,7 @@ You can easily read a Request's session data, that can be trusted to have origin **Note**: if you are using this in production, you should pass the ``secret_key`` argument to ``API(...)``:: - api = responder.API(secret_key=os.environ['SECRET_KEY'] + api = responder.API(secret_key=os.environ['SECRET_KEY']) Using Requests Test Client -------------------------- From fe41d4c863888877904ba43ac5722efac8d3de52 Mon Sep 17 00:00:00 2001 From: taoufik07 Date: Wed, 24 Oct 2018 01:17:02 +0100 Subject: [PATCH 5/6] Fix static response --- responder/api.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/responder/api.py b/responder/api.py index 1b04783..9ce0be1 100644 --- a/responder/api.py +++ b/responder/api.py @@ -230,7 +230,6 @@ class API: # Create the response object. cont = False - if route: if not route.uses_websocket: resp = models.Response(req=req, formats=self.formats) @@ -292,7 +291,6 @@ class API: else: resp = models.Response(req=req, formats=self.formats) self.default_response(req, resp, notfound=True) - self.default_response(req, resp) self._prepare_session(resp) @@ -356,6 +354,7 @@ class API: def static_response(self, req, resp): index = (self.static_dir / "index.html").resolve() + resp.content = "" if os.path.exists(index): with open(index, "r") as f: resp.text = f.read() From f69b644a77670f53eec9f51828baefe6b03bba21 Mon Sep 17 00:00:00 2001 From: Frost Ming Date: Wed, 24 Oct 2018 12:28:11 +0800 Subject: [PATCH 6/6] Typo in tour.rst --- docs/source/tour.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/tour.rst b/docs/source/tour.rst index 2f94d20..a757e1d 100644 --- a/docs/source/tour.rst +++ b/docs/source/tour.rst @@ -182,7 +182,7 @@ Here's an example of a test (written with pytest):: resp.text = hello r = api.requests.get(url=api.url_for(some_view)) - assert r.text = hello + assert r.text == hello HSTS (Redirect to HTTPS) ------------------------