def fileish_open(fileish, mode):
if mode is not None and any(m in mode for m in ['<STR_LIT:+>', '<STR_LIT:w>', '<STR_LIT:a>', '<STR_LIT:x>']):<EOL><INDENT>attr = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>attr = '<STR_LIT>'<EOL><DEDENT>if hasattr(fileish, attr) and hasattr(fileish, '<STR_LIT>'):<EOL><INDENT>return fileish<EOL><DEDENT>elif isinstance(fileish, str):<EOL><INDENT>try:<EOL><INDENT>return open(fileish, mode)<EOL><DEDENT>except TypeError:<EOL><INDENT>return io.BytesIO(fileish)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>return io.BytesIO(fileish)<EOL><DEDENT>
Convert file-ish object to BytesIO like object.
:param fileish: the file-ihs object (str, BytesIO, bytes, file contents)
:param str mode: mode for the open function.
:rtype: BytesIO