]> granicus.if.org Git - python/commitdiff
Close #12454: The mailbox module is now using ASCII, instead of the locale
authorVictor Stinner <victor.stinner@haypocalc.com>
Mon, 17 Oct 2011 18:44:22 +0000 (20:44 +0200)
committerVictor Stinner <victor.stinner@haypocalc.com>
Mon, 17 Oct 2011 18:44:22 +0000 (20:44 +0200)
encoding, to read and write MH mailboxes (.mh_sequences files).

Lib/mailbox.py
Misc/NEWS

index e23ea8c6329c6a54e460c43b458694c761dedc8c..82d657180fd1e175cdd9a51e8071ec902d3db5e5 100644 (file)
@@ -1108,8 +1108,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')
-        try:
+        with open(os.path.join(self._path, '.mh_sequences'), 'r', encoding='ASCII') as f:
             all_keys = set(self.keys())
             for line in f:
                 try:
@@ -1128,13 +1127,11 @@ class MH(Mailbox):
                 except ValueError:
                     raise FormatError('Invalid sequence specification: %s' %
                                       line.rstrip())
-        finally:
-            f.close()
         return results
 
     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+', encoding='ASCII')
         try:
             os.close(os.open(f.name, os.O_WRONLY | os.O_TRUNC))
             for name, keys in sequences.items():
index fd1e833426fb6098f80127ab5b4fbc0d88b3cebf..abe2e23f8d42bad7f54940d40f3733716620f1c2 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -311,6 +311,9 @@ Core and Builtins
 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
   now available on Windows.