Your IP : 18.119.19.251


Current Path : /opt/alt/python38/lib64/python3.8/__pycache__/
Upload File :
Current File : //opt/alt/python38/lib64/python3.8/__pycache__/mailbox.cpython-38.opt-1.pyc

U

i�fE3�@sRdZddlZddlZddlZddlZddlZddlZddlZddlZddl	Zddl
ZddlZddlZzddl
Z
Wnek
r�dZ
YnXddddddd	d
ddd
ddddddgZej�d�ZGdd�d�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd	�d	ejj�ZGd d
�d
e�ZGd!d"�d"e�ZGd#d�de�ZGd$d�de�ZGd%d
�d
e�Z Gd&d�de�Z!Gd'd(�d(�Z"Gd)d*�d*e"�Z#d=d,d-�Z$d.d/�Z%d0d1�Z&d2d3�Z'd4d5�Z(d6d7�Z)Gd8d�de*�Z+Gd9d�de+�Z,Gd:d�de+�Z-Gd;d�de+�Z.Gd<d�de+�Z/dS)>zDRead/write support for Maildir, mbox, MH, Babyl, and MMDF mailboxes.�N�Mailbox�Maildir�mbox�MH�Babyl�MMDF�Message�MaildirMessage�mboxMessage�	MHMessage�BabylMessage�MMDFMessage�Error�NoSuchMailboxError�
NotEmptyError�ExternalClashError�FormatError�asciic@seZdZdZdCdd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dDdd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�ZdEd0d1�Zd2d3�ZdFd4d5�Zd6d7�Zd8d9�Zd:d;�Zd<d=�Z d>d?�Z!d@Z"dGdAdB�Z#dS)Hrz*A group of messages in a particular place.NTcCs tj�tj�|��|_||_dS)zInitialize a Mailbox instance.N)�os�path�abspath�
expanduser�_path�_factory��selfr�factory�create�r�,/opt/alt/python38/lib64/python3.8/mailbox.py�__init__$szMailbox.__init__cCstd��dS)�$Add message and return assigned key.�&Method must be implemented by subclassN��NotImplementedError�r�messagerrr�add)szMailbox.addcCstd��dS)�=Remove the keyed message; raise KeyError if it doesn't exist.r"Nr#�r�keyrrr�remove-szMailbox.removecCs|�|�dS�N)r+r)rrr�__delitem__1szMailbox.__delitem__cCs(z|�|�Wntk
r"YnXdS�z'If the keyed message exists, remove it.N)r+�KeyErrorr)rrr�discard4szMailbox.discardcCstd��dS)�>Replace the keyed message; raise KeyError if it doesn't exist.r"Nr#�rr*r&rrr�__setitem__;szMailbox.__setitem__cCs*z|�|�WStk
r$|YSXdS)z9Return the keyed message, or default if it doesn't exist.N)�__getitem__r/)rr*�defaultrrr�get?szMailbox.getc
CsB|js|�|�St�|�|���}|�|�W5QR�SQRXdS)z=Return the keyed message; raise KeyError if it doesn't exist.N)r�get_message�
contextlib�closing�get_file)rr*�filerrrr4Fs
zMailbox.__getitem__cCstd��dS)�4Return a Message representation or raise a KeyError.r"Nr#r)rrrr7NszMailbox.get_messagecCst�|�|����S)z�Return a string representation or raise a KeyError.

        Uses email.message.Message to create a 7bit clean string
        representation of the message.��email�message_from_bytes�	get_bytesZ	as_stringr)rrr�
get_stringRszMailbox.get_stringcCstd��dS)z8Return a byte string representation or raise a KeyError.r"Nr#r)rrrr@YszMailbox.get_bytescCstd��dS)�6Return a file-like representation or raise a KeyError.r"Nr#r)rrrr:]szMailbox.get_filecCstd��dS)�Return an iterator over keys.r"Nr#�rrrr�iterkeysaszMailbox.iterkeyscCst|���S)zReturn a list of keys.)�listrErDrrr�keyseszMailbox.keysc	cs>|��D]0}z||}Wntk
r0YqYnX|VqdS)z%Return an iterator over all messages.N�rEr/�rr*�valuerrr�
itervaluesis
zMailbox.itervaluescCs|��Sr,)rKrDrrr�__iter__rszMailbox.__iter__cCst|���S)z,Return a list of messages. Memory intensive.)rFrKrDrrr�valuesuszMailbox.valuesc	csB|��D]4}z||}Wntk
r0YqYnX||fVqdS)z.Return an iterator over (key, message) tuples.NrHrIrrr�	iteritemsys
zMailbox.iteritemscCst|���S)z9Return a list of (key, message) tuples. Memory intensive.)rFrNrDrrr�items�sz
Mailbox.itemscCstd��dS)�9Return True if the keyed message exists, False otherwise.r"Nr#r)rrr�__contains__�szMailbox.__contains__cCstd��dS)�*Return a count of messages in the mailbox.r"Nr#rDrrr�__len__�szMailbox.__len__cCs|��D]}|�|�qdS)zDelete all messages.N)rGr0r)rrr�clear�sz
Mailbox.clearcCs4z||}Wntk
r$|YSX|�|�|S)z3Delete the keyed message and return it, or default.)r/r0)rr*r5�resultrrr�pop�s

zMailbox.popcCs*|��D]}||�|�fStd��dS)z6Delete an arbitrary (key, message) pair and return it.zNo messages in mailboxN)rErVr/r)rrr�popitem�szMailbox.popitemc	Cstt|d�r|��}nt|d�r(|��}n|}d}|D].\}}z|||<Wq4tk
r`d}Yq4Xq4|rptd��dS)z4Change the messages that correspond to certain keys.rNrOFTzNo message with key(s)N)�hasattrrNrOr/)r�arg�sourceZbad_keyr*r&rrr�update�s



zMailbox.updatecCstd��dS)�&Write any pending changes to the disk.r"Nr#rDrrr�flush�sz
Mailbox.flushcCstd��dS)�Lock the mailbox.r"Nr#rDrrr�lock�szMailbox.lockcCstd��dS)�#Unlock the mailbox if it is locked.r"Nr#rDrrr�unlock�szMailbox.unlockcCstd��dS)�Flush and close the mailbox.r"Nr#rDrrr�close�sz
Mailbox.closecCs.z|�d�WStk
r(td��YnXdS)Nrz?String input must be ASCII-only; use bytes or a Message instead)�encode�UnicodeError�
ValueErrorr%rrr�_string_to_bytes�szMailbox._string_to_bytesFc	Cs�t|tjj�rvt��}tj�||d�}|�|�|�	d�|�
�}|�dt�}|�
|�|jrr|�t�sr|�
t��n�t|tttjf��rt|tj�r�t�dtd�|��}t|t�r�|�|�}|r�|�dd�}|�dt�}|�
|�|j�r�|�t��s�|�
t�n�t|d��r�t|d��r2t�d	td�|j}d
}|��}|�d��r\|d
d�d}n|�d
��rx|d
d�d}|�s��q�|�r�|�d��r�d|dd
�}|�dt�}|�
|�|}�q6|j�r�|�r�|�t��s�|�
t�ntdt|���d
S)z%Dump message contents to target file.r�
�8Use of StringIO input is deprecated, use BytesIO instead�s
From s
>From �read�buffer�DUse of text mode files is deprecated, use a binary mode file insteadN�
����
����From s>From ��Invalid message type: %s)�
isinstancer>r&r�io�BytesIO�	generator�BytesGenerator�flatten�seekrk�replace�linesep�write�_append_newline�endswith�str�bytes�StringIO�warnings�warn�DeprecationWarning�getvaluergrXrl�readline�
startswith�	TypeError�type)	rr&�targetZmangle_from_rl�gen�dataZlastline�linerrr�
_dump_message�s`


