Close #12454: The mailbox module is now using ASCII, instead of the locale

encoding, to read and write MH mailboxes (.mh_sequences files).
This commit is contained in:
Victor Stinner 2011-10-17 20:44:22 +02:00
parent 9ea8e4c29d
commit 5c267e2d22
2 changed files with 5 additions and 5 deletions

View File

@ -1108,8 +1108,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') with open(os.path.join(self._path, '.mh_sequences'), 'r', encoding='ASCII') as f:
try:
all_keys = set(self.keys()) all_keys = set(self.keys())
for line in f: for line in f:
try: try:
@ -1128,13 +1127,11 @@ class MH(Mailbox):
except ValueError: except ValueError:
raise FormatError('Invalid sequence specification: %s' % raise FormatError('Invalid sequence specification: %s' %
line.rstrip()) line.rstrip())
finally:
f.close()
return results return results
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+', encoding='ASCII')
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():

View File

@ -311,6 +311,9 @@ Core and Builtins
Library Library
------- -------
- Issue #12454: The mailbox module is now using ASCII, instead of the locale
encoding, to read and write MH mailboxes (.mh_sequences files).
- Issue #13194: zlib.compressobj().copy() and zlib.decompressobj().copy() are - Issue #13194: zlib.compressobj().copy() and zlib.decompressobj().copy() are
now available on Windows. now available on Windows.