AlkantarClanX12

Your IP : 18.222.56.71


Current Path : /opt/alt/python310/lib64/python3.10/__pycache__/
Upload File :
Current File : //opt/alt/python310/lib64/python3.10/__pycache__/mailbox.cpython-310.pyc

o

6��f�3�@s>dZddlZddlZddlZddlZddlZddlZddlZddlZddl	Zddl
ZddlZddlZddl
mZzddlZWneyIdZYnwgd�Zej�d�ZGdd�d�ZGdd	�d	e�ZGd
d�de�ZGdd
�d
e�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�dejj�ZGdd�de�ZGdd�de�ZGdd�de�Z Gdd�de�Z!Gd d!�d!e�Z"Gd"d#�d#e�Z#Gd$d%�d%�Z$Gd&d'�d'e$�Z%d?d)d*�Z&d+d,�Z'd-d.�Z(d/d0�Z)d1d2�Z*d3d4�Z+Gd5d6�d6e,�Z-Gd7d8�d8e-�Z.Gd9d:�d:e-�Z/Gd;d<�d<e-�Z0Gd=d>�d>e-�Z1dS)@zDRead/write support for Maildir, mbox, MH, Babyl, and MMDF mailboxes.�N)�GenericAlias)�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/�ZdDd0d1�Zd2d3�ZdDd4d5�Zd6d7�Zd8d9�Zd:d;�Zd<d=�Z d>d?�Z!d@Z"dEdAdB�Z#e$e%�Z&dS)Frz*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/python310/lib64/python3.10/mailbox.py�__init__%s
zMailbox.__init__cC�td��)�$Add message and return assigned key.�&Method must be implemented by subclass��NotImplementedError�r�messagerrr �add*�zMailbox.addcCr")�=Remove the keyed message; raise KeyError if it doesn't exist.r$r%�r�keyrrr �remove.r*zMailbox.removecCs|�|�dS�N)r.r,rrr �__delitem__2szMailbox.__delitem__cCs&z|�|�WdStyYdSw�z'If the keyed message exists, remove it.N)r.�KeyErrorr,rrr �discard5s
�zMailbox.discardcCr")�>Replace the keyed message; raise KeyError if it doesn't exist.r$r%�rr-r(rrr �__setitem__<r*zMailbox.__setitem__cCs$z|�|�WSty|YSw)z9Return the keyed message, or default if it doesn't exist.)�__getitem__r2)rr-�defaultrrr �get@s
�zMailbox.getcCsN|js|�|�St�|�|���
}|�|�Wd�S1s wYdS)z=Return the keyed message; raise KeyError if it doesn't exist.N)r�get_message�
contextlib�closing�get_file)rr-�filerrr r7Gs

