MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / add

Method add

tools/python-3.11.9-amd64/Lib/mailbox.py:951–983  ·  view source on GitHub ↗

Add message and return assigned key.

(self, message)

Source from the content-addressed store, hash-verified

949 self._locked = False
950
951 def add(self, message):
952 """Add message and return assigned key."""
953 keys = self.keys()
954 if len(keys) == 0:
955 new_key = 1
956 else:
957 new_key = max(keys) + 1
958 new_path = os.path.join(self._path, str(new_key))
959 f = _create_carefully(new_path)
960 closed = False
961 try:
962 if self._locked:
963 _lock_file(f)
964 try:
965 try:
966 self._dump_message(message, f)
967 except BaseException:
968 # Unlock and close so it can be deleted on Windows
969 if self._locked:
970 _unlock_file(f)
971 _sync_close(f)
972 closed = True
973 os.remove(new_path)
974 raise
975 if isinstance(message, MHMessage):
976 self._dump_sequences(message, new_key)
977 finally:
978 if self._locked:
979 _unlock_file(f)
980 finally:
981 if not closed:
982 _sync_close(f)
983 return new_key
984
985 def remove(self, key):
986 """Remove the keyed message; raise KeyError if it doesn't exist."""

Callers 15

_addFunction · 0.45
os.pyFile · 0.45
global_matchesMethod · 0.45
attr_matchesMethod · 0.45
optimizeFunction · 0.45
registerMethod · 0.45
_getmembersFunction · 0.45
classify_class_attrsFunction · 0.45
getclosurevarsFunction · 0.45
wrapperFunction · 0.45
__init__Method · 0.45
_set_tstate_lockMethod · 0.45

Calls 11

_dump_sequencesMethod · 0.95
maxFunction · 0.85
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