def open_compressed(filename=None, fileobj=None, mode='r',
                    compressor=('gzip', '--quiet')):
    """Read or write a compressed file using an external (de)compressor.
    One of filename and fileobj must be specified.

    filename -- Filename to open.
    fileobj -- File object to wrap (de)compressor around.
    mode -- Must contain 'r' or 'w'. Passed to open if filename is provided.
    compressor -- Command-line of (de)compression program, for example,
                  ['gzip', '--quiet'].
                  Specified compressor should behave like gzip(1)
                  (with respect to behavior with no arguments and with '-d').
    """
    if filename and not fileobj:
        fileobj = open(filename, mode)
    elif filename or not fileobj:
        raise ValueError("Must specify exactly one of filename or fileobj")
    if 'r' in mode:
        return Popen(tuple(compressor) + ('-d',),
                     stdin=fileobj, stdout=PIPE, stderr=STDOUT).stdout
    elif 'w' in mode:
        return Popen(tuple(compressor), stdin=PIPE, stdout=fileobj).stdin
    else:
        raise ValueError("Must specify read or write")
dataset/ETHPy150Open nandhp/python-imdb/imdb/utils.py/open_compressed/original