Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
abersheeran committed Nov 28, 2023
2 parents 691b8b6 + 2569f5c commit 946e037
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 28 deletions.
2 changes: 1 addition & 1 deletion baize/__version__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
VERSION = (0, 20, 6)
VERSION = (0, 20, 7)

__version__ = ".".join(map(str, VERSION))
10 changes: 9 additions & 1 deletion baize/asgi/staticfiles.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import stat
from typing import Optional

from baize import staticfiles
from baize.datastructures import URL
Expand Down Expand Up @@ -55,7 +56,7 @@ async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
return await self.handle_404(scope, receive, send)


class Pages(staticfiles.BasePages[ASGIApp], Files):
class Pages(Files):
"""
Provide the ASGI application to download files in the specified path or
the specified directory under the specified package.
Expand Down Expand Up @@ -98,3 +99,10 @@ async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
raise HTTPException(404)
else:
return await self.handle_404(scope, receive, send)

def ensure_absolute_path(self, path: str) -> Optional[str]:
abspath = super().ensure_absolute_path(path)
if abspath is not None:
if abspath.endswith("/"):
abspath += "index.html"
return abspath
10 changes: 0 additions & 10 deletions baize/staticfiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,3 @@ def set_response_headers(self, response: BaseResponse) -> None:
"Cache-Control", f"{self.cacheability}, max-age={self.max_age}"
)
response.headers.append("Vary", "Accept-Encoding, User-Agent, Cookie, Referer")


@mypyc_attr(allow_interpreted_subclasses=True)
class BasePages(BaseFiles[Interface], Generic[Interface]):
def ensure_absolute_path(self, path: str) -> Optional[str]:
abspath = super().ensure_absolute_path(path)
if abspath is not None:
if abspath.endswith("/"):
abspath += "index.html"
return abspath
18 changes: 5 additions & 13 deletions baize/wsgi/requests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import json
from itertools import chain
from typing import Any, Dict, Iterator, Mapping, Optional
from urllib.parse import parse_qsl

Expand Down Expand Up @@ -90,19 +89,12 @@ def headers(self) -> Headers:
Note that in its internal storage, all keys are in lower case.
"""
return Headers(
(key.lower().replace("_", "-"), value)
for key, value in chain(
(
(key[5:], value)
for key, value in self._environ.items()
if key.startswith("HTTP_")
),
(
(key, self._environ[key])
for key in ("CONTENT_TYPE", "CONTENT_LENGTH")
if key in self._environ
),
(
(key[5:] if key.startswith("HTTP_") else key).lower().replace("_", "-"),
value,
)
for key, value in self._environ.items()
if key.startswith("HTTP_") or key in ("CONTENT_TYPE", "CONTENT_LENGTH")
)


Expand Down
11 changes: 9 additions & 2 deletions baize/wsgi/staticfiles.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import stat
from typing import Iterable
from typing import Iterable, Optional

from baize import staticfiles
from baize.datastructures import URL
Expand Down Expand Up @@ -53,7 +53,7 @@ def __call__(
return self.handle_404(environ, start_response)


class Pages(staticfiles.BasePages[WSGIApp], Files):
class Pages(Files):
"""
Provide the WSGI application to download files in the specified path or
the specified directory under the specified package.
Expand Down Expand Up @@ -94,3 +94,10 @@ def __call__(
raise HTTPException(404)
else:
return self.handle_404(environ, start_response)

def ensure_absolute_path(self, path: str) -> Optional[str]:
abspath = super().ensure_absolute_path(path)
if abspath is not None:
if abspath.endswith("/"):
abspath += "index.html"
return abspath
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ license = { text = "Apache-2.0" }
name = "baize"
readme = "README.md"
requires-python = ">=3.7"
version = "0.20.6"
version = "0.20.7"

[project.urls]
Homepage = "https://github.com/abersheeran/baize"
Expand Down

0 comments on commit 946e037

Please sign in to comment.