$�zMailbox.__getitem__cCr")�4Return a Message representation or raise a KeyError.r$r%r,rrr r:Or*zMailbox.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_stringSszMailbox.get_stringcCr")z8Return a byte string representation or raise a KeyError.r$r%r,rrr rCZr*zMailbox.get_bytescCr")�6Return a file-like representation or raise a KeyError.r$r%r,rrr r=^r*zMailbox.get_filecCr")�Return an iterator over keys.r$r%�rrrr �iterkeysbr*zMailbox.iterkeyscC�t|���S)zReturn a list of keys.)�listrHrGrrr �keysf�zMailbox.keysc	cs:�|��D]}z||}Wn	tyYqw|VqdS)z%Return an iterator over all messages.N�rHr2�rr-�valuerrr �
itervaluesjs���zMailbox.itervaluescCs|��Sr/)rPrGrrr �__iter__sszMailbox.__iter__cCrI)z,Return a list of messages. Memory intensive.)rJrPrGrrr �valuesvrLzMailbox.valuesc	cs>�|��D]}z||}Wn	tyYqw||fVqdS)z.Return an iterator over (key, message) tuples.NrMrNrrr �	iteritemszs���zMailbox.iteritemscCrI)z9Return a list of (key, message) tuples. Memory intensive.)rJrSrGrrr �items�rLz
Mailbox.itemscCr")�9Return True if the keyed message exists, False otherwise.r$r%r,rrr �__contains__�r*zMailbox.__contains__cCr")�*Return a count of messages in the mailbox.r$r%rGrrr �__len__�r*zMailbox.__len__cCs|��D]}|�|�qdS)zDelete all messages.N)rKr3r,rrr �clear�s�z
Mailbox.clearcCs2z||}Wnty|YSw|�|�|S)z3Delete the keyed message and return it, or default.)r2r3)rr-r8�resultrrr �pop�s�
zMailbox.popcCs&|��D]
}||�|�fStd��)z6Delete an arbitrary (key, message) pair and return it.zNo messages in mailbox)rHr[r2r,rrr �popitem�szMailbox.popitemc	Cspt|d�r
|��}nt|d�r|��}n|}d}|D]\}}z|||<Wqty/d}Yqw|r6td��dS)z4Change the messages that correspond to certain keys.rSrTFTzNo message with key(s)N)�hasattrrSrTr2)r�arg�sourceZbad_keyr-r(rrr �update�s



��zMailbox.updatecCr")�&Write any pending changes to the disk.r$r%rGrrr �flush�r*z
Mailbox.flushcCr")�Lock the mailbox.r$r%rGrrr �lock�r*zMailbox.lockcCr")�#Unlock the mailbox if it is locked.r$r%rGrrr �unlock�r*zMailbox.unlockcCr")�Flush and close the mailbox.r$r%rGrrr �close�r*z
Mailbox.closecCs$z|�d�WStytd��w)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�r?t��}tj�||d�}|�|�|�	d�|�
�}|�dt�}|�
|�|jr;|�t�s=|�
t�d
Sd
Sd
St|tttjf�r�t|tj�rYt�dtd�|��}t|t�rc|�|�}|rk|�dd�}|�dt�}|�
|�|jr�|�t�s�|�
t�d
Sd
Sd
St|d�r�t|d�r�t�d	td�|j}d
}	|��}|�d�r�|d
d
�d}n
|�d�r�|d
d�d}|s�n|r�|�d�r�d|dd
�}|�dt�}|�
|�|}q�|jr�|r�|�t�s�|�
t�d
Sd
Sd
Sd
Stdt|���)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 insteadNT�
����
����From s>From ��Invalid message type: %s)�
isinstancerAr(r	�io�BytesIO�	generator�BytesGenerator�flatten�seekrp�replace�linesep�write�_append_newline�endswith�str�bytes�StringIO�warnings�warn�DeprecationWarning�getvaluerlr]rq�readline�
startswith�	TypeError�type)	rr(�targetZmangle_from_rq�gen�dataZlastline�linerrr �
_dump_message�sf


��


�

�


��zMailbox._dump_message�NTr/�F)'�__name__�
__module__�__qualname__�__doc__r!r)r.r0r3r6r9r7r:rDrCr=rHrKrPrQrRrSrTrVrXrYr[r\r`rbrdrfrhrlr�r��classmethodr�__class_getitem__rrrr r"sF

		
	

6rc@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�sE|r@t�|jd�|j�	�D]}t�|d�q6nt
|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�mkdirrRr�_toc�_toc_mtimes�
_last_read�_skewfactor)r�dirnamerrrrrr r!s ��

zMaildir.__init__c
Csf|��}z|�||�Wnty|��t�|j��wt|�t|t	�r;|�
�}|j|��}||jkr:d}nd}d}tj
�|j��|j�d}tj
�|j|||�}t|t	�rlt�|jtj
�|j�|��f�z'z	t�|j|�Wnttfy�t�|j|�YW|Swt�|j�W|Sty�}zt�|j�|jtjkr�td|���d}~ww)r#�r�rz$Name clash with existing message: %sN)�_create_tmpr��
BaseExceptionrhrr.�name�_sync_closerzr
�
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�errr r)$sR�

�
�
�����zMaildir.addcCs t�tj�|j|�|���dS�r+N)rr.rr�r�_lookupr,rrr r.Ns zMaildir.removec	Cs*z|�|�WdSttfyYdSwr1)r.r2�FileNotFoundErrorr,rrr r3Rs
�zMaildir.discardcCs�|�|�}|�|�}|�|�}t|t�r|}n|}tj�|�}|j|vr0|j|�|j�d}nd}|�	|�tj�
|j|�}	tj�
|j|||�}
t|t�r]t�|	tj�
|	�|��f�t�|	|
�dS)r4rvr�N)r�r)rzr
rrr�r�r�r3r�rr�r�r�r�)rr-r(Zold_subpathZtemp_keyZtemp_subpathZdominant_subpathr�r�Ztmp_path�new_pathrrr r6Zs$






�zMaildir.__setitem__cCs�|�|�}ttj�|j|�d��}|jr|�|�}nt|�}Wd�n1s(wYtj�|�\}}|�	|�|j
|vrJ|�|�|j
�d�|�tj�
tj�|j|���|S)r?�rbNrv)r��openrrr�rrr
r��
set_subdirr��set_info�set_date�getmtime)rr-Zsubpath�f�msgr�r�rrr r:us
��

zMaildir.get_messagecCsPttj�|j|�|��d��}|���td�Wd�S1s!wYdS)�2Return a bytes representation or raise a KeyError.r�rmN)	r�rrr�rr�rpr�r��rr-r�rrr rC�s$�zMaildir.get_bytescCs$ttj�|j|�|��d�}t|�S)rEr�)r�rrr�rr��
_ProxyFiler�rrr r=�szMaildir.get_filec	csB�|��|jD]}z|�|�Wn	tyYqw|VqdS�rFN)�_refreshr�r�r2r,rrr rH�s�
��zMaildir.iterkeyscC�|��||jvS�rU)r�r�r,rrr rV��
zMaildir.__contains__cC�|��t|j�S�rW)r��lenr�rGrrr rX�r�zMaildir.__len__cC�dS)�"Write any pending changes to disk.NrrGrrr rb�sz
Maildir.flushcCr�)rcNrrGrrr rd��zMaildir.lockcCr�)reNrrGrrr rf�r�zMaildir.unlockcCr��rgNrrGrrr rh�r�z
Maildir.closecCs\g}t�|j�D]#}t|�dkr+|ddkr+tj�tj�|j|��r+|�|dd��q|S)�Return a list of folder names.�r�.N)r�listdirrr�r�isdirr��append�rrZ�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�|�s,t�t�|tj	tj
Bd��|S)z>Create a folder and return a Maildir instance representing it.r��rZ
maildirfolder�)rrr�rrrr�rhr��O_CREAT�O_WRONLY)rr�rrZZmaildirfolder_pathrrr �
add_folder�s�zMaildir.add_foldercCstj�|jd|�}t�tj�|d��t�tj�|d��D]}t|�dks,|ddkr2td|��qt�|�D]!}|dkrY|dkrY|dkrYtj�tj�||��rYtd||f��q8tj|d	d
�D]#\}}}|D]}t�	tj�||��qh|D]}t�
tj�||��qwqat�
|�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]}tj�|jd|�}|tj�|�dkr)t�|�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|vr|�dd�}d|vr|�dd�}dt|�t|dd�t��tj|f}tj	�
|jd|�}zt�|�Wn!t
yatjd7_zt|�WYSty^YnwYnwtd	|��)
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: %s)r��socket�gethostnamer��intr�getpidr�_countrr�r�statr��_create_carefully�FileExistsErrorr)rr�Zhostnamer�rrrr r��s0����zMaildir._create_tmpcCs�t��|jd|jkr/d}|jD]}tj�|j|�}||j|kr%d}||j|<q|s/dSi|_|jD]/}|j|}t�	|�D]"}tj�
||�}tj�|�rQqA|�|j
�d}tj�
||�|j|<qAq5t��|_dS)z!Update table of contents mapping.�FTNr)r�r�r�r�rrr�r�r�r�r�r�r�r�)rZrefreshr��mtimerr��pr�rrr r�s(


�zMaildir._refreshcCstztj�tj�|j|j|��r|j|WSWn	ty Ynw|��z|j|WSty9td|�d�w)z=Use TOC to return subpath for given key, or raise a KeyError.�No message with key: %sN)rrr�r�rr�r2r�r,rrr r�&s���zMaildir._lookupcCsLt|d�s
|��|_	z|t|j�WStyYdSty%Yq
w)z0Return the next message in a one-time iteration.�
_onetime_keysTN)r]rHr	�next�
StopIterationr2rGrrr r
4s

�zMaildir.nextr�)r�r�r�r�r�r!r)r.r3r6r:rCr=rHrVrXrbrdrfrhr�r�r�r�r�rr�r�r�r
rrrr rs8
*
	
$rc@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�}Wn7tyG}z+|jtjkr,|r't|jd�}nt|j��|jtjtj	fvr<t|jd�}n�WYd}~nd}~ww||_
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�rrr r!Ds(
��

z_singlefileMailbox.__init__cCs8|��|�|�|j|j<|jd7_d|_|jdS)r#r�T)r��_append_messager�rrr'rrr r)[s

z_singlefileMailbox.addcCs|�|�|j|=d|_dS)r+TN)r�r�rr,rrr r.es

z_singlefileMailbox.removecCs$|�|�|�|�|j|<d|_dS)r4TN)r�rr�rr5rrr r6ks

z_singlefileMailbox.__setitem__ccs�|��|j��EdHdSr�)r�r�rKrGrrr rHqs�z_singlefileMailbox.iterkeyscCr�r�)r�r�r,rrr rVvr�z_singlefileMailbox.__contains__cCr�r�)r�r�r�rGrrr rX{r�z_singlefileMailbox.__len__cCs|js
t|j�d|_dSdS)rcTN)r�
_lock_filerrGrrr rd��

�z_singlefileMailbox.lockcCs|jr
t|j�d|_dSdS�reFN)r�_unlock_filerrGrrr rf�rz_singlefileMailbox.unlockc
Cs�|js|jrt|j�d|_dS|jdusJ�|j�dd�|j��}||jkr1td|j|f��t	|j
�}zSi}|�|�t|j�
��D]=}|j|\}}|j�|�|�|�|��}	|j�td||j����}|son|�|�q^||��f||<|�|�qE|��|_Wn|��t�|j��t|�|j��t�|j
�j}	t�|j|	�z
t�|j|j
�Wnty�t�|j
�t�|j|j
�Ynwt|j
d�|_||_d|_d|_|jr�t|jdd	�dSdS)
r�FNrrz4Size of mailbox file changed (expected %i, found %i)T�r
)�dotlock) rr�_sync_flushrr�r��tellrr�_create_temporaryr�_pre_mailbox_hook�sortedrK�_pre_message_hookrp�minr��_post_message_hookrhrr.r�r�r�st_mode�chmodr�rr�rr)
rZcur_lenZnew_fileZnew_tocr-�start�stopZ	new_startrq�moderrr rb�sj


�



�
�
��z_singlefileMailbox.flushcCr�)�,Called before writing the mailbox to file f.Nr�rr�rrr r!�r�z$_singlefileMailbox._pre_mailbox_hookcCr�)�-Called before writing each message to file f.Nrr,rrr r#�r�z$_singlefileMailbox._pre_message_hookcCr���,Called after writing each message to file f.Nrr,rrr r%�r�z%_singlefileMailbox._post_message_hookcCs�z#|��Wz|jr|��W|j��dSW|j��dS|j��wz|jr3|��W|j��wW|j��w|j��wr�)rbrrfrrhrGrrr rh�s

��
�z_singlefileMailbox.closecCsH|jdur	|��|dur"z|j|WSty!td|�d�wdS)z'Return (start, stop) or raise KeyError.Nr)r��
_generate_tocr2r,rrr r��s
��z_singlefileMailbox._lookupcCs�|j�dd�|j��}t|j�dkr|js|�|j�z|�|j�|�|�}|�	|j�Wnt
y=|j�|��w|j��|j��|_
|S)z;Append message to mailbox and return (start, stop) offsets.rr)rr�rr�r�rr!r#�_install_messager%r��truncaterbr)rr(ZbeforeZoffsetsrrr r�s

�
z"_singlefileMailbox._append_messager�r/)r�r�r�r�r!r)r.r6rHrVrXrdrfrbr!r#r%rhr�rrrrr rAs$

@

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?�rmrxNr)r�rr�r�r�r�rpr�_message_factory�set_from�decode)rr-r(r)�	from_line�stringr�rrr r:	sz_mboxMMDF.get_messageFcCst�|�||��j|d�S)�3Return a string representation or raise a KeyError.)�unixfromr@)rr-�from_rrr rDs

��z_mboxMMDF.get_stringcCsJ|�|�\}}|j�|�|s|j��|j�||j���}|�td�S)r:rm)r�rr�r�rprr�r�)rr-r<r(r)r9rrr rCs
z_mboxMMDF.get_bytescCs<|�|�\}}|j�|�|s|j��t|j|j��|�S)rE)r�rr�r��_PartialFiler)rr-r<r(r)rrr r=!s

z_mboxMMDF.get_filecCsd}t|t�r|�|�}t|t�r3|�d�r3|�d�}|dkr.|d|�}||dd�}n*|}d}n%t|t�rD|���d�}d|}nt|t	j
j�rX|��}|durX|�d�}|durgdt
�t
�����}|j��}|j�|t�|�||j|j�|j��}||fS)	z1Format a message and blindly write to self._file.Nrwrmrvr�r4rsFrom MAILER-DAEMON )rzr�rlr�r��find�_mboxMMDFMessage�get_fromrirAr(r	�get_unixfromr��asctime�gmtimerrr�r�r��
_mangle_from_)rr(r8�newlineZauthorr(r)rrr r1)s0







z_mboxMMDF._install_messageNr�)
r�r�r�r�rDr:rDrCr=r1rrrr r3s



	r3c@s2eZdZdZdZdZd
dd�Zdd�Zdd	�ZdS)rzA classic mbox mailbox.TNcC�t|_t�||||�dS)zInitialize an mbox mailbox.N)rr5r3r!rrrr r!O�z
mbox.__init__cCs|�t�dSr.�r�r�r,rrr r%T�zmbox._post_message_hookcCs�gg}}d}|j�d�	|j��}|j��}|�d�r>t|�t|�kr6|r1|�|tt��n|�|�|�|�d}n|sR|rL|�|tt��n|�|�n
|tkrYd}nd}qtt	t
||���|_t|j�|_|j��|_
dS)�0Generate key-to-(start, stop) table of contents.FrTrwN)rr�rr�r�r�r�r��dict�	enumerate�zipr�rr)r�starts�stopsZlast_was_empty�line_posr�rrr r0Xs2






�zmbox._generate_tocr�)	r�r�r�r�rDr�r!r%r0rrrr rFs
rc@s2eZdZdZddd�Zdd�Zdd	�Zd
d�ZdS)
rzAn MMDF mailbox.NTcCrF)zInitialize an MMDF mailbox.N)rr5r3r!rrrr r!}rGz
MMDF.__init__cC�|�dt�dS)r-�NrHr,rrr r#��zMMDF._pre_message_hookcCs|�tdt�dS)r/rRNrHr,rrr r%�szMMDF._post_message_hookcCs�gg}}|j�d�d}	|}|j��}|j��}|�dt�rM|�|�	|}|j��}|j��}|dtkrC|�|tt��n	|sK|�|�nq'n|sPnqtt	t
||���|_t|j�|_|j�dd�|j��|_
dS)rJrTrRrN)rr�r�rr�r�r�r�rKrLrMr�rr)rrNrO�next_posrPr�rrr r0�s8






��
�zMMDF._generate_tocr�)r�r�r�r�r!r#r%r0rrrr rzs
rc@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�s5|r0t�|jd�t�t�tj�	|jd�tj
tjBtjBd��nt
|j��d|_dS)zInitialize an MH instance.r��
.mh_sequencesi�FN)rr!rrr�rr�rhr�r�r��O_EXCLr�rrrrrr r!�s�

zMH.__init__cCs�|��}t|�dkr
d}nt|�d}tj�|jt|��}t|�}d}zQ|j	r+t
|�z7z|�||�WntyN|j	rBt
|�t|�d}t�|��wt|t�rZ|�||�W|j	rbt
|�n	|j	rkt
|�wwW|sst|�|S|s|t|�ww)r#rr�FT)rKr��maxrrr�rr�rrrr�r�rr�r.rzr�_dump_sequences)rr(rKZnew_keyr�r��closedrrr r)�sJ
�
���
���
�zMH.addc
Csltj�|jt|��}zt|d�}Wnty*}z
|jtjkr%t	d|���d}~ww|�
�t�|�dS)r+r
rN)rrr�rr�r�r�r�rr2rhr.)rr-rr�r�rrr r.�s��z	MH.removec
Cs�tj�|jt|��}zt|d�}Wnty*}z
|jtjkr%t	d|���d}~wwz?|j
r3t|�z't�t�|tj
tjB��|�||�t|t�rR|�||�W|j
rZt|�n	|j
rct|�wwWt|�dSt|�w)r4r
rN)rrr�rr�r�r�r�rr2rrrhr��O_TRUNCr�rzrrXrr�)rr-r(rr�r�rrr r6�s4��
���
��zMH.__setitem__c
Csz |jrttj�|jt|��d�}n
ttj�|jt|��d�}Wnty9}z
|jtj	kr4t
d|���d}~ww|�&|jrDt|�z
t|�}W|jrQt
|�n	|jrZt
|�wwWd�n1sewY|����D]
\}}||vr}|�|�qp|S)r?r
r�rN)rr�rrr�rr�r�r�rr2rrr�
get_sequencesrT�add_sequence)rr-r�r�r�r��key_listrrr r:�s:���
��
���
�zMH.get_messagec
Cs�z |jrttj�|jt|��d�}n
ttj�|jt|��d�}Wnty9}z
|jtj	kr4t
d|���d}~ww|�)|jrDt|�z|���
td�W|jrTt|�Wd�S|jrdt|�ww1shwYdS)r�r
r�rNrm)rr�rrr�rr�r�r�rr2rrpr�r�r�rr-r�r�rrr rCs.����
��zMH.get_bytesc
CsXzttj�|jt|��d�}Wt
|�Sty+}z
|jtjkr&t	d|���d}~ww)rEr�rN)r�rrr�rr�r�r�rr2r�r^rrr r=,s���zMH.get_filecCsttdd�t�|j�D���S)rFcss �|]}|��rt|�VqdSr/)�isdigitr�)�.0r�rrr �	<genexpr>9s��zMH.iterkeys.<locals>.<genexpr>)�iterr"rr�rrGrrr rH7szMH.iterkeyscCstj�tj�|jt|���Sr�)rrr�r�rr�r,rrr rV<szMH.__contains__cCstt|����Sr�)r�rJrHrGrrr rX@�z
MH.__len__cCs6|jsttj�|jd�d�|_t|j�d|_dSdS)rcrUr
TN)rr�rrr�rrrrGrrr rdDs


�zMH.lockcCs,|jrt|j�t|j�|`d|_dSdSr)rrrr�rGrrr rfKs


