Back to index

python3.2  3.2.2
Public Member Functions | Private Member Functions | Static Private Attributes
mailbox._mboxMMDF Class Reference
Inheritance diagram for mailbox._mboxMMDF:
Inheritance graph
[legend]
Collaboration diagram for mailbox._mboxMMDF:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def get_message
def get_string
def get_bytes
def get_file
def add
def remove
def __setitem__
def iterkeys
def __contains__
def __len__
def lock
def unlock
def flush
def close
def __delitem__
def discard
def get
def __getitem__
def get_string
def get_bytes
def get_file
def keys
def itervalues
def __iter__
def values
def iteritems
def items
def clear
def pop
def popitem
def update

Private Member Functions

def _install_message

Static Private Attributes

 _mangle_from_ = True

Detailed Description

An mbox or MMDF mailbox.

Definition at line 748 of file mailbox.py.


Member Function Documentation

def mailbox._singlefileMailbox.__contains__ (   self,
  key 
) [inherited]
Return True if the keyed message exists, False otherwise.

Reimplemented from mailbox.Mailbox.

Definition at line 622 of file mailbox.py.

00622 
00623     def __contains__(self, key):
00624         """Return True if the keyed message exists, False otherwise."""
00625         self._lookup()
00626         return key in self._toc

Here is the call graph for this function:

def mailbox.Mailbox.__delitem__ (   self,
  key 
) [inherited]

Definition at line 54 of file mailbox.py.

00054 
00055     def __delitem__(self, key):
00056         self.remove(key)

Here is the call graph for this function:

def mailbox.Mailbox.__getitem__ (   self,
  key 
) [inherited]
Return the keyed message; raise KeyError if it doesn't exist.

Definition at line 75 of file mailbox.py.

00075 
00076     def __getitem__(self, key):
00077         """Return the keyed message; raise KeyError if it doesn't exist."""
00078         if not self._factory:
00079             return self.get_message(key)
00080         else:
00081             with contextlib.closing(self.get_file(key)) as file:
00082                 return self._factory(file)

Here is the call graph for this function:

Here is the caller graph for this function:

def mailbox.Mailbox.__iter__ (   self) [inherited]

Definition at line 119 of file mailbox.py.

00119 
00120     def __iter__(self):
00121         return self.itervalues()

Here is the call graph for this function:

def mailbox._singlefileMailbox.__len__ (   self) [inherited]
Return a count of messages in the mailbox.

Reimplemented from mailbox.Mailbox.

Definition at line 627 of file mailbox.py.

00627 
00628     def __len__(self):
00629         """Return a count of messages in the mailbox."""
00630         self._lookup()
00631         return len(self._toc)

Here is the call graph for this function:

def mailbox._singlefileMailbox.__setitem__ (   self,
  key,
  message 
) [inherited]
Replace the keyed message; raise KeyError if it doesn't exist.

Reimplemented from mailbox.Mailbox.

Reimplemented in mailbox.Babyl.

Definition at line 610 of file mailbox.py.

00610 
00611     def __setitem__(self, key, message):
00612         """Replace the keyed message; raise KeyError if it doesn't exist."""
00613         self._lookup(key)
00614         self._toc[key] = self._append_message(message)
00615         self._pending = True

Here is the call graph for this function:

def mailbox._mboxMMDF._install_message (   self,
  message 
) [private]
Format a message and blindly write to self._file.

Definition at line 785 of file mailbox.py.

00785 
00786     def _install_message(self, message):
00787         """Format a message and blindly write to self._file."""
00788         from_line = None
00789         if isinstance(message, str):
00790             message = self._string_to_bytes(message)
00791         if isinstance(message, bytes) and message.startswith(b'From '):
00792             newline = message.find(b'\n')
00793             if newline != -1:
00794                 from_line = message[:newline]
00795                 message = message[newline + 1:]
00796             else:
00797                 from_line = message
00798                 message = b''
00799         elif isinstance(message, _mboxMMDFMessage):
00800             author = message.get_from().encode('ascii')
00801             from_line = b'From ' + author
00802         elif isinstance(message, email.message.Message):
00803             from_line = message.get_unixfrom()  # May be None.
00804             if from_line is not None:
00805                 from_line = from_line.encode('ascii')
00806         if from_line is None:
00807             from_line = b'From MAILER-DAEMON ' + time.asctime(time.gmtime()).encode()
00808         start = self._file.tell()
00809         self._file.write(from_line + linesep)
00810         self._dump_message(message, self._file, self._mangle_from_)
00811         stop = self._file.tell()
00812         return (start, stop)
00813 

