Skip to content

Commit c16bc35

Browse files
committed
Add comments
1 parent a09404b commit c16bc35

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

aiohttp/web_fileresponse.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ def __init__(
9797
headers: Optional[LooseHeaders] = None,
9898
) -> None:
9999
super().__init__(status=status, reason=reason, headers=headers)
100+
# either set self._io or self._path
100101
if isinstance(path, io.BufferedReader):
101102
self._io = path
102103
self._path = None
@@ -193,6 +194,10 @@ def _make_response(
193194
file_path, st, file_encoding = self._get_file_path_stat_encoding(
194195
accept_encoding
195196
)
197+
# file_path is None if the path is not a regular file
198+
# it is also None if self._io is used instead of self._path
199+
if file_path is None and self._io is None:
200+
return _FileResponseResult.NOT_ACCEPTABLE, None, st, None
196201

197202
etag_value = f"{st.st_mtime_ns:x}-{st.st_size:x}"
198203

@@ -222,10 +227,9 @@ def _make_response(
222227
):
223228
return _FileResponseResult.NOT_MODIFIED, None, st, file_encoding
224229

230+
# if file_path is None at this stage, self._io is set or NOT_ACCEPTABLE
231+
# would have been returned earlier
225232
if file_path is None:
226-
if self._io is None:
227-
return _FileResponseResult.NOT_ACCEPTABLE, None, st, None
228-
229233
return _FileResponseResult.SEND_FILE, self._io, st, file_encoding
230234

231235
fobj = file_path.open("rb")
@@ -240,6 +244,7 @@ def _make_response(
240244
def _get_file_path_stat_encoding(
241245
self, accept_encoding: str
242246
) -> Tuple[Optional[pathlib.Path], os.stat_result, Optional[str]]:
247+
# self._io used instead of self._path
243248
if self._path is None:
244249
assert self._io is not None
245250
return None, os.stat(self._io.fileno()), None
@@ -396,6 +401,8 @@ async def _prepare_open_file(
396401
guesser = CONTENT_TYPES.guess_type
397402
self.content_type = guesser(self._path)[0] or FALLBACK_CONTENT_TYPE
398403
else:
404+
# content-type cannot be determined if self._io is used
405+
# instead of self._path
399406
self.content_type = FALLBACK_CONTENT_TYPE
400407

401408
if file_encoding:

0 commit comments

Comments
 (0)