summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmaury Forgeot d'Arc <amauryfa@gmail.com>2008-03-26 19:49:26 (GMT)
committerAmaury Forgeot d'Arc <amauryfa@gmail.com>2008-03-26 19:49:26 (GMT)
commit9edef04c956c36aaa3ccc3eaef2d99f233153297 (patch)
treeaad4f8f586d31cb8cffaaefaefb9aaf0a9e25e8c
parentf6cd967e2c204238cb4fe56c7e842cf7766ddd01 (diff)
downloadcpython-9edef04c956c36aaa3ccc3eaef2d99f233153297.zip
cpython-9edef04c956c36aaa3ccc3eaef2d99f233153297.tar.gz
cpython-9edef04c956c36aaa3ccc3eaef2d99f233153297.tar.bz2
Correct Issue#1561: test_mailbox failed on Windows.
Open all text files with newline='', this is the only way to have consistent offsets.
-rwxr-xr-xLib/mailbox.py32
-rw-r--r--Lib/test/test_mailbox.py5
2 files changed, 18 insertions, 19 deletions
diff --git a/Lib/mailbox.py b/Lib/mailbox.py
index d2db53f..3ee9cbe 100755
--- a/Lib/mailbox.py
+++ b/Lib/mailbox.py
@@ -311,7 +311,7 @@ class Maildir(Mailbox):
def get_message(self, key):
"""Return a Message representation or raise a KeyError."""
subpath = self._lookup(key)
- f = open(os.path.join(self._path, subpath), 'r')
+ f = open(os.path.join(self._path, subpath), 'r', newline='')
try:
if self._factory:
msg = self._factory(f)
@@ -328,7 +328,7 @@ class Maildir(Mailbox):
def get_string(self, key):
"""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:
return f.read()
finally:
@@ -336,7 +336,7 @@ class Maildir(Mailbox):
def get_file(self, key):
"""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)
def iterkeys(self):
@@ -502,15 +502,15 @@ class _singlefileMailbox(Mailbox):
"""Initialize a single-file mailbox."""
Mailbox.__init__(self, path, factory, create)
try:
- f = open(self._path, 'r+')
+ f = open(self._path, 'r+', newline='')
except IOError as e:
if e.errno == errno.ENOENT:
if create:
- f = open(self._path, 'w+')
+ f = open(self._path, 'w+', newline='')
else:
raise NoSuchMailboxError(self._path)
elif e.errno == errno.EACCES:
- f = open(self._path, 'r')
+ f = open(self._path, 'r', newline='')
else:
raise
self._file = f
@@ -866,7 +866,7 @@ class MH(Mailbox):
"""Replace the keyed message; raise KeyError if it doesn't exist."""
path = os.path.join(self._path, str(key))
try:
- f = open(path, 'r+')
+ f = open(path, 'r+', newline='')
except IOError as e:
if e.errno == errno.ENOENT:
raise KeyError('No message with key: %s' % key)
@@ -890,9 +890,9 @@ class MH(Mailbox):
"""Return a Message representation or raise a KeyError."""
try:
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:
- 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:
if e.errno == errno.ENOENT:
raise KeyError('No message with key: %s' % key)
@@ -917,9 +917,9 @@ class MH(Mailbox):
"""Return a string representation or raise a KeyError."""
try:
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:
- 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:
if e.errno == errno.ENOENT:
raise KeyError('No message with key: %s' % key)
@@ -939,7 +939,7 @@ class MH(Mailbox):
def get_file(self, key):
"""Return a file-like representation or raise a KeyError."""
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:
if e.errno == errno.ENOENT:
raise KeyError('No message with key: %s' % key)
@@ -1017,7 +1017,7 @@ class MH(Mailbox):
def get_sequences(self):
"""Return a name-to-key-list dictionary to define each sequence."""
results = {}
- f = open(os.path.join(self._path, '.mh_sequences'), 'r')
+ f = open(os.path.join(self._path, '.mh_sequences'), 'r', newline='')
try:
all_keys = set(self.keys())
for line in f:
@@ -1043,7 +1043,7 @@ class MH(Mailbox):
def set_sequences(self, sequences):
"""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:
os.close(os.open(f.name, os.O_WRONLY | os.O_TRUNC))
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."""
fd = os.open(path, os.O_CREAT | os.O_EXCL | os.O_RDWR)
try:
- return open(path, 'r+')
+ return open(path, 'r+', newline='')
finally:
os.close(fd)
@@ -2072,7 +2072,7 @@ class MHMailbox:
if not self.boxes:
return None
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)
try:
msg._mh_msgno = fn
diff --git a/Lib/test/test_mailbox.py b/Lib/test/test_mailbox.py
index 8f4b486..ca87229 100644
--- a/Lib/test/test_mailbox.py
+++ b/Lib/test/test_mailbox.py
@@ -410,8 +410,7 @@ class TestMailbox(TestBase):
_sample_message, io.StringIO(_sample_message)):
output = io.StringIO()
self._box._dump_message(input, output)
- self.assertEqual(output.getvalue(),
- _sample_message.replace('\n', os.linesep))
+ self.assertEqual(output.getvalue(), _sample_message)
output = io.StringIO()
self.assertRaises(TypeError,
lambda: self._box._dump_message(None, output))
@@ -757,7 +756,7 @@ class _TestMboxMMDF(TestMailbox):
self._box._file.seek(0)
contents = self._box._file.read()
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)
def test_lock_conflict(self):