Back to index

python3.2  3.2.2
Classes | Functions | Variables
mailbox Namespace Reference

Classes

class  Mailbox
class  Maildir
class  _singlefileMailbox
class  _mboxMMDF
class  mbox
class  MMDF
class  MH
class  Babyl
class  Message
class  MaildirMessage
class  _mboxMMDFMessage
class  mboxMessage
class  MHMessage
class  BabylMessage
class  MMDFMessage
class  _ProxyFile
class  _PartialFile
class  Error
class  NoSuchMailboxError
class  NotEmptyError
class  ExternalClashError
class  FormatError

Functions

def _lock_file
def _unlock_file
def _create_carefully
def _create_temporary
def _sync_flush
def _sync_close

Variables

 fcntl = None
list __all__
tuple linesep = os.linesep.encode('ascii')

Function Documentation

def mailbox._create_carefully (   path) [private]
Create a file if it doesn't exist and open for reading and writing.

Definition at line 2059 of file mailbox.py.

02059 
02060 def _create_carefully(path):
02061     """Create a file if it doesn't exist and open for reading and writing."""
02062     fd = os.open(path, os.O_CREAT | os.O_EXCL | os.O_RDWR, 0o666)
02063     try:
02064         return open(path, 'rb+')
02065     finally:
02066         os.close(fd)

Here is the caller graph for this function:

def mailbox._create_temporary (   path) [private]
Create a temp file based on path and open for reading and writing.

Definition at line 2067 of file mailbox.py.

02067 
02068 def _create_temporary(path):
02069     """Create a temp file based on path and open for reading and writing."""
02070     return _create_carefully('%s.%s.%s.%s' % (path, int(time.time()),
02071                                               socket.gethostname(),
02072                                               os.getpid()))

Here is the call graph for this function:

Here is the caller graph for this function:

def mailbox._lock_file (   f,
  dotlock = True 
) [private]
Lock file f using lockf and dot locking.

Definition at line 2007 of file mailbox.py.

02007 
02008 def _lock_file(f, dotlock=True):
02009     """Lock file f using lockf and dot locking."""
02010     dotlock_done = False
02011     try:
02012         if fcntl:
02013             try:
02014                 fcntl.lockf(f, fcntl.LOCK_EX | fcntl.LOCK_NB)
02015             except IOError as e:
02016                 if e.errno in (errno.EAGAIN, errno.EACCES, errno.EROFS):
02017                     raise ExternalClashError('lockf: lock unavailable: %s' %
02018                                              f.name)
02019                 else:
02020                     raise
02021         if dotlock:
02022             try:
02023                 pre_lock = _create_temporary(f.name + '.lock')
02024                 pre_lock.close()
02025             except IOError as e:
02026                 if e.errno in (errno.EACCES, errno.EROFS):
02027                     return  # Without write access, just skip dotlocking.
02028                 else:
02029                     raise
02030             try:
02031                 if hasattr(os, 'link'):
02032                     os.link(pre_lock.name, f.name + '.lock')
02033                     dotlock_done = True
02034                     os.unlink(pre_lock.name)
02035                 else:
02036                     os.rename(pre_lock.name, f.name + '.lock')
02037                     dotlock_done = True
02038             except OSError as e:
02039                 if e.errno == errno.EEXIST or \
02040                   (os.name == 'os2' and e.errno == errno.EACCES):
02041                     os.remove(pre_lock.name)
02042                     raise ExternalClashError('dot lock unavailable: %s' %
02043                                              f.name)
02044                 else:
02045                     raise
02046     except:
02047         if fcntl:
02048             fcntl.lockf(f, fcntl.LOCK_UN)
02049         if dotlock_done:
02050             os.remove(f.name + '.lock')
02051         raise

Here is the call graph for this function:

Here is the caller graph for this function:

def mailbox._sync_close (   f) [private]
Close file f, ensuring all changes are physically on disk.

Definition at line 2079 of file mailbox.py.

02079 
02080 def _sync_close(f):
02081     """Close file f, ensuring all changes are physically on disk."""
02082     _sync_flush(f)
02083     f.close()
02084 

Here is the call graph for this function:

Here is the caller graph for this function:

def mailbox._sync_flush (   f) [private]
Ensure changes to file f are physically on disk.

Definition at line 2073 of file mailbox.py.

02073 
02074 def _sync_flush(f):
02075     """Ensure changes to file f are physically on disk."""
02076     f.flush()
02077     if hasattr(os, 'fsync'):
02078         os.fsync(f.fileno())

Here is the caller graph for this function:

def mailbox._unlock_file (   f) [private]
Unlock file f using lockf and dot locking.

Definition at line 2052 of file mailbox.py.

02052 
02053 def _unlock_file(f):
02054     """Unlock file f using lockf and dot locking."""
02055     if fcntl:
02056         fcntl.lockf(f, fcntl.LOCK_UN)
02057     if os.path.exists(f.name + '.lock'):
02058         os.remove(f.name + '.lock')

Here is the caller graph for this function:


Variable Documentation

Initial value:
00001 [ 'Mailbox', 'Maildir', 'mbox', 'MH', 'Babyl', 'MMDF',
00002             'Message', 'MaildirMessage', 'mboxMessage', 'MHMessage',
00003             'BabylMessage', 'MMDFMessage']

Definition at line 32 of file mailbox.py.

mailbox.fcntl = None

Definition at line 30 of file mailbox.py.

tuple mailbox.linesep = os.linesep.encode('ascii')

Definition at line 36 of file mailbox.py.