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