test_old_mailbox pass.
fcre = re.compile(r'^From ', re.MULTILINE)
def _is8bitstring(s):
- if isinstance(s, str):
+ if isinstance(s, bytes):
try:
str(s, 'us-ascii')
+ return True
except UnicodeError:
+ pass
+ elif isinstance(s, str):
+ try:
+ s.decode('us-ascii')
return True
+ except UnicodeError:
+ pass
return False
-
\f
class Generator:
"""Generates output from a Message object tree.
# We need to test that the string can be converted to unicode and
# back to a byte string, given the input and output codecs of the
# charset.
- if isinstance(s, str):
+ if isinstance(s, bytes):
# Possibly raise UnicodeError if the byte string can't be
# converted to a unicode with the input codec of the charset.
incodec = charset.input_codec or 'us-ascii'
# than the iput coded. Still, use the original byte string.
outcodec = charset.output_codec or 'us-ascii'
ustr.encode(outcodec, errors)
- elif isinstance(s, str):
+ elif isinstance(s, bytes):
# Now we have to be sure the unicode string can be converted
# to a byte string with a reasonable output codec. We want to
# use the byte string in the chunk.
"""Initialize a single-file mailbox."""
Mailbox.__init__(self, path, factory, create)
try:
- f = open(self._path, 'rb+')
+ f = open(self._path, 'r+')
except IOError as e:
if e.errno == errno.ENOENT:
if create:
- f = open(self._path, 'wb+')
+ f = open(self._path, 'w+')
else:
raise NoSuchMailboxError(self._path)
elif e.errno == errno.EACCES:
- f = open(self._path, 'rb')
+ f = open(self._path, 'r')
else:
raise
self._file = f
def read(self, size=None):
"""Read bytes."""
- return self._read(size, self._file.read)
+ return str(self._read(size, self._file.read))
def readline(self, size=None):
"""Read a line."""
- return self._read(size, self._file.readline)
+ return str(self._read(size, self._file.readline))
def readlines(self, sizehint=None):
"""Read multiple lines."""
"""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, 'rb+')
+ return open(path, 'r+')
finally:
os.close(fd)
self._box = self._factory(self._path)
def tearDown(self):
- self._box.close()
self._delete_recursively(self._path)
def test_add(self):
class _TestMboxMMDF(TestMailbox):
def tearDown(self):
- self._box.close()
self._delete_recursively(self._path)
for lock_remnant in glob.glob(self._path + '.*'):
test_support.unlink(lock_remnant)
self._box._file.seek(0)
contents = self._box._file.read()
self._box.close()
- self.assert_(contents == open(self._path, 'rb').read())
+ self.assert_(contents == open(self._path, 'r').read())
self._box = self._factory(self._path)
def test_lock_conflict(self):
_factory = lambda self, path, factory=None: mailbox.Babyl(path, factory)
def tearDown(self):
- self._box.close()
self._delete_recursively(self._path)
for lock_remnant in glob.glob(self._path + '.*'):
test_support.unlink(lock_remnant)