�z	MH.unlockcCr�)raNrrGrrr rbSr�zMH.flushcCs|jr	|��dSdSr�)rrfrGrrr rhWs�zMH.closecCs<g}t�|j�D]}tj�tj�|j|��r|�|�q|S)r�)rr�rrr�r�r�r�rrr r�\s
�zMH.list_folderscCsttj�|j|�|jdd�S)z+Return an MH instance for the named folder.Fr��rrrr�rrr�rrr r�ds�z
MH.get_foldercCsttj�|j|�|jd�S)z:Create a folder and return an MH instance representing it.r�rdr�rrr r�is�z
MH.add_foldercCs`tj�|j|�}t�|�}|dgkrt�tj�|d��n|gkr"ntd|j��t�|�dS)r�rUzFolder not empty: %sN)rrr�rr�r.rr�)rr�r�entriesrrr r�ns

zMH.remove_folderc

si}ttj�|jd�ddd��p}t|����|D]^}zM|�d�\}}t�}|��D]$}|��r7|�	t
|��q)dd�|�d�D�\}}	|�t||	d	��q)�fd
d�t
|�D�||<t||�dkrf||=Wqtyvtd
|����wWd�|S1s�wY|S)z=Return a name-to-key-list dictionary to define each sequence.rU�r�ASCII��encodingr�css�|]}t|�VqdSr/)r�)r`�xrrr ra���z#MH.get_sequences.<locals>.<genexpr>�-r�csg|]}|�vr|�qSrr)r`r-�Zall_keysrr �
<listcomp>�s�z$MH.get_sequences.<locals>.<listcomp>rz"Invalid sequence specification: %sN)r�rrr�r�setrKr�r_r)r�r`�ranger"r�rkr�rstrip)
rZresultsr�r�r��contentsrK�specr(r)rrmr r[zs4����
��zMH.get_sequencescCsttj�|jd�ddd�}zqt�t�|jtjtjB��|�	�D]W\}}t
|�dkr+q |�|d�d}d}tt
|��D])}|d	|krN|sMd
}|�d�n|r\d}|�d||f�n|�d
|�|}q<|rr|�t|�d�q |�d�q Wt|�dSt|�w)z:Set sequences using the given name-to-key-list dictionary.rUzr+rgrhrr�NFr�Trlz%s %sz %s�
)r�rrr�rrhr�r�rZrTr�r�r"ror�r�)r�	sequencesr�r�rK�prevZ
completingr-rrr �
set_sequences�s2
��zMH.set_sequencesc	
Cs8|��}d}g}|��D]`}|d|krh|�||df�zt�tj�|jt|��tj�|jt|d���Wn#t	t
fyZt�tj�|jt|��tj�|jt|d���Ynwt�tj�|jt|���|d7}q|d|_
t|�dkrzdS|��D]\}}|D]\}}||vr�|||�|�<q�q~|�|�dS)z?Re-name messages to eliminate numbering gaps. Invalidates keys.rr�N)r[rHr�rr�rr�rr�r�r�r��unlinkrr�rT�indexrw)	rrurvZchangesr-r�r]�oldr�rrr �pack�s6���

��zMH.packcCst|��}|��}|��D]\}}||vr|�|�q||vr$||�|�=q|D]}||vr2|g||<q'|�|�dS)z;Inspect a new MHMessage and update sequences appropriately.N)r[rTr�ryrw)rr(r-Zpending_sequencesZ
all_sequencesr�r]�sequencerrr rX�s�
�zMH._dump_sequencesr�)r�r�r�r�r!r)r.r6r:rCr=rHrVrXrdrfrbrhr�r�r�r�r[rwr{rXrrrr r�s0
"rc@s�eZdZdZehd��Zddd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�ZdS) rzAn Rmail-style Babyl mailbox.>�unseen�resent�answered�	forwardedZfiled�deletedZeditedNTcCst�||||�i|_dS)zInitialize a Babyl mailbox.N)rr!�_labelsrrrr r!�s
zBabyl.__init__cCs(t�||�}t|t�r|��|j|<|S)r#)rr)rzr
�
get_labelsr�)rr(r-rrr r)�s
z	Babyl.addcCs&t�||�||jvr|j|=dSdSr�)rr.r�r,rrr r.�s
�zBabyl.removecCs.t�|||�t|t�r|��|j|<dSdS)r4N)rr6rzr
r�r�r5rrr r6�s
�zBabyl.__setitem__c
Cs|�|�\}}|j�|�|j��t��}	|j��}|dtks$|s%n
|�|�td��qt��}	|j��}|tks?|s@n
|�|�td��q4||j�	�}|dksWJ�|j�
|�}|�td�}t|��|�}	|	�
|���||jvr|	�|j|�|	S)r?T�*** EOOH ***rmr)r�rr�r�r{r|r�r�r�rrpr
r��set_visibler��
set_labels)
rr-r(r)�original_headersr�Zvisible_headers�n�bodyr�rrr r:�s4

�
�
zBabyl.get_messagec	Cs�|�|�\}}|j�|�|j��t��}	|j��}|dtks$|s%n
|�|�td��q	|j��}|tks;|s<nq0|�	�}||j�
�}|dksNJ�|j�|�}|�td�}||S)r:Tr�rmr)r�rr�r�r{r|r�r�r�r�rrp)	rr-r(r)r�r�Zheadersr�r�rrr rCs*

�
�zBabyl.get_bytescCst�|�|��dt��S)rErm)r{r|rCr�r�r,rrr r=(�zBabyl.get_filecCs<|��t�}|j��D]}|�|�q|�|j�t|�S)z4Return a list of user-defined labels in the mailbox.)r�ror�rRr`�difference_update�_special_labelsrJ)r�labelsZ
label_listrrr r�,szBabyl.get_labelscCs<gg}}|j�d�d}g}	|}|j��}|j��}|dtkrOt|�t|�kr3|�|tt��|�|�dd�|j��dd��d�D�}|�|�n(|d	ksY|d	tkrkt|�t|�krj|�|tt��n|sw|�|tt��nqtt	t
||���|_tt	|��|_t|j�|_
|j�dd
�|j��|_dS)rJrTscSsg|]
}|��r|���qSr)�strip�r`�labelrrr rnCs�z'Babyl._generate_toc.<locals>.<listcomp>r�N�,�r)rr�r�rr�r�r�r�rKrLrMr�r�rr)rrNrOrTZlabel_listsrPr�r�rrr r05s:



���zBabyl._generate_toccCsVdt}|dt7}|��}dd�|D�}|dd�|�t7}|d7}|�|�dS)	r+sBABYL OPTIONS:s
Version: 5css�|]}|��VqdSr/)rir�rrr raXrkz*Babyl._pre_mailbox_hook.<locals>.<genexpr>sLabels:r�r�N)r�r�r�r�)rr�Zbabylr�rrr r!SszBabyl._pre_mailbox_hookcCrQ)r-�NrHr,rrr r#]rSzBabyl._pre_message_hookcCs|�td�dS)r/r�NrHr,rrr r%arSzBabyl._post_message_hookcCs`|j��}t|t�rXg}g}|��D]}||jvr|�|�q|�|�q|j�d�|D]}|j�d|���q-|j�d�|D]}|j�d|��d�qB|j�t	�n|j�dt	�t|t
jj�r�t
��}t
j�|dd�}|�|�|�d�	|��}|j�|�d
t	��|d
ks�|s�nq~|j�dt	�t|t�r�t
��}	t
j�|	dd�}
|
�|���	|	��}|j�|�d
t	��|d
ks�|s�nq�n|�d�	|��}|j�|�d
t	��|d
ks�|s�nq�	|�d�}|s�n|j�|�d
t	��q�n)t|ttt
jf��r{t|t
j��rt�d
td�|��}t|t��r%|�|�}|�d�d}|ddk�rf|j�|d|��d
t	��|j�dt	�|j�|d|��d
t	��|j�||d��d
t	��n�|j�dt	t	�|j�|�d
t	��n�t |d��rt |d��r�t�dtd�|j!}|��}
d	}	|��}|�"d��r�|dd�d
}n|�"d��r�|dd�d
}|j�|�d
t	��|d
k�s�|�s�|�r�d}|j�dt	�|�|
�nn�q�	|��}|�s�n4|�"d��r�|dd�t	}n|�"d��r|dd�t	}n|�"d
��r|dd�t	}|j�|��q�nt#dt$|���|j��}||fS)z0Write message contents and return (start, stop).�1s, s,,� r�s1,,FrTrmr�rrnros

