def test_get_handle_info_stdin(self): _, library = dist.load() stdin_handle = GetStdHandle(library.STD_INPUT_HANDLE) handle_flags = GetHandleInformation(stdin_handle) inherit = handle_flags & library.HANDLE_FLAG_INHERIT expected = (0, library.HANDLE_FLAG_INHERIT) self.assertIn(inherit, expected)
def test_get_handle_info_socket(self): ffi, library = dist.load() sock = socket.socket() self.addCleanup(sock.close) sock_handle = HANDLE(ffi.cast("void *", sock.fileno())) handle_flags = GetHandleInformation(sock_handle) inherit = handle_flags & library.HANDLE_FLAG_INHERIT expected = self._expected_inheritance() self.assertEqual(inherit, expected)
def _set_handle_info_socket(self, inherit, check=False): ffi, library = dist.load() sock = socket.socket() self.addCleanup(sock.close) sock_handle = HANDLE(ffi.cast("void *", sock.fileno())) SetHandleInformation(sock_handle, library.HANDLE_FLAG_INHERIT, inherit) if check: result = GetHandleInformation(sock_handle) self.assertEqual(inherit, result)
def test_duplication(self): event = CreateEvent(bManualReset=False, bInitialState=False) self.addCleanup(CloseHandle, event) _, library = dist.load() handle = DuplicateHandle(GetCurrentProcess(), event, GetCurrentProcess(), 0, True, library.DUPLICATE_SAME_ACCESS) self.addCleanup(CloseHandle, handle) info = GetHandleInformation(handle) self.assertEqual(info, library.HANDLE_FLAG_INHERIT)
def _set_handle_info_file(self, inherit, check=False): _, library = dist.load() tempdir = tempfile.mkdtemp() self.addCleanup(os.rmdir, tempdir) filename = os.path.join(tempdir, "test_file") with open(filename, "w") as test_file: self.addCleanup(os.unlink, filename) test_file.write("data") file_handle = handle_from_file(test_file) SetHandleInformation(file_handle, library.HANDLE_FLAG_INHERIT, inherit) if check: result = GetHandleInformation(file_handle) self.assertEqual(inherit, result)
def test_get_handle_info_file(self): _, library = dist.load() # can't use mkstemp: not inheritable on Python < 3.4 tempdir = tempfile.mkdtemp() self.addCleanup(os.rmdir, tempdir) filename = os.path.join(tempdir, "test_file") with open(filename, "w") as test_file: self.addCleanup(os.unlink, filename) test_file.write("data") file_handle = handle_from_file(test_file) handle_flags = GetHandleInformation(file_handle) inherit = handle_flags & library.HANDLE_FLAG_INHERIT expected = self._expected_inheritance() self.assertEqual(inherit, expected)