(self, key, message)
Replace the keyed message; raise KeyError if it doesn't exist.
Replace the keyed message; raise KeyError if it doesn't exist.
Replace the keyed message ; raise KeyError if it doesn t exist .
def __setitem__(self, key, message):
        """Replace the keyed message; raise KeyError if it doesn't exist."""
        old_subpath = self._lookup(key)
        temp_key = self.add(message)
        temp_subpath = self._lookup(temp_key)
        if isinstance(message, MaildirMessage):
            # temp's subdir and suffix were specified by message.
            dominant_subpath = temp_subpath
        else:
            # temp's subdir and suffix were defaults from add().
            dominant_subpath = old_subpath
        subdir = os.path.dirname(dominant_subpath)
        if self.colon in dominant_subpath:
            suffix = self.colon + dominant_subpath.split(self.colon)[-1]
        else:
            suffix = ''
        self.discard(key)
        tmp_path = os.path.join(self._path, temp_subpath)
        new_path = os.path.join(self._path, subdir, key + suffix)
        if isinstance(message, MaildirMessage):
            os.utime(tmp_path,
                     (os.path.getatime(tmp_path), message.get_date()))
        # No file modification should be done after the file is moved to its
        # final position in order to prevent race conditions with changes
        # from other programs
        os.rename(tmp_path, new_path)
def __setitem__ ( self , key , message ) : old_subpath = self . _lookup ( key ) temp_key = self . add ( message ) temp_subpath = self . _lookup ( temp_key ) if isinstance ( message , MaildirMessage ) : # temp's subdir and suffix were specified by message. dominant_subpath = temp_subpath else : # temp's subdir and suffix were defaults from add(). dominant_subpath = old_subpath subdir = os . path . dirname ( dominant_subpath ) if self . colon in dominant_subpath : suffix = self . colon + dominant_subpath . split ( self . colon ) [ - 1 ] else : suffix = '' self . discard ( key ) tmp_path = os . path . join ( self . _path , temp_subpath ) new_path = os . path . join ( self . _path , subdir , key + suffix ) if isinstance ( message , MaildirMessage ) : os . utime ( tmp_path , ( os . path . getatime ( tmp_path ) , message . get_date ( ) ) ) # No file modification should be done after the file is moved to its # final position in order to prevent race conditions with changes # from other programs os . rename ( tmp_path , new_path )