Here is the call graph for this function:

Here is the caller graph for this function:

def mailbox._singlefileMailbox.add (   self,
  message 
) [inherited]
Add message and return assigned key.

Reimplemented from mailbox.Mailbox.

Reimplemented in mailbox.Babyl.

Definition at line 596 of file mailbox.py.

00596 
00597     def add(self, message):
00598         """Add message and return assigned key."""
00599         self._lookup()
00600         self._toc[self._next_key] = self._append_message(message)
00601         self._next_key += 1
00602         self._pending = True
00603         return self._next_key - 1

Here is the call graph for this function:

Here is the caller graph for this function:

def mailbox.Mailbox.clear (   self) [inherited]
Delete all messages.

Definition at line 147 of file mailbox.py.

00147 
00148     def clear(self):
00149         """Delete all messages."""
00150         for key in self.keys():
00151             self.discard(key)

Here is the call graph for this function:

def mailbox._singlefileMailbox.close (   self) [inherited]
Flush and close the mailbox.

Reimplemented from mailbox.Mailbox.

Definition at line 714 of file mailbox.py.

00714 
00715     def close(self):
00716         """Flush and close the mailbox."""
00717         self.flush()
00718         if self._locked:
00719             self.unlock()
00720         self._file.close()  # Sync has been done by self.flush() above.

Here is the call graph for this function:

Here is the caller graph for this function:

def mailbox.Mailbox.discard (   self,
  key 
) [inherited]
If the keyed message exists, remove it.

Reimplemented in mailbox.Maildir.

Definition at line 57 of file mailbox.py.

00057 
00058     def discard(self, key):
00059         """If the keyed message exists, remove it."""
00060         try:
00061             self.remove(key)
00062         except KeyError:
00063             pass

Here is the call graph for this function:

Here is the caller graph for this function:

def mailbox._singlefileMailbox.flush (   self) [inherited]
Write any pending changes to disk.

Reimplemented from mailbox.Mailbox.

Definition at line 644 of file mailbox.py.

00644 
00645     def flush(self):
00646         """Write any pending changes to disk."""
00647         if not self._pending:
00648             return
00649 
00650         # In order to be writing anything out at all, self._toc must
00651         # already have been generated (and presumably has been modified
00652         # by adding or deleting an item).
00653         assert self._toc is not None
00654 
00655         # Check length of self._file; if it's changed, some other process
00656         # has modified the mailbox since we scanned it.
00657         self._file.seek(0, 2)
00658         cur_len = self._file.tell()
00659         if cur_len != self._file_length:
00660             raise ExternalClashError('Size of mailbox file changed '
00661                                      '(expected %i, found %i)' %
00662                                      (self._file_length, cur_len))
00663 
00664         new_file = _create_temporary(self._path)
00665         try:
00666             new_toc = {}
00667             self._pre_mailbox_hook(new_file)
00668             for key in sorted(self._toc.keys()):
00669                 start, stop = self._toc[key]
00670                 self._file.seek(start)
00671                 self._pre_message_hook(new_file)
00672                 new_start = new_file.tell()
00673                 while True:
00674                     buffer = self._file.read(min(4096,
00675                                                  stop - self._file.tell()))
00676                     if not buffer:
00677                         break
00678                     new_file.write(buffer)
00679                 new_toc[key] = (new_start, new_file.tell())
00680                 self._post_message_hook(new_file)
00681         except:
00682             new_file.close()
00683             os.remove(new_file.name)
00684             raise
00685         _sync_close(new_file)
00686         # self._file is about to get replaced, so no need to sync.
00687         self._file.close()
00688         try:
00689             os.rename(new_file.name, self._path)
00690         except OSError as e:
00691             if e.errno == errno.EEXIST or \
00692               (os.name == 'os2' and e.errno == errno.EACCES):
00693                 os.remove(self._path)
00694                 os.rename(new_file.name, self._path)
00695             else:
00696                 raise
00697         self._file = open(self._path, 'rb+')
00698         self._toc = new_toc
00699         self._pending = False
00700         if self._locked:
00701             _lock_file(self._file, dotlock=False)

Here is the call graph for this function:

Here is the caller graph for this function:

def mailbox.Mailbox.get (   self,
  key,
  default = None 
) [inherited]
Return the keyed message, or default if it doesn't exist.

Definition at line 68 of file mailbox.py.

00068 
00069     def get(self, key, default=None):
00070         """Return the keyed message, or default if it doesn't exist."""
00071         try:
00072             return self.__getitem__(key)
00073         except KeyError:
00074             return default

Here is the call graph for this function:

Here is the caller graph for this function:

def mailbox.Mailbox.get_bytes (   self,
  key 
) [inherited]
Return a byte string representation or raise a KeyError.

Reimplemented in mailbox.Babyl, mailbox.MH, and mailbox.Maildir.

Definition at line 94 of file mailbox.py.

00094 
00095     def get_bytes(self, key):
00096         """Return a byte string representation or raise a KeyError."""
00097         raise NotImplementedError('Method must be implemented by subclass')

Here is the caller graph for this function:

def mailbox._mboxMMDF.get_bytes (   self,
  key,
  from_ = False 
)
Return a string representation or raise a KeyError.

Definition at line 768 of file mailbox.py.

00768 
00769     def get_bytes(self, key, from_=False):
00770         """Return a string representation or raise a KeyError."""
00771         start, stop = self._lookup(key)
00772         self._file.seek(start)
00773         if not from_:
00774             self._file.readline()
00775         string = self._file.read(stop - self._file.tell())
00776         return string.replace(linesep, b'\n')

Here is the call graph for this function:

def mailbox.Mailbox.get_file (   self,
  key 
) [inherited]
Return a file-like representation or raise a KeyError.

Reimplemented in mailbox.Babyl, test.test_mailbox.FakeMailBox, mailbox.MH, and mailbox.Maildir.

Definition at line 98 of file mailbox.py.

00098 
00099     def get_file(self, key):
00100         """Return a file-like representation or raise a KeyError."""
00101         raise NotImplementedError('Method must be implemented by subclass')

Here is the caller graph for this function:

def mailbox._mboxMMDF.get_file (   self,
  key,
  from_ = False 
)
Return a file-like representation or raise a KeyError.

Definition at line 777 of file mailbox.py.

00777 
00778     def get_file(self, key, from_=False):
00779         """Return a file-like representation or raise a KeyError."""
00780         start, stop = self._lookup(key)
00781         self._file.seek(start)
00782         if not from_:
00783             self._file.readline()
00784         return _PartialFile(self._file, self._file.tell(), stop)

Here is the call graph for this function:

def mailbox._mboxMMDF.get_message (   self,
  key 
)
Return a Message representation or raise a KeyError.

Reimplemented from mailbox.Mailbox.

Definition at line 753 of file mailbox.py.

00753 
00754     def get_message(self, key):
00755         """Return a Message representation or raise a KeyError."""
00756         start, stop = self._lookup(key)
00757         self._file.seek(start)
00758         from_line = self._file.readline().replace(linesep, b'')
00759         string = self._file.read(stop - self._file.tell())
00760         msg = self._message_factory(string.replace(linesep, b'\n'))
00761         msg.set_from(from_line[5:].decode('ascii'))
00762         return msg

Here is the call graph for this function:

def mailbox.Mailbox.get_string (   self,
  key 
) [inherited]
Return a string representation or raise a KeyError.

Uses email.message.Message to create a 7bit clean string
representation of the message.

Definition at line 87 of file mailbox.py.

00087 
00088     def get_string(self, key):
00089         """Return a string representation or raise a KeyError.
00090 
00091         Uses email.message.Message to create a 7bit clean string
00092         representation of the message."""
00093         return email.message_from_bytes(self.get_bytes(key)).as_string()

Here is the call graph for this function:

def mailbox._mboxMMDF.get_string (   self,
  key,
  from_ = False 
)
Return a string representation or raise a KeyError.

Definition at line 763 of file mailbox.py.

00763 
00764     def get_string(self, key, from_=False):
00765         """Return a string representation or raise a KeyError."""
00766         return email.message_from_bytes(
00767             self.get_bytes(key)).as_string(unixfrom=from_)

Here is the call graph for this function:

def mailbox.Mailbox.items (   self) [inherited]
Return a list of (key, message) tuples. Memory intensive.

Definition at line 135 of file mailbox.py.

00135 
00136     def items(self):
00137         """Return a list of (key, message) tuples. Memory intensive."""
00138         return list(self.iteritems())

Here is the call graph for this function:

Here is the caller graph for this function:

def mailbox.Mailbox.iteritems (   self) [inherited]
Return an iterator over (key, message) tuples.

Definition at line 126 of file mailbox.py.

00126 
00127     def iteritems(self):
00128         """Return an iterator over (key, message) tuples."""
00129         for key in self.keys():
00130             try:
00131                 value = self[key]
00132             except KeyError:
00133                 continue
00134             yield (key, value)

Here is the call graph for this function:

Here is the caller graph for this function:

