diff --git a/Lib/mailbox.py b/Lib/mailbox.py index b00d9e863..364af6bb0 100644 --- a/Lib/mailbox.py +++ b/Lib/mailbox.py @@ -2183,11 +2183,7 @@ def _unlock_file(f): def _create_carefully(path): """Create a file if it doesn't exist and open for reading and writing.""" - fd = os.open(path, os.O_CREAT | os.O_EXCL | os.O_RDWR, 0o666) - try: - return open(path, 'rb+') - finally: - os.close(fd) + return open(path, 'xb+') def _create_temporary(path): """Create a temp file based on path and open for reading and writing.""" diff --git a/Lib/test/test_mailbox.py b/Lib/test/test_mailbox.py index 940baf394..0169948e4 100644 --- a/Lib/test/test_mailbox.py +++ b/Lib/test/test_mailbox.py @@ -1,7 +1,6 @@ import os import sys import time -import stat import socket import email import email.message @@ -13,7 +12,6 @@ from test.support import import_helper from test.support import os_helper from test.support import refleak_helper from test.support import socket_helper -from test.support.testcase import ExtraAssertions import unittest import textwrap import mailbox @@ -1267,7 +1265,7 @@ class _TestMboxMMDF(_TestSingleFile): self._box.close() -class TestMbox(_TestMboxMMDF, unittest.TestCase, ExtraAssertions): +class TestMbox(_TestMboxMMDF, unittest.TestCase): _factory = lambda self, path, factory=None: mailbox.mbox(path, factory)