Create a file in the tmp subdirectory and open and return it.
(self)
| 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.""" |