Selkies
Developer Referencestream_server

_AuditedFileResponse

A file served by aiohttp, recorded for the audit as event once it went out: the whole file or the range asked for, with the bytes served. A download the client stops before the end raises out of prepare and is not recorded. With remove, a file that went out whole is deleted.

Functions

constructor__init__(path, served, event='file.download', remove=False, **kwargs) -> None
Source Code
def __init__(self, path: pathlib.Path, served: str, event: str = "file.download",
             remove: bool = False, **kwargs: Any) -> None:
    super().__init__(path, **kwargs)
    self._served = served
    self._event = event
    self._remove = path if remove else None
parampathpathlib.Path
paramservedstr
parameventstr
= 'file.download'
paramremovebool
= False
paramkwargsAny
= {}

Returns

None
funcprepare(request) -> Any
Source Code
async def prepare(self, request: web.BaseRequest) -> Any:
    writer = await super().prepare(request)
    if request.method == "GET" and self.status in (200, 206):
        audit.emit(self._event, filename=self._served,
                   size_bytes=self.content_length or 0, partial=self.status == 206)
        if self._remove is not None and self.status == 200:
            with contextlib.suppress(OSError):
                os.unlink(self._remove)
    return writer
paramrequestweb.BaseRequest

Returns

typing.Any

On this page

Edit on GitHub