BadWriteFormatter¶
- class lsst.daf.butler.tests.BadWriteFormatter(file_descriptor: FileDescriptor, *, ref: DatasetRef, write_parameters: Mapping[str, Any] | None = None, write_recipes: Mapping[str, Any] | None = None, **kwargs: Any)¶
- Bases: - YamlFormatter- A formatter that never works but does leave a file behind. - Attributes Summary - Declare whether - read_from_fileis available to this formatter.- Declare whether - read_from_streamis available to this formatter.- Declare whether - read_from_uriis available to this formatter.- Methods Summary - read_from_uri(uri[, component, expected_size])- Read a dataset from a URI that can be local or remote. - write_direct(in_memory_dataset, uri[, ...])- Serialize and write directly to final location. - Attributes Documentation - can_read_from_local_file: ClassVar[bool] = False¶
- Declare whether - read_from_fileis available to this formatter.
 - can_read_from_stream: ClassVar[bool] = False¶
- Declare whether - read_from_streamis available to this formatter.
 - can_read_from_uri: ClassVar[bool] = False¶
- Declare whether - read_from_uriis available to this formatter.
 - Methods Documentation - read_from_uri(uri: ResourcePath, component: str | None = None, expected_size: int = -1) Any¶
- Read a dataset from a URI that can be local or remote. - Parameters:
- urilsst.resources.ResourcePath
- URI to use to read the dataset. This URI can be local or remote and can refer to the actual resource or to a locally cached file. 
- componentstrorNone, optional
- The component to be read from the dataset. 
- expected_sizeint, optional
- If known, the expected size of the resource to read. This can be - -1indicates the file size is not known.
 
- uri
- Returns:
- in_memory_datasetobjectorNotImplemented
- The Python object read from the resource or - NotImplemented.
 
- in_memory_dataset
- Raises:
- FormatterNotImplementedError
- Raised if there is no support for direct reads from a, possibly, remote URI. 
 
 - Notes - This method is only called if the class property - can_read_from_uriis set to- True.- It is possible that a cached local file will be given to this method even if it was originally a remote URI. This can happen if the original write resulted in the file being added to the local cache. - If the full file is being read this file will not be added to the local cache. Consider returning - NotImplementedin this situation, for example if there are no parameters or component specified, and allowing the system to fall back to calling- read_from_local_file(which will populate the cache if configured to do so).
 - write_direct(in_memory_dataset: Any, uri: ResourcePath, cache_manager: AbstractDatastoreCacheManager | None = None) bool¶
- Serialize and write directly to final location. - Parameters:
- in_memory_datasetobject
- The Dataset to serialize. 
- urilsst.resources.ResourcePath
- URI to use when writing the serialized dataset. 
- cache_managerAbstractDatastoreCacheManager
- A cache manager to use to allow a formatter to cache the written file. 
 
- in_memory_dataset
- Returns:
- writtenbool
- Flag to indicate whether the direct write did happen. 
 
- written
- Raises:
- Exception
- Raised if there was a failure from serializing to bytes that was not - FormatterNotImplementedError.
 
 - Notes - This method will call - to_bytesto serialize the in-memory dataset and then will call the- writemethod directly.- If the dataset should be cached or is local the file will not be written and the method will return - False. This is because local URIs should be written to a temporary file name and then renamed to allow atomic writes. That path is handled by- write_locally_then_movethrough- write_local_file) and is preferred over this method being subclassed and the atomic write re-implemented.