diff --git a/tool/hoardy_web/mitmproxy.py b/tool/hoardy_web/mitmproxy.py index 9ca39e9..1fb289a 100644 --- a/tool/hoardy_web/mitmproxy.py +++ b/tool/hoardy_web/mitmproxy.py @@ -16,6 +16,7 @@ # along with this program. If not, see . import io as _io +import os as _os import struct as _struct import typing as _t @@ -128,4 +129,5 @@ def rrexprs_mitmproxy_load_fileobj(fobj : _io.BufferedReader, source : DeferredS def rrexprs_mitmproxy_loadf(path : str | bytes) -> _t.Iterator[ReqresExpr[StreamElementSource[FileSource]]]: with open(path, "rb") as f: - yield from rrexprs_mitmproxy_load_fileobj(f, make_FileSource(path, f)) + in_stat = _os.fstat(f.fileno()) + yield from rrexprs_mitmproxy_load_fileobj(f, make_FileSource(path, in_stat)) diff --git a/tool/hoardy_web/source.py b/tool/hoardy_web/source.py index 0709c75..bd5c019 100644 --- a/tool/hoardy_web/source.py +++ b/tool/hoardy_web/source.py @@ -122,9 +122,7 @@ def replaces(self, other : DeferredSource) -> bool: return False return True -def make_FileSource(path : str | bytes, fobj : _io.BufferedReader, in_stat : _os.stat_result | None = None) -> FileSource: - if in_stat is None: - in_stat = _os.fstat(fobj.fileno()) +def make_FileSource(path : str | bytes, in_stat : _os.stat_result) -> FileSource: return FileSource(path, in_stat.st_mtime_ns, in_stat.st_dev, in_stat.st_ino) DeferredSourceType = _t.TypeVar("DeferredSourceType", bound=DeferredSource) diff --git a/tool/hoardy_web/wrr.py b/tool/hoardy_web/wrr.py index 4641aa5..4619302 100644 --- a/tool/hoardy_web/wrr.py +++ b/tool/hoardy_web/wrr.py @@ -699,15 +699,18 @@ def rrexprs_wrr_some_load(fobj : _io.BufferedReader, source : DeferredSourceType def rrexpr_wrr_loadf(path : str | bytes, in_stat : _os.stat_result | None = None) -> ReqresExpr[FileSource]: with open(path, "rb") as f: - return rrexpr_wrr_load(f, make_FileSource(path, f, in_stat)) + in_stat = _os.fstat(f.fileno()) + return rrexpr_wrr_load(f, make_FileSource(path, in_stat)) def rrexprs_wrr_bundle_loadf(path : str | bytes, in_stat : _os.stat_result | None = None) -> _t.Iterator[ReqresExpr[StreamElementSource[FileSource]]]: with open(path, "rb") as f: - yield from rrexprs_wrr_bundle_load(f, make_FileSource(path, f, in_stat)) + in_stat = _os.fstat(f.fileno()) + yield from rrexprs_wrr_bundle_load(f, make_FileSource(path, in_stat)) def rrexprs_wrr_some_loadf(path : str | bytes, in_stat : _os.stat_result | None = None) -> _t.Iterator[ReqresExpr[FileSource | StreamElementSource[FileSource]]]: with open(path, "rb") as f: - yield from rrexprs_wrr_some_load(f, make_FileSource(path, f, in_stat)) + in_stat = _os.fstat(f.fileno()) + yield from rrexprs_wrr_some_load(f, make_FileSource(path, in_stat)) def trivial_Reqres(url : ParsedURL, content_type : str = "text/html",