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

Method add

Lib/mailbox.py:292–332  ·  view source on GitHub ↗

Add message and return assigned key.

(self, message)

Source from the content-addressed store, hash-verified

290 self._skewfactor = 0.1 # Adjust if os/fs clocks are skewing
291
292 def add(self, message):
293 """Add message and return assigned key."""
294 tmp_file = self._create_tmp()
295 try:
296 self._dump_message(message, tmp_file)
297 except BaseException:
298 tmp_file.close()
299 os.remove(tmp_file.name)
300 raise
301 _sync_close(tmp_file)
302 if isinstance(message, MaildirMessage):
303 subdir = message.get_subdir()
304 suffix = self.colon + message.get_info()
305 if suffix == self.colon:
306 suffix = ''
307 else:
308 subdir = 'new'
309 suffix = ''
310 uniq = os.path.basename(tmp_file.name).split(self.colon)[0]
311 dest = os.path.join(self._path, subdir, uniq + suffix)
312 if isinstance(message, MaildirMessage):
313 os.utime(tmp_file.name,
314 (os.path.getatime(tmp_file.name), message.get_date()))
315 # No file modification should be done after the file is moved to its
316 # final position in order to prevent race conditions with changes
317 # from other programs
318 try:
319 try:
320 os.link(tmp_file.name, dest)
321 except (AttributeError, PermissionError):
322 os.rename(tmp_file.name, dest)
323 else:
324 os.remove(tmp_file.name)
325 except OSError as e:
326 os.remove(tmp_file.name)
327 if e.errno == errno.EEXIST:
328 raise ExternalClashError('Name clash with existing message: %s'
329 % dest)
330 else:
331 raise
332 return uniq
333
334 def remove(self, key):
335 """Remove the keyed message; raise KeyError if it doesn't exist."""

Callers 1

__setitem__Method · 0.95

Calls 15

_create_tmpMethod · 0.95
_sync_closeFunction · 0.85
isinstanceFunction · 0.85
ExternalClashErrorClass · 0.85
_dump_messageMethod · 0.80
get_subdirMethod · 0.80
basenameMethod · 0.80
utimeMethod · 0.80
get_dateMethod · 0.80
closeMethod · 0.45
removeMethod · 0.45
get_infoMethod · 0.45

Tested by

no test coverage detected