Merge branch 'master' into fix/cbv

This commit is contained in:
2018-10-24 06:57:28 -04:00
committed by GitHub
3 changed files with 8 additions and 8 deletions
+2 -2
View File
@@ -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
--------------------------
@@ -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)
------------------------
+3 -4
View File
@@ -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
@@ -230,7 +229,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 +290,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)
@@ -328,6 +325,7 @@ class API:
if default:
self.default_endpoint = endpoint
# Can we remove it ?
try:
if callable(endpoint):
endpoint.is_routed = True
@@ -335,7 +333,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())
)
@@ -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()
+3 -2
View File
@@ -72,9 +72,10 @@ class Route:
@property
def is_class_based(self):
return hasattr(self.endpoint, "__class__")
@property
@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__")