The StreamInfo class is used to store information about a file stream. All fields can be None, and will depend on how the stream was opened.
| 4 | |
| 5 | @dataclass(kw_only=True, frozen=True) |
| 6 | class StreamInfo: |
| 7 | """The StreamInfo class is used to store information about a file stream. |
| 8 | All fields can be None, and will depend on how the stream was opened. |
| 9 | """ |
| 10 | |
| 11 | mimetype: Optional[str] = None |
| 12 | extension: Optional[str] = None |
| 13 | charset: Optional[str] = None |
| 14 | filename: Optional[ |
| 15 | str |
| 16 | ] = None # From local path, url, or Content-Disposition header |
| 17 | local_path: Optional[str] = None # If read from disk |
| 18 | url: Optional[str] = None # If read from url |
| 19 | |
| 20 | def copy_and_update(self, *args, **kwargs): |
| 21 | """Copy the StreamInfo object and update it with the given StreamInfo |
| 22 | instance and/or other keyword arguments.""" |
| 23 | new_info = asdict(self) |
| 24 | |
| 25 | for si in args: |
| 26 | assert isinstance(si, StreamInfo) |
| 27 | new_info.update({k: v for k, v in asdict(si).items() if v is not None}) |
| 28 | |
| 29 | if len(kwargs) > 0: |
| 30 | new_info.update(kwargs) |
| 31 | |
| 32 | return StreamInfo(**new_info) |
no outgoing calls
searching dependent graphs…