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