get_file¶
- asdf.generic_io.get_file(init: FileLike, mode: FileMode = 'r', uri: PathLike | None = None, close: bool = False) GenericFile[source]¶
Returns a
GenericFileinstance suitable for wrapping the given objectinit.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
initmay be:A
bytesorunicodefile path orfile:orhttp:url.A Python 2
fileobject.An
io.IOBaseobject (the default file object on Python 3).A ducktyped object that looks like a file object. If
modeis"r", it must have areadmethod. Ifmodeis"w", it must have awritemethod. Ifmodeis"rw"it must have theread,write,tellandseekmethods.A
GenericFileinstance, in which case it is wrapped in aGenericWrapperinstance, 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
initis abytesorunicodeobject (since it will be the uri), and it may be determined automatically ifinitrefers 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 toFalse.
- Returns:
- fdGenericFile
- Raises:
- ValueError, TypeError, IOError