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

Method pack

Lib/mailbox.py:1281–1305  ·  view source on GitHub ↗

Re-name messages to eliminate numbering gaps. Invalidates keys.

(self)

Source from the content-addressed store, hash-verified

1279 _sync_close(f)
1280
1281 def pack(self):
1282 """Re-name messages to eliminate numbering gaps. Invalidates keys."""
1283 sequences = self.get_sequences()
1284 prev = 0
1285 changes = []
1286 for key in self.iterkeys():
1287 if key - 1 != prev:
1288 changes.append((key, prev + 1))
1289 try:
1290 os.link(os.path.join(self._path, str(key)),
1291 os.path.join(self._path, str(prev + 1)))
1292 except (AttributeError, PermissionError):
1293 os.rename(os.path.join(self._path, str(key)),
1294 os.path.join(self._path, str(prev + 1)))
1295 else:
1296 os.unlink(os.path.join(self._path, str(key)))
1297 prev += 1
1298 self._next_key = prev + 1
1299 if len(changes) == 0:
1300 return
1301 for name, key_list in sequences.items():
1302 for old, new in changes:
1303 if old in key_list:
1304 key_list[key_list.index(old)] = new
1305 self.set_sequences(sequences)
1306
1307 def _dump_sequences(self, message, key):
1308 """Inspect a new MHMessage and update sequences appropriately."""

Callers 15

compile_fileFunction · 0.45
writeMethod · 0.45
_write_sizeMethod · 0.45
_write_objectMethod · 0.45
setupcanvasMethod · 0.45
_write_headerMethod · 0.45
_patchheaderMethod · 0.45
_init_write_gzMethod · 0.45
closeMethod · 0.45
_create_headerMethod · 0.45
write32uFunction · 0.45
compressFunction · 0.45

Calls 10

get_sequencesMethod · 0.95
iterkeysMethod · 0.95
set_sequencesMethod · 0.95
strFunction · 0.85
appendMethod · 0.45
joinMethod · 0.45
renameMethod · 0.45
unlinkMethod · 0.45
itemsMethod · 0.45
indexMethod · 0.45

Tested by 4

initGUIMethod · 0.36
createWidgetsMethod · 0.36
showSelectedErrorMethod · 0.36
__init__Method · 0.36