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

Method _create_tmp

Lib/mailbox.py:547–569  ·  view source on GitHub ↗

Create a file in the tmp subdirectory and open and return it.

(self)

Source from the content-addressed store, hash-verified

545 _count = 1 # This is used to generate unique file names.
546
547 def _create_tmp(self):
548 """Create a file in the tmp subdirectory and open and return it."""
549 now = time.time()
550 hostname = socket.gethostname()
551 if '/' in hostname:
552 hostname = hostname.replace('/', r'\057')
553 if ':' in hostname:
554 hostname = hostname.replace(':', r'\072')
555 uniq = "%s.M%sP%sQ%s.%s" % (int(now), int(now % 1 * 1e6), os.getpid(),
556 Maildir._count, hostname)
557 path = os.path.join(self._path, 'tmp', uniq)
558 try:
559 os.stat(path)
560 except FileNotFoundError:
561 Maildir._count += 1
562 try:
563 return _create_carefully(path)
564 except FileExistsError:
565 pass
566
567 # Fall through to here if stat succeeded or open raised EEXIST.
568 raise ExternalClashError('Name clash prevented file creation: %s' %
569 path)
570
571 def _refresh(self):
572 """Update table of contents mapping."""

Callers 2

addMethod · 0.95
test_create_tmpMethod · 0.80

Calls 6

_create_carefullyFunction · 0.85
ExternalClashErrorClass · 0.85
timeMethod · 0.45
replaceMethod · 0.45
joinMethod · 0.45
statMethod · 0.45

Tested by 1

test_create_tmpMethod · 0.64