'Lock the account, throwing an exception if it is locked already.'

def __lock(self):

    self._lockfd = open(self._lockfilepath, 'w')
    try:
        fcntl.lockf(self._lockfd, (fcntl.LOCK_EX | fcntl.LOCK_NB))
    except NameError:
        pass
    except IOError:
        self._lockfd.close()
        six.reraise(OfflineImapError, OfflineImapError(('Could    not    lock    account    %s.    Is    another    instance    using    this    account?' % self), OfflineImapError.ERROR.REPO), exc_info()[2])
