'Check if a given file-like object (or whatever else subprocess.Popen
takes as a handle/stream) can be correctly inherited by a child process.
This just duplicates the code in subprocess.Popen._get_handles to make
sure we go down the correct code path; this to catch some non-standard
corner cases.'

@classmethod
def _checkFileObjInheritable(cls, fileobj, handle_name):

    import _subprocess
    import ctypes
    import msvcrt
    new_handle = None
    try:
        if (fileobj is None):
            handle = _subprocess.GetStdHandle(getattr(_subprocess, handle_name))
            if (handle is None):
                return True
        elif (fileobj == subprocess.PIPE):
            return True
        elif isinstance(fileobj, int):
            handle = msvcrt.get_osfhandle(fileobj)
        else:
            handle = msvcrt.get_osfhandle(fileobj.fileno())
        new_handle = self._make_inheritable(handle)
        return True
    except:
        return False
    finally:
        CloseHandle = ctypes.windll.kernel32.CloseHandle
        if (new_handle is not None):
            CloseHandle(new_handle)
