MCPcopy Index your code
hub / github.com/RustPython/RustPython / add

Method add

Lib/mailbox.py:1007–1039  ·  view source on GitHub ↗

Add message and return assigned key.

(self, message)

Source from the content-addressed store, hash-verified

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

Callers 15

add_outputFunction · 0.45
index.jsFile · 0.45
_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
__init__Method · 0.45

Calls 13

_dump_sequencesMethod · 0.95
lenFunction · 0.85
maxFunction · 0.85
strFunction · 0.85
_create_carefullyFunction · 0.85
_lock_fileFunction · 0.85
_unlock_fileFunction · 0.85
_sync_closeFunction · 0.85
isinstanceFunction · 0.85
_dump_messageMethod · 0.80
keysMethod · 0.45
joinMethod · 0.45

Tested by 1

test_importsMethod · 0.36