(item: KeyValueArg)
| 210 | |
| 211 | |
| 212 | def load_text_file(item: KeyValueArg) -> str: |
| 213 | path = item.value |
| 214 | try: |
| 215 | with open(os.path.expanduser(path), 'rb') as f: |
| 216 | return f.read().decode() |
| 217 | except OSError as e: |
| 218 | raise ParseError(f'{item.orig!r}: {e}') |
| 219 | except UnicodeDecodeError: |
| 220 | raise ParseError( |
| 221 | f'{item.orig!r}: cannot embed the content of {item.value!r},' |
| 222 | ' not a UTF-8 or ASCII-encoded text file' |
| 223 | ) |
| 224 | |
| 225 | |
| 226 | def load_json(arg: KeyValueArg, contents: str) -> JSONType: |
no test coverage detected