�


�
zMailbox._dump_message)NT)N)N)N)F)$�__name__�
__module__�__qualname__�__doc__r r'r+r-r0r3r6r4r7rAr@r:rErGrKrLrMrNrOrQrSrTrVrWr[r]r_rarcrgrr�rrrrr!sB

		
	
c@s�eZdZdZdZd6dd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-Zd.d/�Zd0d1�Zd2d3�Zd4d5�ZdS)7rzA qmail-style Maildir mailbox.�:NTcCs�t�||||�tj�|jd�tj�|jd�tj�|jd�d�|_tj�|j�s�|r�t�|jd�|j�	�D]}t�|d�qln
t
|j��i|_ddd�|_d|_
d|_d	S)
zInitialize a Maildir instance.�tmp�new�cur)r�r�r��r)r�r�g�������?N)rr rr�joinr�_paths�exists�mkdirrMr�_toc�_toc_mtimes�
_last_read�_skewfactor)r�dirnamerrrrrrr 
s�
zMaildir.__init__c
Cs~|��}z|�||�Wn*tk
rB|��t�|j��YnXt|�t|t	�r||�
�}|j|��}||jkr�d}nd}d}tj
�|j��|j�d}tj
�|j|||�}t|t	�r�t�|jtj
�|j�|��f�zLzt�|j|�Wn(ttfk
�rt�|j|�YnXt�|j�WnNtk
�rx}z.t�|j�|jtjk�rftd|��n�W5d}~XYnX|S)r!�r�rz$Name clash with existing message: %sN)�_create_tmpr��
BaseExceptionrcrr+�name�_sync_closerur	�
get_subdir�colon�get_infor�basename�splitr�r�utime�getatime�get_date�link�AttributeError�PermissionError�rename�OSError�errnoZEEXISTr)rr&Ztmp_file�subdir�suffix�uniq�dest�errrr'!sF


��zMaildir.addcCs t�tj�|j|�|���dS�r(N)rr+rr�r�_lookupr)rrrr+KszMaildir.removec	Cs,z|�|�Wnttfk
r&YnXdSr.)r+r/�FileNotFoundErrorr)rrrr0OszMaildir.discardcCs�|�|�}|�|�}|�|�}t|t�r.|}n|}tj�|�}|j|kr`|j|�|j�d}nd}|�	|�tj�
|j|�}	tj�
|j|||�}
t|t�r�t�|	tj�
|	�|��f�t�|	|
�dS)r1rqr�N)r�r'rur	rrr�r�r�r0r�rr�r�r�r�)rr*r&Zold_subpathZtemp_keyZtemp_subpathZdominant_subpathr�r�Ztmp_path�new_pathrrrr3Ws$






�zMaildir.__setitem__c	Cs�|�|�}ttj�|j|�d�� }|jr4|�|�}nt|�}W5QRXtj�|�\}}|�	|�|j
|kr�|�|�|j
�d�|�tj�
tj�|j|���|S)r<�rbrq)r��openrrr�rrr	r��
set_subdirr��set_info�set_date�getmtime)rr*Zsubpath�f�msgr�r�rrrr7rs


zMaildir.get_messagec
CsDttj�|j|�|��d��}|���td�W5QR�SQRXdS)�2Return a bytes representation or raise a KeyError.r�rhN)	r�rrr�rr�rkr|r}�rr*r�rrrr@�szMaildir.get_bytescCs$ttj�|j|�|��d�}t|�S)rBr�)r�rrr�rr��
_ProxyFiler�rrrr:�szMaildir.get_filec	csF|��|jD]2}z|�|�Wntk
r8YqYnX|VqdS�rCN)�_refreshr�r�r/r)rrrrE�s

zMaildir.iterkeyscCs|��||jkS�rP)r�r�r)rrrrQ�szMaildir.__contains__cCs|��t|j�S�rR)r��lenr�rDrrrrS�szMaildir.__len__cCsdS)�"Write any pending changes to disk.NrrDrrrr]�sz
Maildir.flushcCsdS)r^NrrDrrrr_�szMaildir.lockcCsdS)r`NrrDrrrra�szMaildir.unlockcCsdS�rbNrrDrrrrc�sz
Maildir.closecCs\g}t�|j�D]F}t|�dkr|ddkrtj�tj�|j|��r|�|dd��q|S)�Return a list of folder names.�r�.N)r�listdirrr�r�isdirr��append�rrU�entryrrr�list_folders�s�zMaildir.list_folderscCs ttj�|jd|�|jdd�S)z/Return a Maildir instance for the named folder.r�F�rr)rrrr�rr�r�folderrrr�
get_folder�s�zMaildir.get_foldercCs\tj�|jd|�}t||jd�}tj�|d�}tj�|�sXt�t�|tj	tj
Bd��|S)z>Create a folder and return a Maildir instance representing it.r��rZ
maildirfolder�)rrr�rrrr�rcr��O_CREAT�O_WRONLY)rr�rrUZmaildirfolder_pathrrr�
add_folder�s�zMaildir.add_foldercCstj�|jd|�}t�tj�|d��t�tj�|d��D](}t|�dksX|ddkr<td|��q<t�|�D]B}|dkrp|dkrp|dkrptj�tj�||��rptd||f��qptj|d	d
�D]F\}}}|D]}t�	tj�||��q�|D]}t�
tj�||��q�q�t�
|�dS)�-Delete the named folder, which must be empty.r�r�r�r�rzFolder contains message(s): %sr�z%Folder contains subdirectory '%s': %sF)�topdownN)rrr�rr�r�rr��walkr+�rmdir)rr�rr��root�dirs�filesrrr�
remove_folder�s&���zMaildir.remove_foldercCsXt��}t�tj�|jd��D]4}tj�|jd|�}|tj�|�dkrt�|�qdS)zDelete old files in "tmp".r�i@�N)�timerr�rr�rr�r+)r�nowr�rrrr�clean�s
z
Maildir.cleanr�cCs�t��}t��}d|kr$|�dd�}d|kr8|�dd�}dt|�t|dd�t��tj|f}tj	�
|jd|�}zt�|�WnFt
k
r�tjd7_zt|�WYStk
r�YnXYnXtd	|��d
S)z=Create a file in the tmp subdirectory and open and return it.�/z\057r�z\072z%s.M%sP%sQ%s.%sr�g��.Ar�z&Name clash prevented file creation: %sN)r��socket�gethostnamer|�intr�getpidr�_countrr�r�statr��_create_carefully�FileExistsErrorr)rr�Zhostnamer�rrrrr��s,��zMaildir._create_tmpcCs�t��|jd|jkr^d}|jD]2}tj�|j|�}||j|krJd}||j|<q"|s^dSi|_|jD]^}|j|}t�	|�D]D}tj�
||�}tj�|�r�q�|�|j
�d}tj�
||�|j|<q�qjt��|_dS)z!Update table of contents mapping.�FTNr)r�r�r�r�rrr�r�r�r�r�r�r�r�)rZrefreshr��mtimerr��pr�rrrr��s&


