load_fileobj

igwn_ligolw.utils.load_fileobj(fileobj, compress=None, xmldoc=None, contenthandler=<class 'igwn_ligolw.ligolw.LIGOLWContentHandler'>)

Parse the contents of the file object fileobj, and return the contents as a LIGO Light Weight document tree. The file object does not need to be seekable. The file object must be in binary mode.

The compress parameter selects the decompression algorithm to use. Valid values are: “auto” to automatically deduce the decompression scheme from the file format; one of “bz2”, “gz”, or “xz” to force bzip2, gzip, or lzma/xz decompression, respectively; False to disable decompression; or None to select the default behaviour (which is “auto”).

If the optional xmldoc argument is provided and not None, the parsed XML tree will be appended to that document, otherwise a new document will be created. The return value is the xmldoc argument or the root of the newly created XML tree.

Example:

>>> from io import BytesIO
>>> f = BytesIO(b'<?xml version="1.0" encoding="utf-8" ?><!DOCTYPE LIGO_LW SYSTEM "http://ldas-sw.ligo.caltech.edu/doc/ligolwAPI/html/ligolw_dtd.txt"><LIGO_LW><Table Name="demo:table"><Column Name="name" Type="lstring"/><Column Name="value" Type="real_8"/><Stream Name="demo:table" Type="Local" Delimiter=",">"mass",0.5,"velocity",34</Stream></Table></LIGO_LW>')
>>> xmldoc = load_fileobj(f)

The contenthandler argument specifies the SAX content handler to use when parsing the document. See the igwn_ligolw package documentation for an explanation of a typical document parsing scenario and the content handler it uses. See igwn_ligolw.ligolw.PartialLIGOLWContentHandler and igwn_ligolw.ligolw.FilteringLIGOLWContentHandler for examples of custom content handlers used to load subsets of documents into memory.