Initialize a single-file mailbox.
(self, path, factory=None, create=True)
| 630 | """A single-file mailbox.""" |
| 631 | |
| 632 | def __init__(self, path, factory=None, create=True): |
| 633 | """Initialize a single-file mailbox.""" |
| 634 | Mailbox.__init__(self, path, factory, create) |
| 635 | try: |
| 636 | f = open(self._path, 'rb+') |
| 637 | except OSError as e: |
| 638 | if e.errno == errno.ENOENT: |
| 639 | if create: |
| 640 | f = open(self._path, 'wb+') |
| 641 | else: |
| 642 | raise NoSuchMailboxError(self._path) |
| 643 | elif e.errno in (errno.EACCES, errno.EROFS): |
| 644 | f = open(self._path, 'rb') |
| 645 | else: |
| 646 | raise |
| 647 | self._file = f |
| 648 | self._toc = None |
| 649 | self._next_key = 0 |
| 650 | self._pending = False # No changes require rewriting the file. |
| 651 | self._pending_sync = False # No need to sync the file |
| 652 | self._locked = False |
| 653 | self._file_length = None # Used to record mailbox size |
| 654 | |
| 655 | def add(self, message): |
| 656 | """Add message and return assigned key.""" |
nothing calls this directly
no test coverage detected