zMaildir._refreshcCs�z.tj�tj�|j|j|��r,|j|WSWntk
rBYnX|��z|j|WStk
rztd|�d�YnXdS)z=Use TOC to return subpath for given key, or raise a KeyError.�No message with key: %sN)rrr�r�rr�r/r�r)rrrr�#szMaildir._lookupcCsXt|d�s|��|_z|t|j�WStk
r:YdStk
rPYqYqXqdS)z0Return the next message in a one-time iteration.�
_onetime_keysN)rXrEr��next�
StopIterationr/rDrrrr�1s

zMaildir.next)NT)r�r�r�r�r�r r'r+r0r3r7r@r:rErQrSr]r_rarcr�r�r�r�r�r�r�r�r�r�rrrrrs6
*
	
$c@s�eZdZdZd$dd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zd%d d!�Zd"d#�ZdS)&�_singlefileMailboxzA single-file mailbox.NTc
Cs�t�||||�zt|jd�}Wnntk
r�}zP|jtjkr\|rPt|jd�}q~t|j��n"|jtjtj	fkr|t|jd�}n�W5d}~XYnX||_
d|_d|_d|_
d|_d|_d|_dS)z!Initialize a single-file mailbox.�rb+zwb+r�NrF)rr r�rr�r��ENOENTr�EACCES�EROFS�_filer��	_next_key�_pending�
_pending_sync�_locked�_file_length)rrrrr�r�rrrr As$z_singlefileMailbox.__init__cCs8|��|�|�|j|j<|jd7_d|_|jdS)r!r�T)r��_append_messager�rrr%rrrr'Xs
z_singlefileMailbox.addcCs|�|�|j|=d|_dS)r(TN)r�r�rr)rrrr+bs
z_singlefileMailbox.removecCs$|�|�|�|�|j|<d|_dS)r1TN)r�r	r�rr2rrrr3hs
z_singlefileMailbox.__setitem__ccs|��|j��EdHdSr�)r�r�rGrDrrrrEnsz_singlefileMailbox.iterkeyscCs|��||jkSr�)r�r�r)rrrrQssz_singlefileMailbox.__contains__cCs|��t|j�Sr�)r�r�r�rDrrrrSxsz_singlefileMailbox.__len__cCs|jst|j�d|_dS)r^TN)r�
_lock_filerrDrrrr_}s
z_singlefileMailbox.lockcCs|jrt|j�d|_dS�r`FN)r�_unlock_filerrDrrrra�s
z_singlefileMailbox.unlockc
Cs�|js |jrt|j�d|_dS|j�dd�|j��}||jkrTtd|j|f��t|j	�}z�i}|�
|�t|j�
��D]x}|j|\}}|j�|�|�|�|��}|j�td||j����}|s�q�|�|�q�||��f||<|�|�q||��|_Wn"|��t�|j��YnXt|�|j��t�|j	�j}	t�|j|	�zt�|j|j	�Wn2tk
�r�t�|j	�t�|j|j	�YnXt|j	d�|_||_d|_d|_|j�r�t|jdd�dS)	r�FNrr�z4Size of mailbox file changed (expected %i, found %i)�r�)�dotlock) rr�_sync_flushrr{�tellrr�_create_temporaryr�_pre_mailbox_hook�sortedr�rG�_pre_message_hookrk�minr~�_post_message_hookrcrr+r�r�r��st_mode�chmodr�r�r�rr
)
rZcur_lenZnew_fileZnew_tocr*�start�stopZ	new_startrl�moderrrr]�s`
	

�



�
z_singlefileMailbox.flushcCsdS)�,Called before writing the mailbox to file f.Nr�rr�rrrr�sz$_singlefileMailbox._pre_mailbox_hookcCsdS)�-Called before writing each message to file f.Nrrrrrr�sz$_singlefileMailbox._pre_message_hookcCsdS��,Called after writing each message to file f.Nrrrrrr�sz%_singlefileMailbox._post_message_hookcCs4z|��W5z|jr|��W5|j��XXdSr�)rrcrrar]rDrrrrc�sz_singlefileMailbox.closecCsN|jdkr|��|dk	rJz|j|WStk
rHtd|�d�YnXdS)z'Return (start, stop) or raise KeyError.Nr�)r��
_generate_tocr/r)rrrr��s
z_singlefileMailbox._lookupcCs�|j�dd�|j��}t|j�dkr8|js8|�|j�z&|�|j�|�|�}|�	|j�Wn"t
k
r�|j�|��YnX|j��|j��|_
|S)z;Append message to mailbox and return (start, stop) offsets.rr�)rr{rr�r�rrr�_install_messagerr��truncater]r)rr&ZbeforeZoffsetsrrrr	�s


z"_singlefileMailbox._append_message)NT)N)r�r�r�r�r r'r+r3rErQrSr_rar]rrrrcr�r	rrrrr�>s"

@

r�c@sBeZdZdZdZdd�Zddd�Zddd	�Zdd
d�Zdd
�Z	dS)�	_mboxMMDFzAn mbox or MMDF mailbox.TcCsp|�|�\}}|j�|�|j���td�}|j�||j���}|�|�td��}|�	|dd��
d��|S)r<�rhrsNr)r�rr{r�r|r}rkr�_message_factory�set_from�decode)rr*rr�	from_line�stringr�rrrr7sz_mboxMMDF.get_messageFcCst�|�||��j|d�S)�3Return a string representation or raise a KeyError.)�unixfromr=)rr*�from_rrrrAs

��z_mboxMMDF.get_stringcCsJ|�|�\}}|j�|�|s(|j��|j�||j���}|�td�S)r+rh)r�rr{r�rkrr|r})rr*r-rrr*rrrr@s
z_mboxMMDF.get_bytescCs<|�|�\}}|j�|�|s(|j��t|j|j��|�S)rB)r�rr{r��_PartialFiler)rr*r-rrrrrr:s

z_mboxMMDF.get_filecCsd}t|t�r|�|�}t|t�rf|�d�rf|�d�}|dkr\|d|�}||dd�}q�|}d}nJt|t�r�|���d�}d|}n(t|t	j
j�r�|��}|dk	r�|�d�}|dkr�dt
�t
�����}|j��}|j�|t�|�||j|j�|j��}||fS)	z1Format a message and blindly write to self._file.Nrrrhrqr�r%rsFrom MAILER-DAEMON )rur�rgr�r��find�_mboxMMDFMessage�get_fromrdr>r&r�get_unixfromr��asctime�gmtimerrr~r}r��
_mangle_from_)rr&r)�newlineZauthorrrrrrr"&s0







z_mboxMMDF._install_messageN)F)F)F)
r�r�r�r�r5r7rAr@r:r"rrrrr$s


	
r$c@s2eZdZdZdZdZd
dd�Zdd�Zdd	�ZdS)rzA classic mbox mailbox.TNcCst|_t�||||�dS)zInitialize an mbox mailbox.N)r
r&r$r rrrrr Lsz
mbox.__init__cCs|�t�dSr�r~r}rrrrrQszmbox._post_message_hookcCs�gg}}d}|j�d�|j��}|j��}|�d�rzt|�t|�krj|r`|�|tt��n
|�|�|�|�d}q|s�|r�|�|tt��q�|�|�q�q|tkr�d}qd}qtt	t
||���|_t|j�|_|j��|_
dS)�0Generate key-to-(start, stop) table of contents.FrrrTN)rr{rr�r�r�r�r}�dict�	enumerate�zipr�rr)r�starts�stopsZlast_was_empty�line_posr�rrrr!Us.






zmbox._generate_toc)NT)	r�r�r�r�r5rr rr!rrrrrCs
c@s2eZdZdZddd�Zdd�Zdd	�Zd
d�ZdS)
rzAn MMDF mailbox.NTcCst|_t�||||�dS)zInitialize an MMDF mailbox.N)r
r&r$r rrrrr zsz
MMDF.__init__cCs|�dt�dS)r�Nr7rrrrrszMMDF._pre_message_hookcCs|�tdt�dS)r r?Nr7rrrrr�szMMDF._post_message_hookcCs�gg}}|j�d�d}|}|j��}|j��}|�dt�r�|�|�|}|j��}|j��}|dtkr�|�|tt��q�qJ|sJ|�|�q�qJq|sq�qtt	t
||���|_t|j�|_|j�dd�|j��|_
dS)r8rr?r�N)rr{r�rr�r}r�r�r9r:r;r�rr)rr<r=�next_posr>r�rrrr!�s.






zMMDF._generate_toc)NT)r�r�r�r�r rrr!rrrrrws

c@s�eZdZdZd0dd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�ZdS)1rzAn MH mailbox.NTcCstt�||||�tj�|j�sj|r`t�|jd�t�t�tj�	|jd�tj
tjBtjBd��n
t
|j��d|_dS)zInitialize an MH instance.r��
.mh_sequencesi�FN)rr rrr�rr�rcr�r�r��O_EXCLr�rrrrrrr �s�
zMH.__init__cCs�|��}t|�dkrd}nt|�d}tj�|jt|��}t|�}d}z�|j
rVt|�zfz|�
||�Wn:tk
r�|j
r�t|�t	|�d}t�|��YnXt|t�r�|�||�W5|j
r�t|�XW5|s�t	|�X|S)r!rr�FT)rGr��maxrrr�rr�r�r�rr
rr�r�r+rur�_dump_sequences)rr&rGZnew_keyr�r��closedrrrr'�s6


zMH.addc
Csxtj�|jt|��}zt|d�}Wn>tk
r`}z |jtjkrNt	d|��n�W5d}~XYnX|�
�t�|�dS)r(r�r�N)rrr�rr�r�r�r�rr/rcr+)rr*rr�r�rrrr+�sz	MH.removec
Cs�tj�|jt|��}zt|d�}Wn>tk
r`}z |jtjkrNt	d|��n�W5d}~XYnXzd|jrrt|�z@t�t�|tjtjB��|�||�t|t�r�|�||�W5|jr�t
|�XW5t
|�XdS)r1r�r�N)rrr�rr�r�r�r�rr/r�rr
rrcr��O_TRUNCr�rurrD)rr*r&rr�r�rrrr3�s$
zMH.__setitem__c
Cs�z@|jr$ttj�|jt|��d�}nttj�|jt|��d�}Wn>tk
r~}z |jtj	krlt
d|��n�W5d}~XYnX|�2|jr�t|�zt
|�}W5|jr�t|�XW5QRX|����D]\}}||kr�|�|�q�|S)r<r�r�r�N)rr�rrr�rr�r�r�rr/r
rr�
get_sequencesrO�add_sequence)rr*r�r�r�r��key_listrrrr7�s&zMH.get_messagec
Cs�z@|jr$ttj�|jt|��d�}nttj�|jt|��d�}Wn>tk
r~}z |jtj	krlt
d|��n�W5d}~XYnX|�F|jr�t|�z |�
��td�W�W5QR�S|jr�t|�XW5QRXdS)r�r�r�r�Nrh)rr�rrr�rr�r�r�rr/r
rrkr|r}�rr*r�r�rrrr@s zMH.get_bytesc
Csfzttj�|jt|��d�}Wn>tk
r\}z |jtjkrJt	d|��n�W5d}~XYnXt
|�S)rBr�r�N)r�rrr�rr�r�r�rr/r�rJrrrr:)szMH.get_filecCsttdd�t�|j�D���S)rCcss|]}|��rt|�VqdSr,)�isdigitr�)�.0r�rrr�	<genexpr>6s�zMH.iterkeys.<locals>.<genexpr>)�iterrrr�rrDrrrrE4szMH.iterkeyscCstj�tj�|jt|���Sr�)rrr�r�rr�r)rrrrQ9szMH.__contains__cCstt|����Sr�)r�rFrErDrrrrS=sz
MH.__len__cCs2|js.ttj�|jd�d�|_t|j�d|_dS)r^rAr�TN)rr�rrr�rrr
rDrrrr_As
zMH.lockcCs(|jr$t|j�t|j�|`d|_dSr)rrrr�rDrrrraHs


z	MH.unlockcCsdS)r\NrrDrrrr]PszMH.flushcCs|jr|��dSr�)rrarDrrrrcTszMH.closecCs<g}t�|j�D]&}tj�tj�|j|��r|�|�q|S)r�)rr�rrr�r�r�r�rrrr�Ys
zMH.list_folderscCsttj�|j|�|jdd�S)z+Return an MH instance for the named folder.Fr��rrrr�rrr�rrrr�as�z
MH.get_foldercCsttj�|j|�|jd�S)z:Create a folder and return an MH instance representing it.r�rOr�rrrr�fs�z
MH.add_foldercCs`tj�|j|�}t�|�}|dgkr:t�tj�|d��n|gkrDntd|j��t�|�dS)r�rAzFolder not empty: %sN)rrr�rr�r+rr�)rr�r�entriesrrrr�ks

zMH.remove_folderc

si}ttj�|jd�ddd���}t|����|D]�}z�|�d�\}}t�}|��D]H}|��rn|�	t
|��qRdd�|�d�D�\}}	|�t||	d	��qR�fd
d�t
|�D�||<t||�dkr�||=Wq0tk
r�td
|����Yq0Xq0W5QRX|S)z=Return a name-to-key-list dictionary to define each sequence.rA�r�ASCII��encodingr�css|]}t|�VqdSr,)r�)rL�xrrrrM�sz#MH.get_sequences.<locals>.<genexpr>�-r�csg|]}|�kr|�qSrr)rLr*�Zall_keysrr�
<listcomp>�s�z$MH.get_sequences.<locals>.<listcomp>rz"Invalid sequence specification: %s)r�rrr�r�setrGr�rKr'r�r[�rangerr�rfr�rstrip)
rZresultsr�r�r��contentsrG�specrrrrWrrGws(
�zMH.get_sequencescCsttj�|jd�ddd�}z�t�t�|jtjtj	B��|�
�D]�\}}t|�dkrVq@|�|d�d}d}t
t|��D]R}|d	|kr�|s�d
}|�d�n*|r�d}|�d||f�n|�d
|�|}qx|r�|�t|�d�q@|�d�q@W5t|�XdS)z:Set sequences using the given name-to-key-list dictionary.rAzr+rRrSrr�NFr�TrVz%s %sz %s�
)r�rrr�rr�rcr�r�rFrOr�r~rrYr�)r�	sequencesr�r�rG�prevZ
completingr*rrr�
set_sequences�s.zMH.set_sequencesc	
Cs>|��}d}g}|��D]�}|d|kr�|�||df�z4t�tj�|jt|��tj�|jt|d���WnHt	t
fk
r�t�tj�|jt|��tj�|jt|d���YnXt�tj�|jt|���|d7}q|d|_
t|�dkr�dS|��D]0\}}|D]"\}}||k�r
|||�|�<�q
q�|�|�dS)z?Re-name messages to eliminate numbering gaps. Invalidates keys.rr�N)rGrEr�rr�rr�rr�r�r�r��unlinkrr�rO�indexra)	rr_r`Zchangesr*r�rI�oldr�rrr�pack�s0��



zMH.packcCst|��}|��}|��D]0\}}||kr4|�|�q||kr||�|�=q|D]}||krN|g||<qN|�|�dS)z;Inspect a new MHMessage and update sequences appropriately.N)rGrOr�rcra)rr&r*Zpending_sequencesZ
all_sequencesr�rI�sequencerrrrD�szMH._dump_sequences)NT)r�r�r�r�r r'r+r3r7r@r:rErQrSr_rar]rcr�r�r�r�rGrarerDrrrrr�s.
"c@s�eZdZdZedddddddh�Zd%dd�Zd
d�Zdd�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd �Zd!d"�Zd#d$�Zd	S)&rzAn Rmail-style Babyl mailbox.�unseen�deletedZfiled�answered�	forwardedZedited�resentNTcCst�||||�i|_dS)zInitialize a Babyl mailbox.N)r�r �_labelsrrrrr �szBabyl.__init__cCs(t�||�}t|t�r$|��|j|<|S)r!)r�r'rur�
get_labelsrl)rr&r*rrrr'�s
z	Babyl.addcCs"t�||�||jkr|j|=dSr�)r�r+rlr)rrrr+�s
zBabyl.removecCs*t�|||�t|t�r&|��|j|<dS)r1N)r�r3rurrmrlr2rrrr3�s
zBabyl.__setitem__c
Cs�|�|�\}}|j�|�|j��t��}|j��}|dtks\|sHq\|�|�td��q,t��}|j��}|tks�|s|q�|�|�td��qd||j�	�}|j�
|�}|�td�}t|��|�}	|	�
|���||jkr�|	�|j|�|	S)r<�*** EOOH ***rh)r�rr{r�rvrwr}r~r|rrkrr��set_visiblerl�
set_labels)
rr*rr�original_headersr�Zvisible_headers�nZbodyr�rrrr7�s*



zBabyl.get_messagec	Cs�|�|�\}}|j�|�|j��t��}|j��}|dtks\|sHq\|�|�td��q,|j��}|tksv|s\qvq\|�	�}||j�
�}|j�|�}|�td�}||S)r+rnrh)r�rr{r�rvrwr}r~r|r�rrk)	rr*rrrqr�Zheadersrrr�rrrr@s 


zBabyl.get_bytescCst�|�|��dt��S)rBrh)rvrwr@r|r}r)rrrr:%szBabyl.get_filecCs<|��t�}|j��D]}|�|�q|�|j�t|�S)z4Return a list of user-defined labels in the mailbox.)r�rYrlrMr[�difference_update�_special_labelsrF)r�labelsZ
label_listrrrrm)szBabyl.get_labelscCs:gg}}|j�d�d}g}|}|j��}|j��}|dtkr�t|�t|�krd|�|tt��|�|�dd�|j��dd��d�D�}|�|�q|dks�|dtkr�t|�t|�kr�|�|tt��q|s|�|tt��q�qtt	t
||���|_tt	|��|_t|j�|_
|j�dd	�|j��|_dS)
r8rscSsg|]}|��r|���qSr)�strip�rL�labelrrrrX@s�z'Babyl._generate_toc.<locals>.<listcomp>r�N�,�r�)rr{r�rr}r�r�r�r9r:r;r�rlrr)rr<r=r@Zlabel_listsr>r�rurrrr!2s4



�zBabyl._generate_toccCsVdt}|dt7}|��}dd�|D�}|dd�|�t7}|d7}|�|�dS)	rsBABYL OPTIONS:s
Version: 5css|]}|��VqdSr,)rdrwrrrrMUsz*Babyl._pre_mailbox_hook.<locals>.<genexpr>sLabels:ryrzN)r}rmr�r~)rr�ZbabylrurrrrPszBabyl._pre_mailbox_hookcCs|�dt�dS)r�Nr7rrrrrZszBabyl._pre_message_hookcCs|�td�dS)r rzNr7rrrrr^szBabyl._post_message_hookcCsx|j��}t|t�r�g}g}|��D]$}||jkr>|�|�q$|�|�q$|j�d�|D]}|j�d|���qZ|j�d�|D]}|j�d|��d�q�|j�t	�n|j�dt	�t|t
jj��rt
��}t
j�|dd�}|�|�|�d�|��}|j�|�d	t	��|d	k�s,|s��q,q�|j�d
t	�t|t��r�t
��}	t
j�|	dd�}
|
�|���|	��}|j�|�d	t	��|d	k�s�|�sn�q�qnn>|�d�|��}|j�|�d	t	��|d	k�s�|�s��q�q�|�d�}|�s��qf|j�|�d	t	���q�nTt|ttt
jf��rt|t
j��rJt�dtd
�|��}t|t��r`|�|�}|�d�d}|ddk�r�|j�|d|��d	t	��|j�d
t	�|j�|d|��d	t	��|j�||d��d	t	��n(|j�d
t	t	�|j�|�d	t	���nXt |d��rVt |d��r:t�dtd
�|j!}|��}
d}|��}|�"d��rl|dd�d	}n|�"d��r�|dd�d	}|j�|�d	t	��|d	k�s�|�sF|�r�d}|j�d
t	�|�|
�n�qڐqF|��}|�s�qf|�"d��r
|dd�t	}n:|�"d��r(|dd�t	}n|�"d	��rD|dd�t	}|j�|��q�nt#dt$|���|j��}||fS)z0Write message contents and return (start, stop).�1s, s,,� rys1,,Frrhrnr
rirjs

r�rqNr�rlrmTrnrorprt)%rrrurrmrtr�r~rdr}r>r&rrvrwrxryrzr{r�r|�get_visiblerkr�r�r�r�r�r�r�rgr/rXrlr�r�r�)rr&rZspecial_labelsrurxZorig_bufferZorig_generatorr�Z
vis_bufferZ
vis_generatorrlZ
body_startZoriginal_posZ
first_passrrrrr"bs�







�
�
zBabyl._install_message)NT)r�r�r�r��	frozensetrtr r'r+r3r7r@r:rmr!rrrr"rrrrr�s&
�
	
c@s*eZdZdZd	dd�Zdd�Zdd�ZdS)
rz0Message with mailbox-format-specific properties.NcCs�t|tjj�r4|�t�|��t|t�r�|�|�n�t|t�rP|�t�	|��n~t|t
�rl|�t�|��nbt|tj
�r�|�t�|��nDt|d�r�|�t�|��n(|dkr�tjj�|�ntdt|���dS)zInitialize a Message instance.rkNrt)rur>r&r�_become_message�copyZdeepcopy�_explain_tor�r?r�Zmessage_from_stringrv�
TextIOWrapperZmessage_from_filerXZmessage_from_binary_filer r�r�r%rrrr �s



zMessage.__init__cCs4t|dg�}|jD]}||kr|j||j|<qdS)z0Assume the non-format-specific state of message.�_type_specific_attributesN)�getattr�__dict__)rr&Z
type_specificr�rrrr��s
zMessage._become_messagecCst|t�rdStd��dS)z:Copy format-specific state to message insofar as possible.Nz Cannot convert to specified type)rurr�r%rrrr��s
zMessage._explain_to)N)r�r�r�r�r r�r�rrrrr�s
c@s|eZdZdZdddgZddd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�ZdS)r	z)Message with Maildir-specific properties.�_subdir�_info�_dateNcCs&d|_d|_t��|_t�||�dS)z%Initialize a MaildirMessage instance.r�r�N)r�r�r�r�rr r%rrrr �s
zMaildirMessage.__init__cCs|jS)zReturn 'new' or 'cur'.)r�rDrrrr��szMaildirMessage.get_subdircCs(|dks|dkr||_ntd|��dS)zSet subdir to 'new' or 'cur'.r�r�z!subdir must be 'new' or 'cur': %sN)r�rf)rr�rrrr�szMaildirMessage.set_subdircCs"|j�d�r|jdd�SdSdS)�*Return as a string the flags that are set.�2,r�Nr�)r�r�rDrrr�	get_flags
szMaildirMessage.get_flagscCsdd�t|��|_dS)�)Set the given flags and unset all others.r�r�N)r�rr�)r�flagsrrr�	set_flagsszMaildirMessage.set_flagscCs$|�d�t|���t|�B��dS�z.Set the given flag(s) without changing others.r�N�r�r�rYr��r�flagrrr�add_flagszMaildirMessage.add_flagcCs,|��r(|�d�t|���t|���dS)�7Unset the given string flag(s) without changing others.r�N)r�r�r�rYr�rrr�remove_flagszMaildirMessage.remove_flagcCs|jS)z<Return delivery date of message, in seconds since the epoch.)r�rDrrrr�szMaildirMessage.get_datecCs6zt|�|_Wn"tk
r0td|�d�YnXdS)z9Set delivery date of message, in seconds since the epoch.zcan't convert to float: %sN)�floatr�rfr�)r�daterrrr�"szMaildirMessage.set_datecCs|jS)z%Get the message's "info" as a string.)r�rDrrrr�)szMaildirMessage.get_infocCs&t|t�r||_ntdt|���dS)z Set the message's "info" string.zinfo must be a string: %sN)rur�r�r�r�)r�inforrrr�-s
zMaildirMessage.set_infocCs�t|t�r8|�|���|�|���|�|����nht|t�r�t	|���}d|kr`|�
d�|��dkrv|�
d�d|kr�|�
d�d|kr�|�
d�d|kr�|�
d�|�d	t�
|����n�t|t��rt	|���}d|kr�|�d
�d|k�r|�d�d|k�r�|�d�n�t|t��r�t	|���}d|k�rD|�d
�d|k�rX|�d
�d|k�rl|�d�d|k�r�|�d�nt|t��r�ntdt|���dS)z;Copy Maildir-specific state to message insofar as possible.�S�Rr��O�T�D�F�A�
MAILER-DAEMONrg�replied�flaggedrhri�Prj�$Cannot convert to specified type: %sN)rur	r�r�r�r�r�r�r0rYr�r'r�r4rrHr�	add_labelrr�r�)rr&r�rrrr�4sP

















�zMaildirMessage._explain_to)N)r�r�r�r�r�r r�r�r�r�r�r�r�r�r�r�r�rrrrr	�s

c@sZeZdZdZdgZddd�Zdd�Zddd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�ZdS)r0z/Message with mbox- or MMDF-specific properties.�_fromNcCsV|�dd�t|tjj�rF|��}|dk	rF|�d�rF|�|dd��t�||�dS)z'Initialize an mboxMMDFMessage instance.r�TNzFrom rs)r'rur>r&rr2r�r )rr&r,rrrr esz_mboxMMDFMessage.__init__cCs|jS)z Return contents of "From " line.)r�rDrrrr1nsz_mboxMMDFMessage.get_fromcCs4|dk	r*|dkrt��}|dt�|�7}||_dS)z>Set "From " line, formatting and appending time_ if specified.NT� )r�r4r3r�)rr-Ztime_rrrr'rs
z_mboxMMDFMessage.set_fromcCs|�dd�|�dd�S)r��Statusr��X-Status)r6rDrrrr�zsz_mboxMMDFMessage.get_flagscCs�t|�}d\}}dD]}||kr||7}|�|�qdD]}||kr8||7}|�|�q8|d�t|��7}z|�d|�Wn tk
r�|�d|�YnXz|�d|�Wn tk
r�|�d|�YnXdS)r�)r�r�)r�r�)r�r�r�r�r�r�N)rYr+r�r�replace_headerr/Z
add_header)rr�Zstatus_flagsZ
xstatus_flagsr�rrrr�~s&z_mboxMMDFMessage.set_flagscCs$|�d�t|���t|�B��dSr�r�r�rrrr��sz_mboxMMDFMessage.add_flagcCs4d|ksd|kr0|�d�t|���t|���dS)r�r�r�r�Nr�r�rrrr��sz_mboxMMDFMessage.remove_flagc	Cs�t|t�r�t|���}d|kr(|�d�d|kr:|�d�d|krL|�d�d|kr^|�d�d|krp|�d�|d	=|d
=d�|����dd
��}z|�	t
�t�
|d���Wnttfk
r�YnX�n
t|t�r�|�|���|�|���n�t|t��rZt|���}d|k�r$|�d�d|k�r8|�d�d|k�rL|�d�|d	=|d
=n�t|t��r�t|���}d|k�r�|�d�d|k�r�|�d�d|k�r�|�d�|d	=|d
=nt|t��r�ntdt|���d
S)zACopy mbox- or MMDF-specific state to message insofar as possible.r�r�r�r�r�r�r�r�Zstatuszx-statusr����Nz%a %b %d %H:%M:%S %Yrgr�r�rhrir�)rur	rYr�r�r�r�r1r�r��calendarZtimegmr��strptimerf�
OverflowErrorr0r�r'rrHrr�rr�r�)rr&r�Z
maybe_daterrrr��sb





�













�z_mboxMMDFMessage._explain_to)N)N)
r�r�r�r�r�r r1r'r�r�r�r�r�rrrrr0`s
	
r0c@seZdZdZdS)r
z&Message with mbox-specific properties.N�r�r�r�r�rrrrr
�sc@sHeZdZdZdgZddd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dS)rz$Message with MH-specific properties.�
_sequencesNcCsg|_t�||�dS)z!Initialize an MHMessage instance.N)r�rr r%rrrr �szMHMessage.__init__cCs|jdd�S)z4Return a list of sequences that include the message.N)r�rDrrrrG�szMHMessage.get_sequencescCst|�|_dS)z3Set the list of sequences that include the message.N)rFr�)rr_rrrra�szMHMessage.set_sequencescCs6t|t�r"||jkr2|j�|�ntdt|���dS)z8Add sequence to list of sequences including the message.zsequence type must be str: %sN)rur�r�r�r�r��rrfrrrrH�s

zMHMessage.add_sequencecCs*z|j�|�Wntk
r$YnXdS)zARemove sequence from the list of sequences including the message.N)r�r+rfr�rrr�remove_sequence�szMHMessage.remove_sequencecCsFt|t�rdt|���}d|kr*|�d�n|�d�|�d�d|krP|�d�d|krb|�d�n�t|t�r�t|���}d|kr�|�d�n
|�d	�d|kr�|�d�d|kr�|�d
�n�t|t�r�|��D]}|�|�q�n`t|t	��r$t|���}d|k�r|�
d�d|k�rB|�
d�nt|t��r2ntdt
|���d
S)z6Copy MH-specific state to message insofar as possible.rgr�r�r�r�r�r��ROr�r�rir�N)rur	rYrGr�r�r0rrHrr�rr�r�)rr&r_rfrrrr��sB










�zMHMessage._explain_to)N)r�r�r�r�r�r rGrarHr�r�rrrrr�s
c@sbeZdZdZddgZddd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dS)rz'Message with Babyl-specific properties.rl�_visibleNcCsg|_t�|_t�||�dS)z#Initialize a BabylMessage instance.N)rlrr�r r%rrrr "szBabylMessage.__init__cCs|jdd�S)z'Return a list of labels on the message.N)rlrDrrrrm(szBabylMessage.get_labelscCst|�|_dS)z&Set the list of labels on the message.N)rFrl)rrurrrrp,szBabylMessage.set_labelscCs6t|t�r"||jkr2|j�|�ntdt|���dS)z+Add label to list of labels on the message.zlabel must be a string: %sN)rur�rlr�r�r��rrxrrrr�0s

zBabylMessage.add_labelcCs*z|j�|�Wntk
r$YnXdS)z4Remove label from the list of labels on the message.N)rlr+rfr�rrr�remove_label8szBabylMessage.remove_labelcCs
t|j�S)z3Return a Message representation of visible headers.�rr�rDrrrr~?szBabylMessage.get_visiblecCst|�|_dS)z2Set the Message representation of visible headers.Nr�)rZvisiblerrrroCszBabylMessage.set_visiblecCsb|j��D](}||kr*|j�|||�q
|j|=q
dD]$}||kr8||jkr8|||j|<q8dS)z9Update and/or sensibly generate a set of visible headers.)ZDateZFromzReply-ToZToZCCZSubjectN)r�rGr�)r�headerrrr�update_visibleGs
zBabylMessage.update_visiblecCsrt|t�r~t|���}d|kr*|�d�n|�d�|�d�d|ksNd|krX|�d�d|krj|�d�d	|kr||�d
�n�t|t�r�t|���}d|kr�|�d�n
|�d�d	|kr�|�d
�d|kr�|�d�n�t|t��rt|���}d|k�r|�d�d|k�rn|�d�nTt|t	��rP|�
|���|��D]}|�|��q<nt|t
��r^ntdt|���dS)z9Copy Babyl-specific state to message insofar as possible.rgr�r�rjrkr�rir�rhr�r�r�r�r�r�r�N)rur	rYrmr�r�r0rrHrror~r�rr�r�)rr&rurxrrrr�RsH










�zBabylMessage._explain_to)N)r�r�r�r�r�r rmrpr�r�r~ror�r�rrrrrs
c@seZdZdZdS)r
z&Message with MMDF-specific properties.Nr�rrrrr
|sc@s�eZdZdZd&dd�Zd'dd�Zd(dd�Zd)d	d
�Zd*dd�Zd
d�Z	dd�Z
d+dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zed$d%��ZdS),r�zA read-only wrapper of a file.NcCs$||_|dkr|��|_n||_dS)zInitialize a _ProxyFile.N)rr�_pos)rr��posrrrr �sz_ProxyFile.__init__cCs|�||jj�S�zRead bytes.)�_readrrk�r�sizerrrrk�sz_ProxyFile.readcCs|�||jj�Sr�)r�r�read1r�rrrr��sz_ProxyFile.read1cCs|�||jj�S)zRead a line.)r�rr�r�rrrr��sz_ProxyFile.readlinecCs<g}|D].}|�|�|dk	r|t|�8}|dkrq8q|S)zRead multiple lines.Nr)r�r�)r�sizehintrUr�rrr�	readlines�s
z_ProxyFile.readlinesccs|��}|sdS|VqdS)zIterate over lines.N)r�)rr�rrrrL�sz_ProxyFile.__iter__cCs|jS)zReturn the position.)r�rDrrrr�sz_ProxyFile.tellrcCs4|dkr|j�|j�|j�||�|j��|_dS)zChange position.r�N�rr{r�r�r�offset�whencerrrr{�sz_ProxyFile.seekcCs0t|d�r,zt|jd�r"|j��W5|`XdS)zClose the file.rrcN)rXrrcrDrrrrc�s

z_ProxyFile.closecCs2|dkrd}|j�|j�||�}|j��|_|S)z"Read size bytes using read_method.Nrqr�)rr��read_methodrUrrrr��sz_ProxyFile._readcCs|S)z$Context management protocol support.rrDrrr�	__enter__�sz_ProxyFile.__enter__cGs|��dSr,)rc)r�excrrr�__exit__�sz_ProxyFile.__exit__cCs
|j��Sr,)r�readablerDrrrr��sz_ProxyFile.readablecCs
|j��Sr,)r�writablerDrrrr��sz_ProxyFile.writablecCs
|j��Sr,)r�seekablerDrrrr��sz_ProxyFile.seekablecCs
|j��Sr,)rr]rDrrrr]�sz_ProxyFile.flushcCs&t|d�sdSt|jd�sdS|jjS)NrTrEF)rXrrErDrrrrE�s

z_ProxyFile.closed)N)N)N)N)N)r)r�r�r�r�r rkr�r�r�rLrr{rcr�r�r�r�r�r�r]�propertyrErrrrr��s&





		r�c@s<eZdZdZddd�Zdd�Zddd	�Zd
d�Zdd
�ZdS)r.z&A read-only wrapper of part of a file.NcCst�|||�||_||_dS)zInitialize a _PartialFile.N)r�r �_start�_stop)rr�rrrrrr �sz_PartialFile.__init__cCst�|�|jS)z*Return the position with respect to start.)r�rr�rDrrrr�sz_PartialFile.tellrcCs<|dkr|j|_d}n|dkr*|j|_d}t�|||�dS)z8Change position, possibly with respect to start or stop.rr�r�N)r�r�r�r�r{r�rrrr{�sz_PartialFile.seekcCsB|j|j}|dkrdS|dks0|dks0||kr4|}t�|||�S)z;Read size bytes using read_method, honoring start and stop.rr%N)r�r�r�r�)rr�r�Z	remainingrrrr��sz_PartialFile._readcCst|d�r|`dS)Nr)rXrrDrrrrcs
z_PartialFile.close)NN)r)	r�r�r�r�r rr{r�rcrrrrr.�s


	r.Tc
Cs�d}�zbtrpzt�|tjtjB�WnJtk
rn}z,|jtjtjtjfkr\t	d|j
��n�W5d}~XYnX|�rfzt|j
d�}|��WnBtk
r�}z$|jtjtjfkr�WY�WdS�W5d}~XYnXz`zt
�|j
|j
d�d}Wn2ttfk
�r$t
�|j
|j
d�d}YnXt
�|j
�Wn0tk
�rdt
�|j
�t	d|j
��YnXWn8t�r�t�|tj�|�r�t
�|j
d��YnXdS)z(Lock file f using lockf and dot locking.Fzlockf: lock unavailable: %sN�.lockTzdot lock unavailable: %s)�fcntl�lockfZLOCK_EXZLOCK_NBr�r�ZEAGAINrrrr�rrcrr�r�r�r�rbr�r+�LOCK_UN)r�rZdotlock_doner�Zpre_lockrrrr

sL�
�r
cCs8trt�|tj�tj�|jd�r4t�|jd�dS)z*Unlock file f using lockf and dot locking.r�N)r�r�r�rrr�r�r+�r�rrrr4src	Cs<t�|tjtjBtjBd�}zt|d�W�St�|�XdS)zCCreate a file if it doesn't exist and open for reading and writing.r�r�N)rr�r�rB�O_RDWRrc)r�fdrrrr�;sr�cCs$td|tt���t��t��f�S)zBCreate a temp file based on path and open for reading and writing.z%s.%s.%s.%s)r�r�r�r�r�rr�)rrrrrCs�rcCs$|��ttd�r t�|���dS)z0Ensure changes to file f are physically on disk.�fsyncN)r]rXrr��filenor�rrrrIs
rcCst|�|��dS)z:Close file f, ensuring all changes are physically on disk.N)rrcr�rrrr�Osr�c@seZdZdZdS)rz"Raised for module-specific errors.Nr�rrrrrUsc@seZdZdZdS)rz:The specified mailbox does not exist and won't be created.Nr�rrrrrXsc@seZdZdZdS)rz>The specified mailbox is not empty and deletion was requested.Nr�rrrrr[sc@seZdZdZdS)rz)Another process caused an action to fail.Nr�rrrrr^sc@seZdZdZdS)rz)A file appears to have an invalid format.Nr�rrrrras)T)0r�rr�r�r�r�r�r�r>Z
email.messageZemail.generatorrvr8r��ImportError�__all__r}rdrrr�r$rrrrr&rr	r0r
rrr
r�r.r
rr�rrr��	Exceptionrrrrrrrrr�<module>s�
�h8DB4-3z%mqH_c'
*

?>