A file part of a form: its content, file name and content type.
Attributes#
| Attribute | Type | Description |
|---|---|---|
content | FileContent | |
name | str = 'blob' | |
content_type | str = 'application/octet-stream' |
Functions#
__init__#
__init__(content, name='blob', content_type='application/octet-stream') -> None| Parameter | Type | Description |
|---|---|---|
content | FileContent | |
name | str = 'blob' | |
content_type | str = 'application/octet-stream' |
stream#
stream() -> Stream_[bytes, FileSourceError]The content; a source is opened when the stream runs, and its
raise or failure is a FileSourceError.
Returns Stream_[bytes, FileSourceError]
def stream(self) -> Stream_[bytes, FileSourceError]:
"""The content; a source is opened when the stream runs, and its
raise or failure is a ``FileSourceError``."""
from pyfect import stream as _stream
content = self.content
if isinstance(content, bytes):
return _stream.succeed(content)
source = content
def open_source() -> Stream_[bytes, FileSourceError]:
try:
opened = source()
except Exception as error:
return _stream.fail(FileSourceError(error))
return opened.map_error(FileSourceError)
return _stream.suspend(open_source)