Skip to content

Commit

Permalink
Merge branch 'master' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
gi0baro committed May 19, 2023
2 parents 197fdd0 + 1737188 commit 0856517
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion emmett/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "2.5.1"
__version__ = "2.5.2"
8 changes: 5 additions & 3 deletions emmett/asgi/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,13 +250,15 @@ def _static_lang_matcher(
def _static_nolang_matcher(
self, path: str
) -> Tuple[Optional[str], Optional[str]]:
if path.startswith('/static'):
if path.startswith('/static/'):
mname, version, file_name = REGEX_STATIC.match(path).group('m', 'v', 'f')
if mname:
mod = self.app._modules.get(mname[2:-3])
static_file = os.path.join(mod._static_path, file_name) if mod else None
else:
elif file_name:
static_file = os.path.join(self.app.static_path, file_name)
else:
static_file = None
return static_file, version
return None, None

Expand Down Expand Up @@ -288,7 +290,7 @@ def _static_handler(
#: handle internal assets
if path.startswith('/__emmett__'):
file_name = path[12:]
if file_name.endswith(".html"):
if not file_name or file_name.endswith(".html"):
return self._http_response(404)
pkg = None
if '/' in file_name:
Expand Down
6 changes: 3 additions & 3 deletions emmett/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,12 +244,12 @@ def rsgi(self, protocol: HTTPProtocol):
try:
stat_data = os.stat(self.file_path)
if not stat.S_ISREG(stat_data.st_mode):
return HTTP(403).rsgi()
return HTTP(403).rsgi(protocol)
self._headers.update(self._get_stat_headers(stat_data))
except IOError as e:
if e.errno == errno.EACCES:
return HTTP(403).rsgi()
return HTTP(404).rsgi()
return HTTP(403).rsgi(protocol)
return HTTP(404).rsgi(protocol)

protocol.response_file(
self.status_code,
Expand Down
11 changes: 8 additions & 3 deletions emmett/rsgi/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,15 @@ def _static_lang_matcher(
def _static_nolang_matcher(
self, path: str
) -> Tuple[Optional[str], Optional[str]]:
if path.startswith('/static'):
if path.startswith('/static/'):
mname, version, file_name = REGEX_STATIC.match(path).group('m', 'v', 'f')
if mname:
mod = self.app._modules.get(mname[2:-3])
static_file = os.path.join(mod._static_path, file_name) if mod else None
else:
elif file_name:
static_file = os.path.join(self.app.static_path, file_name)
else:
static_file = None
return static_file, version
return None, None

Expand All @@ -166,8 +168,11 @@ def _static_handler(
#: handle internal assets
if path.startswith('/__emmett__'):
file_name = path[12:]
if not file_name:
return self._http_response(404)
static_file = os.path.join(
os.path.dirname(__file__), '..', 'assets', file_name)
os.path.dirname(__file__), '..', 'assets', file_name
)
if os.path.splitext(static_file)[1] == 'html':
return self._http_response(404)
return self._static_response(static_file)
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "emmett"
version = "2.5.1"
version = "2.5.2"
description = "The web framework for inventors"
authors = ["Giovanni Barillari <[email protected]>"]
license = "BSD-3-Clause"
Expand Down Expand Up @@ -43,7 +43,7 @@ emmett = "emmett.cli:main"
[tool.poetry.dependencies]
python = "^3.8"
click = ">=6.0"
granian = "~0.4.0"
granian = "~0.4.2"
emmett-crypto = "~0.3"
pendulum = "~2.1.2"
pyDAL = "17.3"
Expand Down

0 comments on commit 0856517

Please sign in to comment.