rrvNr�rqrrrsrtrury)%rrrzr
r�r�r�r�rir�rAr(r	r{r|r}r~rr�r�r��get_visiblerpr�r�r�r�r�r�r�rlr>r]rqr�r�r�)rr(r(Zspecial_labelsr�r�Zorig_bufferZorig_generatorr�Z
vis_bufferZ
vis_generatorrqZ
body_startZoriginal_posZ
first_passr)rrr r1es�




�
�
�
��
���

zBabyl._install_messager�)r�r�r�r��	frozensetr�r!r)r.r6r:rCr=r�r0r!r#r%r1rrrr r�s 
	
rc@s*eZdZdZd	dd�Zdd�Zdd�ZdS)
r	z0Message with mailbox-format-specific properties.NcCs�t|tjj�r|�t�|��t|t�r|�|�dSdSt|t�r,|�t�	|��dSt|t
�r;|�t�|��dSt|tj
�rK|�t�|��dSt|d�rZ|�t�|��dS|durgtjj�|�dStdt|���)zInitialize a Message instance.rpNry)rzrAr(r	�_become_message�copyZdeepcopy�_explain_tor�rBr�Zmessage_from_stringr{�
TextIOWrapperZmessage_from_filer]Zmessage_from_binary_filer!r�r�r'rrr r!�s 
�


zMessage.__init__cCs4t|dg�}|jD]}||vr|j||j|<q	dS)z0Assume the non-format-specific state of message.�_type_specific_attributesN)�getattr�__dict__)rr(Z
type_specificr�rrr r��s
��zMessage._become_messagecCst|t�rdStd��)z:Copy format-specific state to message insofar as possible.Nz Cannot convert to specified type)rzr	r�r'rrr r��s
zMessage._explain_tor/)r�r�r�r�r!r�r�rrrr r	�s

r	c@szeZdZdZgd�Zddd�Zdd�Zdd	�Zd
d�Zdd
�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�r	r!r'rrr r!�s
zMaildirMessage.__init__cC�|jS)zReturn 'new' or 'cur'.)r�rGrrr r��zMaildirMessage.get_subdircCs&|dks|dkr
||_dStd|��)zSet subdir to 'new' or 'cur'.r�r�z!subdir must be 'new' or 'cur': %sN)r�rk)rr�rrr r�s
zMaildirMessage.set_subdircCs|j�d�r
|jdd�SdS)�*Return as a string the flags that are set.�2,rNr�)r�r�rGrrr �	get_flags
szMaildirMessage.get_flagscCsdd�t|��|_dS)�)Set the given flags and unset all others.r�r�N)r�r"r�)r�flagsrrr �	set_flagsr�zMaildirMessage.set_flagscC�$|�d�t|���t|�B��dS�z.Set the given flag(s) without changing others.r�N�r�r�ror��r�flagrrr �add_flag�$zMaildirMessage.add_flagcCs0|��r|�d�t|���t|���dSdS)�7Unset the given string flag(s) without changing others.r�N)r�r�r�ror�rrr �remove_flags$�zMaildirMessage.remove_flagcCr�)z<Return delivery date of message, in seconds since the epoch.)r�rGrrr r�!r�zMaildirMessage.get_datecCs.zt|�|_WdStytd|�d�w)z9Set delivery date of message, in seconds since the epoch.zcan't convert to float: %sN)�floatr�rkr�)r�daterrr r�%s
�zMaildirMessage.set_datecCr�)z%Get the message's "info" as a string.)r�rGrrr r�,r�zMaildirMessage.get_infocCs$t|t�r
||_dStdt|���)z Set the message's "info" string.zinfo must be a string: %sN)rzr�r�r�r�)r�inforrr r�0s

zMaildirMessage.set_infocCs�t|t�r|�|���|�|���|�|���dSt|t�rct	|���}d|vr0|�
d�|��dkr;|�
d�d|vrD|�
d�d|vrM|�
d�d|vrV|�
d�|�d	t�
|����dSt|t�r�t	|���}d|vrw|�d
�d|vr�|�d�d|vr�|�d�dSdSt|t�r�t	|���}d|vr�|�d
�d|vr�|�d
�d|vr�|�d�d|vr�|�d�dSdSt|t�r�dStdt|���)z;Copy Maildir-specific state to message insofar as possible.�S�Rr��O�T�D�F�A�
MAILER-DAEMONr}�replied�flaggedr�r�Pr��$Cannot convert to specified type: %sN)rzr
r�r�r�r�r�r�r?ror�r6r�rCrr\r
�	add_labelr	r�r�)rr(r�rrr r�7sT









�



�
�zMaildirMessage._explain_tor/)r�r�r�r�r�r!r�r�r�r�r�r�r�r�r�r�r�rrrr r
�s
r
c@sZeZdZdZdgZddd�Zdd�Zddd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�ZdS)r?z/Message with mbox- or MMDF-specific properties.�_fromNcCsV|�dd�t|tjj�r#|��}|dur#|�d�r#|�|dd��t�||�dS)z'Initialize an mboxMMDFMessage instance.r�TNzFrom rx)r6rzrAr(r	rAr�r!)rr(r;rrr r!hsz_mboxMMDFMessage.__init__cCr�)z Return contents of "From " line.)r�rGrrr r@qr�z_mboxMMDFMessage.get_fromcCs4|dur|durt��}|dt�|�7}||_dS)z>Set "From " line, formatting and appending time_ if specified.NT� )r�rCrBr�)rr<Ztime_rrr r6us

z_mboxMMDFMessage.set_fromcCs|�dd�|�dd�S)r��Statusr��X-Status)r9rGrrr r�}r�z_mboxMMDFMessage.get_flagscCs�t|�}d\}}dD]}||vr||7}|�|�q
dD]}||vr+||7}|�|�q|d�t|��7}z|�d|�WntyL|�d|�Ynwz	|�d|�WdStyf|�d|�YdSw)r�)r�r�)r�r�)r�r�r�r�r�r�N)ror.r�r"�replace_headerr2Z
add_header)rr�Zstatus_flagsZ
xstatus_flagsr�rrr r��s.
�
���z_mboxMMDFMessage.set_flagscCr�r�r�r�rrr r��r�z_mboxMMDFMessage.add_flagcCs8d|vsd|vr|�d�t|���t|���dSdS)r�r�r�r�Nr�r�rrr r��s$�z_mboxMMDFMessage.remove_flagc	Cs�t|t�rgt|���}d|vr|�d�d|vr|�d�d|vr&|�d�d|vr/|�d�d|vr8|�d�|d	=|d
=d�|����dd
��}z|�	t
�t�
|d���Wd
SttfyfYd
Swt|t�r||�|���|�|���d
St|t�r�t|���}d|vr�|�d�d|vr�|�d�d|vr�|�d�|d	=|d
=d
St|t�r�t|���}d|vr�|�d�d|vr�|�d�d|vr�|�d�|d	=|d
=d
St|t�r�d
Stdt|���)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 %Yr}r�r�r�rr�)rzr
ror�r�r�r�r@r�r��calendarZtimegmr��strptimerk�
OverflowErrorr?r�r6rr\r
r�r	r�r�)rr(r�Z
maybe_daterrr r��sd





��











�z_mboxMMDFMessage._explain_tor/)
r�r�r�r�r�r!r@r6r�r�r�r�r�rrrr r?cs
	
r?c@�eZdZdZdS)rz&Message with mbox-specific properties.N�r�r�r�r�rrrr r��rc@sHeZdZdZdgZddd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dS)rz$Message with MH-specific properties.�
_sequencesNcCsg|_t�||�dS)z!Initialize an MHMessage instance.N)r�r	r!r'rrr r!�szMHMessage.__init__cC�|jdd�S)z4Return a list of sequences that include the message.N)r�rGrrr r[�rIzMHMessage.get_sequencescC�t|�|_dS)z3Set the list of sequences that include the message.N)rJr�)rrurrr rw�rIzMHMessage.set_sequencescC�8t|t�r||jvr|j�|�dSdStdt|���)z8Add sequence to list of sequences including the message.zsequence type must be str: %sN)rzr�r�r�r�r��rr|rrr r\��


�zMHMessage.add_sequencecC�(z	|j�|�WdStyYdSw)zARemove sequence from the list of sequences including the message.N)r�r.rkr�rrr �remove_sequence��
�zMHMessage.remove_sequencecCsPt|t�r5t|���}d|vr|�d�n
|�d�|�d�d|vr(|�d�d|vr3|�d�d
Sd
St|t�ret|���}d|vrJ|�d�n|�d	�d|vrX|�d�d|vrc|�d
�d
Sd
St|t�rx|��D]}|�|�qnd
St|t	�r�t|���}d|vr�|�
d�d|vr�|�
d�d
Sd
St|t�r�d
Stdt
|���)z6Copy MH-specific state to message insofar as possible.r}r�r�r�r�r�r��ROr�r�rr�N)rzr
ror[r�r�r?rr\r
r�r	r�r�)rr(rur|rrr r��sJ



�


�
�

�
�zMHMessage._explain_tor/)r�r�r�r�r�r!r[rwr\r�r�rrrr r�s
rc@sbeZdZdZddgZddd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dS)r
z'Message with Babyl-specific properties.r��_visibleNcCsg|_t�|_t�||�dS)z#Initialize a BabylMessage instance.N)r�r	r�r!r'rrr r!%szBabylMessage.__init__cCr�)z'Return a list of labels on the message.N)r�rGrrr r�+rIzBabylMessage.get_labelscCr�)z&Set the list of labels on the message.N)rJr�)rr�rrr r�/rIzBabylMessage.set_labelscCr�)z+Add label to list of labels on the message.zlabel must be a string: %sN)rzr�r�r�r�r��rr�rrr r�3r�zBabylMessage.add_labelcCr�)z4Remove label from the list of labels on the message.N)r�r.rkr�rrr �remove_label;r�zBabylMessage.remove_labelcCs
t|j�S)z3Return a Message representation of visible headers.�r	r�rGrrr r�Bs
zBabylMessage.get_visiblecCr�)z2Set the Message representation of visible headers.Nr�)rZvisiblerrr r�FrIzBabylMessage.set_visiblecCsb|j��D]}||vr|j�|||�q|j|=qdD]}||vr.||jvr.|||j|<qdS)z9Update and/or sensibly generate a set of visible headers.)ZDateZFromzReply-ToZToZCCZSubjectN)r�rKr�)r�headerrrr �update_visibleJs
��zBabylMessage.update_visiblecCsxt|t�rBt|���}d|vr|�d�n
|�d�|�d�d|vs'd|vr,|�d�d|vr5|�d�d	|vr@|�d
�dSdSt|t�rrt|���}d|vrW|�d�n|�d�d	|vre|�d
�d|vrp|�d�dSdSt|t�r�t|���}d|vr�|�d�d|vr�|�d�dSdSt|t	�r�|�
|���|��D]}|�|�q�dSt|t
�r�dStdt|���)z9Copy Babyl-specific state to message insofar as possible.r}r�r�r�r~r�rr�r�r�r�r�r�r�r�r�N)rzr
ror�r�r�r?rr\r
r�r�r�r	r�r�)rr(r�r�rrr r�UsP




�


�

�
�
�zBabylMessage._explain_tor/)r�r�r�r�r�r!r�r�r�r�r�r�r�r�rrrr r
 s
r
c@r�)rz&Message with MMDF-specific properties.Nr�rrrr rr�rc@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%��Zee�ZdS)(r�zA read-only wrapper of a file.NcCs&||_|dur|��|_dS||_dS)zInitialize a _ProxyFile.N)rr�_pos)rr��posrrr r!�s
z_ProxyFile.__init__cC�|�||jj�S�zRead bytes.)�_readrrp�r�sizerrr rp�rcz_ProxyFile.readcCr�r�)r�r�read1r�rrr r��rcz_ProxyFile.read1cCr�)zRead a line.)r�rr�r�rrr r��rcz_ProxyFile.readlinecCs>g}|D]}|�|�|dur|t|�8}|dkr|Sq|S)zRead multiple lines.Nr)r�r�)r�sizehintrZr�rrr �	readlines�s
�z_ProxyFile.readlinesccs�	|��}|s
dS|Vq)zIterate over lines.TN)r�)rr�rrr rQ�s��z_ProxyFile.__iter__cCr�)zReturn the position.)r�rGrrr r�r�z_ProxyFile.tellrcCs4|dkr|j�|j�|j�||�|j��|_dS)zChange position.r�N�rr�r�r�r�offset�whencerrr r��sz_ProxyFile.seekcCs@t|d�rzt|jd�r|j��W|`dSW|`dS|`wdS)zClose the file.rrhN)r]rrhrGrrr rh�s
��z_ProxyFile.closecCs2|durd}|j�|j�||�}|j��|_|S)z"Read size bytes using read_method.Nrvr�)rr��read_methodrZrrr r��sz_ProxyFile._readcCs|S)z$Context management protocol support.rrGrrr �	__enter__�r�z_ProxyFile.__enter__cGs|��dSr/)rh)r�excrrr �__exit__�sz_ProxyFile.__exit__cC�
|j��Sr/)r�readablerGrrr r���
z_ProxyFile.readablecCr�r/)r�writablerGrrr r��r�z_ProxyFile.writablecCr�r/)r�seekablerGrrr r��r�z_ProxyFile.seekablecCr�r/)rrbrGrrr rb�r�z_ProxyFile.flushcCs&t|d�sdSt|jd�sdS|jjS)NrTrYF)r]rrYrGrrr rY�s

z_ProxyFile.closedr/�r)r�r�r�r�r!rpr�r�r�rQrr�rhr�r�r�r�r�r�rb�propertyrYr�rr�rrrr r��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�r(r)rrr r!�s
z_PartialFile.__init__cCst�|�|jS)z*Return the position with respect to start.)r�rr�rGrrr r�rcz_PartialFile.tellrcCs<|dkr|j|_d}n
|dkr|j|_d}t�|||�dS)z8Change position, possibly with respect to start or stop.rr�rN)r�r�r�r�r�r�rrr r��sz_PartialFile.seekcCsB|j|j}|dkrdS|dus|dks||kr|}t�|||�S)z;Read size bytes using read_method, honoring start and stop.rr4N)r�r�r�r�)rr�r�Z	remainingrrr r��sz_PartialFile._readcCst|d�r	|`dSdS)Nr)r]rrGrrr rhs
�z_PartialFile.close)NNr�)	r�r�r�r�r!rr�r�rhrrrr r=�s


	r=Tc
Cs�d}z�tr1zt�|tjtjB�Wnty0}z|jtjtjtjfvr+t	d|j
���d}~ww|r�z
t|j
d�}|��Wnty^}z|jtjtjfvrYWYd}~WdS�d}~wwz4zt
�|j
|j
d�d}Wnttfy�t
�|j
|j
d�d}Ynwt
�|j
�WWdSWWdSty�t
�|j
�t	d|j
��wWdStr�t�|tj�|r�t
�|j
d��)z(Lock file f using lockf and dot locking.Fzlockf: lock unavailable: %sN�.lockTzdot lock unavailable: %s)�fcntl�lockfZLOCK_EXZLOCK_NBr�r�ZEAGAINrrrr�r rhrr�r�r�r�rxrr.�LOCK_UN)r�rZdotlock_doner�Zpre_lockrrr rs\����������rcCs<tr	t�|tj�tj�|jd�rt�|jd�dSdS)z*Unlock file f using lockf and dot locking.r�N)r�r�r�rrr�r�r.�r�rrr r9s
�rc	Cs@t�|tjtjBtjBd�}zt|d�Wt�|�St�|�w)zCCreate a file if it doesn't exist and open for reading and writing.r�r
)rr�r�rV�O_RDWRrh)r�fdrrr r@s
rcCs$td|tt���t��t��f�S)zBCreate a temp file based on path and open for reading and writing.z%s.%s.%s.%s)rr�r�r�r�rr)rrrr r Hs�r cCs(|��ttd�rt�|���dSdS)z0Ensure changes to file f are physically on disk.�fsyncN)rbr]rr�filenor�rrr rNs
�rcCst|�|��dS)z:Close file f, ensuring all changes are physically on disk.N)rrhr�rrr r�Tsr�c@r�)rz"Raised for module-specific errors.Nr�rrrr rZr�rc@r�)rz:The specified mailbox does not exist and won't be created.Nr�rrrr r]r�rc@r�)rz>The specified mailbox is not empty and deletion was requested.Nr�rrrr r`r�rc@r�)rz)Another process caused an action to fail.Nr�rrrr rcr�rc@r�)rz)A file appears to have an invalid format.Nr�rrrr rfr�r)T)2r�rr�r�r�r�r�r�rAZ
email.messageZemail.generatorr{r;�typesrr��ImportError�__all__r�rirrrr3rrrrr(r	r
r?rrr
rr�r=rrrr rr��	Exceptionrrrrrrrrr �<module>sp�j8DB4-3z%mqH_e
'*