get_file

asdf.generic_io.get_file(init: FileLike, mode: FileMode = 'r', uri: PathLike | None = None, close: bool = False) GenericFile[source]

Returns a GenericFile instance suitable for wrapping the given object init.

If passed an already open file-like object, it must be opened for reading/writing in binary mode. It is the caller’s responsibility to close it.

Parameters:
initobject

init may be:

  • A bytes or unicode file path or file: or http: url.

  • A Python 2 file object.

  • An io.IOBase object (the default file object on Python 3).

  • A ducktyped object that looks like a file object. If mode is "r", it must have a read method. If mode is "w", it must have a write method. If mode is "rw" it must have the read, write, tell and seek methods.

  • A GenericFile instance, in which case it is wrapped in a GenericWrapper instance, so that the file is closed when only when the final layer is unwrapped.

modestr

Must be one of "r", "w" or "rw".

uristr

Sets the base URI of the file object. This will be used to resolve any relative URIs contained in the file. This is redundant if init is a bytes or unicode object (since it will be the uri), and it may be determined automatically if init refers to a regular filesystem file. It is not required if URI resolution is not used in the file.

closebool

If True, closes the underlying file handle when this object is closed. Defaults to False.

Returns:
fdGenericFile
Raises:
ValueError, TypeError, IOError