def mailbox._singlefileMailbox.iterkeys (   self) [inherited]
Return an iterator over keys.

Reimplemented from mailbox.Mailbox.

Definition at line 616 of file mailbox.py.

00616 
00617     def iterkeys(self):
00618         """Return an iterator over keys."""
00619         self._lookup()
00620         for key in self._toc.keys():
00621             yield key

Here is the call graph for this function:

Here is the caller graph for this function:

def mailbox.Mailbox.itervalues (   self) [inherited]
Return an iterator over all messages.

Definition at line 110 of file mailbox.py.

00110 
00111     def itervalues(self):
00112         """Return an iterator over all messages."""
00113         for key in self.keys():
00114             try:
00115                 value = self[key]
00116             except KeyError:
00117                 continue
00118             yield value

Here is the call graph for this function:

Here is the caller graph for this function:

def mailbox.Mailbox.keys (   self) [inherited]
Return a list of keys.

Definition at line 106 of file mailbox.py.

00106 
00107     def keys(self):
00108         """Return a list of keys."""
00109         return list(self.iterkeys())

Here is the call graph for this function:

Here is the caller graph for this function:

def mailbox._singlefileMailbox.lock (   self) [inherited]
Lock the mailbox.

Reimplemented from mailbox.Mailbox.

Definition at line 632 of file mailbox.py.

00632 
00633     def lock(self):
00634         """Lock the mailbox."""
00635         if not self._locked:
00636             _lock_file(self._file)
00637             self._locked = True

Here is the call graph for this function:

Here is the caller graph for this function:

def mailbox.Mailbox.pop (   self,
  key,
  default = None 
) [inherited]
Delete the keyed message and return it, or default.

Definition at line 152 of file mailbox.py.

00152 
00153     def pop(self, key, default=None):
00154         """Delete the keyed message and return it, or default."""
00155         try:
00156             result = self[key]
00157         except KeyError:
00158             return default
00159         self.discard(key)
00160         return result

Here is the call graph for this function:

Here is the caller graph for this function:

def mailbox.Mailbox.popitem (   self) [inherited]
Delete an arbitrary (key, message) pair and return it.

Definition at line 161 of file mailbox.py.

00161 
00162     def popitem(self):
00163         """Delete an arbitrary (key, message) pair and return it."""
00164         for key in self.keys():
00165             return (key, self.pop(key))     # This is only run once.
00166         else:
00167             raise KeyError('No messages in mailbox')

Here is the call graph for this function:

def mailbox._singlefileMailbox.remove (   self,
  key 
) [inherited]
Remove the keyed message; raise KeyError if it doesn't exist.

Reimplemented from mailbox.Mailbox.

Reimplemented in mailbox.Babyl.

Definition at line 604 of file mailbox.py.

00604 
00605     def remove(self, key):
00606         """Remove the keyed message; raise KeyError if it doesn't exist."""
00607         self._lookup(key)
00608         del self._toc[key]
00609         self._pending = True

Here is the call graph for this function:

Here is the caller graph for this function:

def mailbox._singlefileMailbox.unlock (   self) [inherited]
Unlock the mailbox if it is locked.

Reimplemented from mailbox.Mailbox.

Definition at line 638 of file mailbox.py.

00638 
00639     def unlock(self):
00640         """Unlock the mailbox if it is locked."""
00641         if self._locked:
00642             _unlock_file(self._file)
00643             self._locked = False

Here is the call graph for this function:

def mailbox.Mailbox.update (   self,
  arg = None 
) [inherited]
Change the messages that correspond to certain keys.

Definition at line 168 of file mailbox.py.

00168 
00169     def update(self, arg=None):
00170         """Change the messages that correspond to certain keys."""
00171         if hasattr(arg, 'iteritems'):
00172             source = arg.items()
00173         elif hasattr(arg, 'items'):
00174             source = arg.items()
00175         else:
00176             source = arg
00177         bad_key = False
00178         for key, message in source:
00179             try:
00180                 self[key] = message
00181             except KeyError:
00182                 bad_key = True
00183         if bad_key:
00184             raise KeyError('No message with key(s)')

Here is the caller graph for this function:

def mailbox.Mailbox.values (   self) [inherited]
Return a list of messages. Memory intensive.

Definition at line 122 of file mailbox.py.

00122 
00123     def values(self):
00124         """Return a list of messages. Memory intensive."""
00125         return list(self.itervalues())

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

mailbox._mboxMMDF._mangle_from_ = True [static, private]

Reimplemented in mailbox.mbox.

Definition at line 751 of file mailbox.py.


The documentation for this class was generated from the following file: