| 43 | class InventoryFile: |
| 44 | @classmethod |
| 45 | def loads( |
| 46 | cls, |
| 47 | content: bytes, |
| 48 | *, |
| 49 | uri: str, |
| 50 | ) -> _Inventory: |
| 51 | format_line, _, content = content.partition(b'\n') |
| 52 | format_line = format_line.rstrip() # remove trailing \r or spaces |
| 53 | if format_line == b'# Sphinx inventory version 2': |
| 54 | return cls._loads_v2(content, uri=uri) |
| 55 | if format_line == b'# Sphinx inventory version 1': |
| 56 | lines = content.decode().splitlines() |
| 57 | return cls._loads_v1(lines, uri=uri) |
| 58 | if format_line.startswith(b'# Sphinx inventory version '): |
| 59 | unknown_version = format_line[27:].decode() |
| 60 | msg = f'unknown or unsupported inventory version: {unknown_version!r}' |
| 61 | raise ValueError(msg) |
| 62 | msg = f'invalid inventory header: {format_line.decode()}' |
| 63 | raise ValueError(msg) |
| 64 | |
| 65 | @classmethod |
| 66 | def load(cls, stream: _SupportsRead, uri: str, joinfunc: _JoinFunc) -> Inventory: |