def _get_handle(path_or_buf, mode, encoding=None, compression=None,<EOL>memory_map=False, is_text=True):
try:<EOL><INDENT>from s3fs import S3File<EOL>need_text_wrapping = (BytesIO, S3File)<EOL><DEDENT>except ImportError:<EOL><INDENT>need_text_wrapping = (BytesIO,)<EOL><DEDENT>handles = list()<EOL>f = path_or_buf<EOL>path_or_buf = _stringify_path(path_or_buf)<EOL>is_path = isinstance(path_or_buf, str)<EOL>if is_path:<EOL><INDENT>compression = _infer_compression(path_or_buf, compression)<EOL><DEDENT>if compression:<EOL><INDENT>if compression == '<STR_LIT>':<EOL><INDENT>if is_path:<EOL><INDENT>f = gzip.open(path_or_buf, mode)<EOL><DEDENT>else:<EOL><INDENT>f = gzip.GzipFile(fileobj=path_or_buf)<EOL><DEDENT><DEDENT>elif compression == '<STR_LIT>':<EOL><INDENT>if is_path:<EOL><INDENT>f = bz2.BZ2File(path_or_buf, mode)<EOL><DEDENT>else:<EOL><INDENT>f = bz2.BZ2File(path_or_buf)<EOL><DEDENT><DEDENT>elif compression == '<STR_LIT>':<EOL><INDENT>zf = BytesZipFile(path_or_buf, mode)<EOL>handles.append(zf)<EOL>if zf.mode == '<STR_LIT:w>':<EOL><INDENT>f = zf<EOL><DEDENT>elif zf.mode == '<STR_LIT:r>':<EOL><INDENT>zip_names = zf.namelist()<EOL>if len(zip_names) == <NUM_LIT:1>:<EOL><INDENT>f = zf.open(zip_names.pop())<EOL><DEDENT>elif len(zip_names) == <NUM_LIT:0>:<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>.format(path_or_buf))<EOL><DEDENT>else:<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>'<STR_LIT>'<EOL>.format(zip_names))<EOL><DEDENT><DEDENT><DEDENT>elif compression == '<STR_LIT>':<EOL><INDENT>f = lzma.LZMAFile(path_or_buf, mode)<EOL><DEDENT>else:<EOL><INDENT>msg = '<STR_LIT>'.format(compression)<EOL>raise ValueError(msg)<EOL><DEDENT>handles.append(f)<EOL><DEDENT>elif is_path:<EOL><INDENT>if encoding:<EOL><INDENT>f = open(path_or_buf, mode, encoding=encoding, newline="<STR_LIT>")<EOL><DEDENT>elif is_text:<EOL><INDENT>f = open(path_or_buf, mode, errors='<STR_LIT:replace>', newline="<STR_LIT>")<EOL><DEDENT>else:<EOL><INDENT>f = open(path_or_buf, mode)<EOL><DEDENT>handles.append(f)<EOL><DEDENT>if is_text and (compression or isinstance(f, need_text_wrapping)):<EOL><INDENT>from io import TextIOWrapper<EOL>f = TextIOWrapper(f, encoding=encoding, newline='<STR_LIT>')<EOL>handles.append(f)<EOL><DEDENT>if memory_map and hasattr(f, '<STR_LIT>'):<EOL><INDENT>try:<EOL><INDENT>g = MMapWrapper(f)<EOL>f.close()<EOL>f = g<EOL><DEDENT>except Exception:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>return f, handles<EOL>
Get file handle for given path/buffer and mode.

Parameters
----------
path_or_buf :
    a path (str) or buffer
mode : str
    mode to open path_or_buf with
encoding : str or None
compression : {'infer', 'gzip', 'bz2', 'zip', 'xz', None}, default None
    If 'infer' and `filepath_or_buffer` is path-like, then detect
    compression from the following extensions: '.gz', '.bz2', '.zip',
    or '.xz' (otherwise no compression).
memory_map : boolean, default False
    See parsers._parser_params for more information.
is_text : boolean, default True
    whether file/buffer is in text format (csv, json, etc.), or in binary
    mode (pickle, etc.)

Returns
-------
f : file-like
    A file-like object
handles : list of file-like objects
    A list of file-like object that were opened in this function.