mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Correct Issue#1561: test_mailbox failed on Windows.
Open all text files with newline='', this is the only way to have consistent offsets.
This commit is contained in:
parent
f6cd967e2c
commit
9edef04c95
2 changed files with 18 additions and 19 deletions
|
@ -311,7 +311,7 @@ class Maildir(Mailbox):
|
||||||
def get_message(self, key):
|
def get_message(self, key):
|
||||||
"""Return a Message representation or raise a KeyError."""
|
"""Return a Message representation or raise a KeyError."""
|
||||||
subpath = self._lookup(key)
|
subpath = self._lookup(key)
|
||||||
f = open(os.path.join(self._path, subpath), 'r')
|
f = open(os.path.join(self._path, subpath), 'r', newline='')
|
||||||
try:
|
try:
|
||||||
if self._factory:
|
if self._factory:
|
||||||
msg = self._factory(f)
|
msg = self._factory(f)
|
||||||
|
@ -328,7 +328,7 @@ class Maildir(Mailbox):
|
||||||
|
|
||||||
def get_string(self, key):
|
def get_string(self, key):
|
||||||
"""Return a string representation or raise a KeyError."""
|
"""Return a string representation or raise a KeyError."""
|
||||||
f = open(os.path.join(self._path, self._lookup(key)), 'r')
|
f = open(os.path.join(self._path, self._lookup(key)), 'r', newline='')
|
||||||
try:
|
try:
|
||||||
return f.read()
|
return f.read()
|
||||||
finally:
|
finally:
|
||||||
|
@ -336,7 +336,7 @@ class Maildir(Mailbox):
|
||||||
|
|
||||||
def get_file(self, key):
|
def get_file(self, key):
|
||||||
"""Return a file-like representation or raise a KeyError."""
|
"""Return a file-like representation or raise a KeyError."""
|
||||||
f = open(os.path.join(self._path, self._lookup(key)), 'r')
|
f = open(os.path.join(self._path, self._lookup(key)), 'r', newline='')
|
||||||
return _ProxyFile(f)
|
return _ProxyFile(f)
|
||||||
|
|
||||||
def iterkeys(self):
|
def iterkeys(self):
|
||||||
|
@ -502,15 +502,15 @@ class _singlefileMailbox(Mailbox):
|
||||||
"""Initialize a single-file mailbox."""
|
"""Initialize a single-file mailbox."""
|
||||||
Mailbox.__init__(self, path, factory, create)
|
Mailbox.__init__(self, path, factory, create)
|
||||||
try:
|
try:
|
||||||
f = open(self._path, 'r+')
|
f = open(self._path, 'r+', newline='')
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
if e.errno == errno.ENOENT:
|
if e.errno == errno.ENOENT:
|
||||||
if create:
|
if create:
|
||||||
f = open(self._path, 'w+')
|
f = open(self._path, 'w+', newline='')
|
||||||
else:
|
else:
|
||||||
raise NoSuchMailboxError(self._path)
|
raise NoSuchMailboxError(self._path)
|
||||||
elif e.errno == errno.EACCES:
|
elif e.errno == errno.EACCES:
|
||||||
f = open(self._path, 'r')
|
f = open(self._path, 'r', newline='')
|
||||||
else:
|
else:
|
||||||
raise
|
raise
|
||||||
self._file = f
|
self._file = f
|
||||||
|
@ -866,7 +866,7 @@ class MH(Mailbox):
|
||||||
"""Replace the keyed message; raise KeyError if it doesn't exist."""
|
"""Replace the keyed message; raise KeyError if it doesn't exist."""
|
||||||
path = os.path.join(self._path, str(key))
|
path = os.path.join(self._path, str(key))
|
||||||
try:
|
try:
|
||||||
f = open(path, 'r+')
|
f = open(path, 'r+', newline='')
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
if e.errno == errno.ENOENT:
|
if e.errno == errno.ENOENT:
|
||||||
raise KeyError('No message with key: %s' % key)
|
raise KeyError('No message with key: %s' % key)
|
||||||
|
@ -890,9 +890,9 @@ class MH(Mailbox):
|
||||||
"""Return a Message representation or raise a KeyError."""
|
"""Return a Message representation or raise a KeyError."""
|
||||||
try:
|
try:
|
||||||
if self._locked:
|
if self._locked:
|
||||||
f = open(os.path.join(self._path, str(key)), 'r+')
|
f = open(os.path.join(self._path, str(key)), 'r+', newline='')
|
||||||
else:
|
else:
|
||||||
f = open(os.path.join(self._path, str(key)), 'r')
|
f = open(os.path.join(self._path, str(key)), 'r', newline='')
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
if e.errno == errno.ENOENT:
|
if e.errno == errno.ENOENT:
|
||||||
raise KeyError('No message with key: %s' % key)
|
raise KeyError('No message with key: %s' % key)
|
||||||
|
@ -917,9 +917,9 @@ class MH(Mailbox):
|
||||||
"""Return a string representation or raise a KeyError."""
|
"""Return a string representation or raise a KeyError."""
|
||||||
try:
|
try:
|
||||||
if self._locked:
|
if self._locked:
|
||||||
f = open(os.path.join(self._path, str(key)), 'r+')
|
f = open(os.path.join(self._path, str(key)), 'r+', newline='')
|
||||||
else:
|
else:
|
||||||
f = open(os.path.join(self._path, str(key)), 'r')
|
f = open(os.path.join(self._path, str(key)), 'r', newline='')
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
if e.errno == errno.ENOENT:
|
if e.errno == errno.ENOENT:
|
||||||
raise KeyError('No message with key: %s' % key)
|
raise KeyError('No message with key: %s' % key)
|
||||||
|
@ -939,7 +939,7 @@ class MH(Mailbox):
|
||||||
def get_file(self, key):
|
def get_file(self, key):
|
||||||
"""Return a file-like representation or raise a KeyError."""
|
"""Return a file-like representation or raise a KeyError."""
|
||||||
try:
|
try:
|
||||||
f = open(os.path.join(self._path, str(key)), 'r')
|
f = open(os.path.join(self._path, str(key)), 'r', newline='')
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
if e.errno == errno.ENOENT:
|
if e.errno == errno.ENOENT:
|
||||||
raise KeyError('No message with key: %s' % key)
|
raise KeyError('No message with key: %s' % key)
|
||||||
|
@ -1017,7 +1017,7 @@ class MH(Mailbox):
|
||||||
def get_sequences(self):
|
def get_sequences(self):
|
||||||
"""Return a name-to-key-list dictionary to define each sequence."""
|
"""Return a name-to-key-list dictionary to define each sequence."""
|
||||||
results = {}
|
results = {}
|
||||||
f = open(os.path.join(self._path, '.mh_sequences'), 'r')
|
f = open(os.path.join(self._path, '.mh_sequences'), 'r', newline='')
|
||||||
try:
|
try:
|
||||||
all_keys = set(self.keys())
|
all_keys = set(self.keys())
|
||||||
for line in f:
|
for line in f:
|
||||||
|
@ -1043,7 +1043,7 @@ class MH(Mailbox):
|
||||||
|
|
||||||
def set_sequences(self, sequences):
|
def set_sequences(self, sequences):
|
||||||
"""Set sequences using the given name-to-key-list dictionary."""
|
"""Set sequences using the given name-to-key-list dictionary."""
|
||||||
f = open(os.path.join(self._path, '.mh_sequences'), 'r+')
|
f = open(os.path.join(self._path, '.mh_sequences'), 'r+', newline='')
|
||||||
try:
|
try:
|
||||||
os.close(os.open(f.name, os.O_WRONLY | os.O_TRUNC))
|
os.close(os.open(f.name, os.O_WRONLY | os.O_TRUNC))
|
||||||
for name, keys in sequences.items():
|
for name, keys in sequences.items():
|
||||||
|
@ -1904,7 +1904,7 @@ def _create_carefully(path):
|
||||||
"""Create a file if it doesn't exist and open for reading and writing."""
|
"""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)
|
fd = os.open(path, os.O_CREAT | os.O_EXCL | os.O_RDWR)
|
||||||
try:
|
try:
|
||||||
return open(path, 'r+')
|
return open(path, 'r+', newline='')
|
||||||
finally:
|
finally:
|
||||||
os.close(fd)
|
os.close(fd)
|
||||||
|
|
||||||
|
@ -2072,7 +2072,7 @@ class MHMailbox:
|
||||||
if not self.boxes:
|
if not self.boxes:
|
||||||
return None
|
return None
|
||||||
fn = self.boxes.pop()
|
fn = self.boxes.pop()
|
||||||
fp = open(os.path.join(self.dirname, fn))
|
fp = open(os.path.join(self.dirname, fn), newline='')
|
||||||
msg = self.factory(fp)
|
msg = self.factory(fp)
|
||||||
try:
|
try:
|
||||||
msg._mh_msgno = fn
|
msg._mh_msgno = fn
|
||||||
|
|
|
@ -410,8 +410,7 @@ class TestMailbox(TestBase):
|
||||||
_sample_message, io.StringIO(_sample_message)):
|
_sample_message, io.StringIO(_sample_message)):
|
||||||
output = io.StringIO()
|
output = io.StringIO()
|
||||||
self._box._dump_message(input, output)
|
self._box._dump_message(input, output)
|
||||||
self.assertEqual(output.getvalue(),
|
self.assertEqual(output.getvalue(), _sample_message)
|
||||||
_sample_message.replace('\n', os.linesep))
|
|
||||||
output = io.StringIO()
|
output = io.StringIO()
|
||||||
self.assertRaises(TypeError,
|
self.assertRaises(TypeError,
|
||||||
lambda: self._box._dump_message(None, output))
|
lambda: self._box._dump_message(None, output))
|
||||||
|
@ -757,7 +756,7 @@ class _TestMboxMMDF(TestMailbox):
|
||||||
self._box._file.seek(0)
|
self._box._file.seek(0)
|
||||||
contents = self._box._file.read()
|
contents = self._box._file.read()
|
||||||
self._box.close()
|
self._box.close()
|
||||||
self.assertEqual(contents, open(self._path, 'r').read())
|
self.assertEqual(contents, open(self._path, 'r', newline='').read())
|
||||||
self._box = self._factory(self._path)
|
self._box = self._factory(self._path)
|
||||||
|
|
||||||
def test_lock_conflict(self):
|
def test_lock_conflict(self):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue