mirror of
https://github.com/simonw/datasette.git
synced 2025-12-10 16:51:24 +01:00
Modernize code to Python 3.6+ (#1158)
* Compact dict and set building * Remove redundant parentheses * Simplify chained conditions * Change method name to lowercase * Use triple double quotes for docstrings Thanks, @eumiro!
This commit is contained in:
parent
90eba4c3ca
commit
a882d67962
19 changed files with 76 additions and 82 deletions
|
|
@ -59,12 +59,10 @@ class Request:
|
|||
|
||||
@property
|
||||
def headers(self):
|
||||
return dict(
|
||||
[
|
||||
(k.decode("latin-1").lower(), v.decode("latin-1"))
|
||||
for k, v in self.scope.get("headers") or []
|
||||
]
|
||||
)
|
||||
return {
|
||||
k.decode("latin-1").lower(): v.decode("latin-1")
|
||||
for k, v in self.scope.get("headers") or []
|
||||
}
|
||||
|
||||
@property
|
||||
def host(self):
|
||||
|
|
@ -115,7 +113,7 @@ class Request:
|
|||
|
||||
@classmethod
|
||||
def fake(cls, path_with_query_string, method="GET", scheme="http"):
|
||||
"Useful for constructing Request objects for tests"
|
||||
"""Useful for constructing Request objects for tests"""
|
||||
path, _, query_string = path_with_query_string.partition("?")
|
||||
scope = {
|
||||
"http_version": "1.1",
|
||||
|
|
@ -167,9 +165,7 @@ class AsgiStream:
|
|||
|
||||
async def asgi_send(self, send):
|
||||
# Remove any existing content-type header
|
||||
headers = dict(
|
||||
[(k, v) for k, v in self.headers.items() if k.lower() != "content-type"]
|
||||
)
|
||||
headers = {k: v for k, v in self.headers.items() if k.lower() != "content-type"}
|
||||
headers["content-type"] = self.content_type
|
||||
await send(
|
||||
{
|
||||
|
|
@ -240,7 +236,7 @@ async def asgi_send(send, content, status, headers=None, content_type="text/plai
|
|||
async def asgi_start(send, status, headers=None, content_type="text/plain"):
|
||||
headers = headers or {}
|
||||
# Remove any existing content-type header
|
||||
headers = dict([(k, v) for k, v in headers.items() if k.lower() != "content-type"])
|
||||
headers = {k: v for k, v in headers.items() if k.lower() != "content-type"}
|
||||
headers["content-type"] = content_type
|
||||
await send(
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue