MCPcopy Index your code
hub / github.com/python/cpython / add

Method add

Lib/mailbox.py:1014–1046  ·  view source on GitHub ↗

Add message and return assigned key.

(self, message)

Source from the content-addressed store, hash-verified

1012 self._locked = False
1013
1014 def add(self, message):
1015 """Add message and return assigned key."""
1016 keys = self.keys()
1017 if len(keys) == 0:
1018 new_key = 1
1019 else:
1020 new_key = max(keys) + 1
1021 new_path = os.path.join(self._path, str(new_key))
1022 f = _create_carefully(new_path)
1023 closed = False
1024 try:
1025 if self._locked:
1026 _lock_file(f)
1027 try:
1028 try:
1029 self._dump_message(message, f)
1030 except BaseException:
1031 # Unlock and close so it can be deleted on Windows
1032 if self._locked:
1033 _unlock_file(f)
1034 _sync_close(f)
1035 closed = True
1036 os.remove(new_path)
1037 raise
1038 if isinstance(message, MHMessage):
1039 self._dump_sequences(message, new_key)
1040 finally:
1041 if self._locked:
1042 _unlock_file(f)
1043 finally:
1044 if not closed:
1045 _sync_close(f)
1046 return new_key
1047
1048 def remove(self, key):
1049 """Remove the keyed message; raise KeyError if it doesn't exist."""

Callers 15

conf.pyFile · 0.45
testFunction · 0.45
handle_starttagMethod · 0.45
mainFunction · 0.45
add_eventMethod · 0.45
toMethod · 0.45
highlightLineMethod · 0.45
pushFrameMethod · 0.45
createStackCloneMethod · 0.45
_updateMissedCountMethod · 0.45
_togglePlayPauseMethod · 0.45

Calls 10

_dump_sequencesMethod · 0.95
strFunction · 0.85
_create_carefullyFunction · 0.85
_lock_fileFunction · 0.85
_unlock_fileFunction · 0.85
_sync_closeFunction · 0.85
_dump_messageMethod · 0.80
keysMethod · 0.45
joinMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected