(path, mode, encoding=None)
Open a local file `path` for reading. The file may be gzip, bz2 or zip
    compressed.

    If a zip archive then a single archive member is expected.

    Parameters
    ----------
    path : str
        File system path
    mode : str
        'r', 'rb' or 'rt'
    encoding : Optional[str]
        Optional text encoding, for opening in text mode.

    Returns
    -------
    stream: io.BaseIO
        A stream opened for reading.
Open a local file `path` for reading. The file may be gzip, bz2 or zip
    compressed.
Open a local file path for reading . The file may be gzip bz2 or zip compressed .
def _open(path, mode, encoding=None):
    # type: (str, str, Optional[str]) -> typing.IO[Any]
    """
    Open a local file `path` for reading. The file may be gzip, bz2 or zip
    compressed.

    If a zip archive then a single archive member is expected.

    Parameters
    ----------
    path : str
        File system path
    mode : str
        'r', 'rb' or 'rt'
    encoding : Optional[str]
        Optional text encoding, for opening in text mode.

    Returns
    -------
    stream: io.BaseIO
        A stream opened for reading.
    """
    if mode not in {'r', 'rb', 'rt'}:
        raise ValueError('r')
    _, ext = os.path.splitext(path)
    ext = ext.lower()
    if ext == ".gz":
        return gzip.open(path, mode, encoding=encoding)
    elif ext == ".bz2":
        return bz2.open(path, mode, encoding=encoding)
    elif ext == ".xz":
        return lzma.open(path, mode, encoding=encoding)
    elif ext == ".zip":
        arh = zipfile.ZipFile(path, 'r')
        filelist = arh.infolist()
        if len(filelist) == 1:
            f = arh.open(filelist[0], 'r')
            # patch the f.close to also close the main archive file
            f_close = f.close

            def close_():
                f_close()
                arh.close()
            f.close = close_
            if 't' in mode:
                f = io.TextIOWrapper(f, encoding=encoding)
            return f
        else:
            raise ValueError("Expected a single file in the archive.")
    else:
        return open(path, mode, encoding=encoding)
def _open ( path , mode , encoding = None ) : # type: (str, str, Optional[str]) -> typing.IO[Any] if mode not in { 'r' , 'rb' , 'rt' } : raise ValueError ( 'r' ) _ , ext = os . path . splitext ( path ) ext = ext . lower ( ) if ext == ".gz" : return gzip . open ( path , mode , encoding = encoding ) elif ext == ".bz2" : return bz2 . open ( path , mode , encoding = encoding ) elif ext == ".xz" : return lzma . open ( path , mode , encoding = encoding ) elif ext == ".zip" : arh = zipfile . ZipFile ( path , 'r' ) filelist = arh . infolist ( ) if len ( filelist ) == 1 : f = arh . open ( filelist [ 0 ] , 'r' ) # patch the f.close to also close the main archive file f_close = f . close def close_ ( ) : f_close ( ) arh . close ( ) f . close = close_ if 't' in mode : f = io . TextIOWrapper ( f , encoding = encoding ) return f else : raise ValueError ( "Expected a single file in the archive." ) else : return open ( path , mode , encoding = encoding )