Validates `path_or_fileobj` and compute `upload_info`.
(self)
| 476 | _is_committed: bool = field(init=False, repr=False, default=False) |
| 477 | |
| 478 | def __post_init__(self) -> None: |
| 479 | """Validates `path_or_fileobj` and compute `upload_info`.""" |
| 480 | |
| 481 | self.path_in_repo = _validate_path_in_repo(self.path_in_repo) |
| 482 | |
| 483 | # Validate `path_or_fileobj` value |
| 484 | if isinstance(self.path_or_fileobj, Path): |
| 485 | self.path_or_fileobj = str(self.path_or_fileobj) |
| 486 | if isinstance(self.path_or_fileobj, str): |
| 487 | path_or_fileobj = os.path.normpath( |
| 488 | os.path.expanduser(self.path_or_fileobj)) |
| 489 | if not os.path.isfile(path_or_fileobj): |
| 490 | raise ValueError( |
| 491 | f"Provided path: '{path_or_fileobj}' is not a file on the local file system" |
| 492 | ) |
| 493 | elif not isinstance(self.path_or_fileobj, (io.BufferedIOBase, bytes)): |
| 494 | raise ValueError( |
| 495 | 'path_or_fileobj must be either an instance of str, bytes or' |
| 496 | ' io.BufferedIOBase. If you passed a file-like object, make sure it is' |
| 497 | ' in binary mode.') |
| 498 | if isinstance(self.path_or_fileobj, io.BufferedIOBase): |
| 499 | try: |
| 500 | self.path_or_fileobj.tell() |
| 501 | self.path_or_fileobj.seek(0, os.SEEK_CUR) |
| 502 | except (OSError, AttributeError) as exc: |
| 503 | raise ValueError( |
| 504 | 'path_or_fileobj is a file-like object but does not implement seek() and tell()' |
| 505 | ) from exc |
| 506 | |
| 507 | # Compute "upload_info" attribute |
| 508 | if isinstance(self.path_or_fileobj, str): |
| 509 | self.upload_info = UploadInfo.from_path(self.path_or_fileobj, |
| 510 | self.file_hash_info) |
| 511 | elif isinstance(self.path_or_fileobj, bytes): |
| 512 | self.upload_info = UploadInfo.from_bytes(self.path_or_fileobj, |
| 513 | self.file_hash_info) |
| 514 | else: |
| 515 | self.upload_info = UploadInfo.from_fileobj(self.path_or_fileobj, |
| 516 | self.file_hash_info) |
| 517 | |
| 518 | @contextmanager |
| 519 | def as_file(self) -> Iterator[BinaryIO]: |
nothing calls this directly
no test coverage detected