Mini Shell

Direktori : /proc/self/root/lib64/python3.9/__pycache__/
Upload File :
Current File : //proc/self/root/lib64/python3.9/__pycache__/mailbox.cpython-39.pyc

a

�DOg�3�@s>dZddlZddlZddlZddlZddlZddlZddlZddlZddl	Zddl
ZddlZddlZddl
mZzddlZWney�dZYn0gd�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/�ZdEd0d1�Zd2d3�ZdFd4d5�Zd6d7�Zd8d9�Zd:d;�Zd<d=�Z d>d?�Z!d@Z"dGdAdB�Z#e$e%�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�/usr/lib64/python3.9/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__2szMailbox.__delitem__cCs&z|�|�Wnty Yn0dS�z'If the keyed message exists, remove it.N)r,�KeyErrorr*rrr �discard5szMailbox.discardcCstd��dS)�>Replace the keyed message; raise KeyError if it doesn't exist.r#Nr$�rr+r'rrr �__setitem__<szMailbox.__setitem__cCs(z|�|�WSty"|YS0dS)z9Return the keyed message, or default if it doesn't exist.N)�__getitem__r0)rr+�defaultrrr �get@szMailbox.getcCsN|js|�|�St�|�|���}|�|�Wd�S1s@0YdS)z=Return the keyed message; raise KeyError if it doesn't exist.N)r�get_message�
contextlib�closing�get_file)rr+�filerrr r5Gs
zMailbox.__getitem__cCstd��dS)�4Return a Message representation or raise a KeyError.r#Nr$r*rrr r8OszMailbox.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_stringcCstd��dS)z8Return a byte string representation or raise a KeyError.r#Nr$r*rrr rAZszMailbox.get_bytescCstd��dS)�6Return a file-like representation or raise a KeyError.r#Nr$r*rrr r;^szMailbox.get_filecCstd��dS)�Return an iterator over keys.r#Nr$�rrrr �iterkeysbszMailbox.iterkeyscCst|���S)zReturn a list of keys.)�listrFrErrr �keysfszMailbox.keysc	cs<|��D].}z||}Wnty.YqYn0|VqdS)z%Return an iterator over all messages.N�rFr0�rr+�valuerrr �
itervaluesjs
zMailbox.itervaluescCs|��Sr-)rLrErrr �__iter__sszMailbox.__iter__cCst|���S)z,Return a list of messages. Memory intensive.)rGrLrErrr �valuesvszMailbox.valuesc	cs@|��D]2}z||}Wnty.YqYn0||fVqdS)z.Return an iterator over (key, message) tuples.NrIrJrrr �	iteritemszs
zMailbox.iteritemscCst|���S)z9Return a list of (key, message) tuples. Memory intensive.)rGrOrErrr �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$rErrr �__len__�szMailbox.__len__cCs|��D]}|�|�qdS)zDelete all messages.N)rHr1r*rrr �clear�sz
Mailbox.clearcCs2z||}Wnty"|YS0|�|�|S)z3Delete the keyed message and return it, or default.)r0r1)rr+r6�resultrrr �pop�s

zMailbox.popcCs*|��D]}||�|�fStd��dS)z6Delete an arbitrary (key, message) pair and return it.zNo messages in mailboxN)rFrWr0r*rrr �popitem�szMailbox.popitemc	Csrt|d�r|��}nt|d�r(|��}n|}d}|D],\}}z|||<Wq4ty^d}Yq40q4|rntd��dS)z4Change the messages that correspond to certain keys.rOrPFTzNo message with key(s)N)�hasattrrOrPr0)r�arg�sourceZbad_keyr+r'rrr �update�s



zMailbox.updatecCstd��dS)�&Write any pending changes to the disk.r#Nr$rErrr �flush�sz
Mailbox.flushcCstd��dS)�Lock the mailbox.r#Nr$rErrr �lock�szMailbox.lockcCstd��dS)�#Unlock the mailbox if it is locked.r#Nr$rErrr �unlock�szMailbox.unlockcCstd��dS)�Flush and close the mailbox.r#Nr$rErrr �close�sz
Mailbox.closecCs,z|�d�WSty&td��Yn0dS)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�seekrl�replace�linesep�write�_append_newline�endswith�str�bytes�StringIO�warnings�warn�DeprecationWarning�getvaluerhrYrm�readline�
startswith�	TypeError�type)	rr'�targetZmangle_from_rm�gen�dataZlastline�linerrr �
_dump_message�s\


�


�
zMailbox._dump_message)NT)N)N)N)F)'�__name__�
__module__�__qualname__�__doc__r!r(r,r.r1r4r7r5r8rBrAr;rFrHrLrMrNrOrPrRrTrUrWrXr\r^r`rbrdrhr�r��classmethodr�__class_getitem__rrrr r"sD

		
	

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�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�mkdirrNr�_toc�_toc_mtimes�
_last_read�_skewfactor)r�dirnamerrrrrr r!s�
zMaildir.__init__c
Cs||��}z|�||�Wn(ty@|��t�|j��Yn0t|�t|t	�rz|�
�}|j|��}||jkr�d}nd}d}tj
�|j��|j�d}tj
�|j|||�}t|t	�r�t�|jtj
�|j�|��f�zJzt�|j|�Wn&ttf�yt�|j|�Yn0t�|j�WnPt�yv}z6t�|j�|jtjk�r`td|��n�WYd}~n
d}~00|S)r"�r�rz$Name clash with existing message: %sN)�_create_tmpr��
BaseExceptionrdrr,�name�_sync_closervr
�
get_subdir�colon�get_infor�basename�splitr�r�utime�getatime�get_date�link�AttributeError�PermissionError�rename�OSError�errno�EEXISTr)rr'Ztmp_file�subdir�suffix�uniq�dest�errr r($sF


��zMaildir.addcCs t�tj�|j|�|���dS�r)N)rr,rr�r�_lookupr*rrr r,NszMaildir.removec	Cs*z|�|�Wnttfy$Yn0dSr/)r,r0�FileNotFoundErrorr*rrr r1RszMaildir.discardcCs�|�|�}|�|�}|�|�}t|t�r.|}n|}tj�|�}|j|vr`|j|�|j�d}nd}|�	|�tj�
|j|�}	tj�
|j|||�}
t|t�r�t�|	tj�
|	�|��f�t�|	|
�dS)r2rrr�N)r�r(rvr
rrr�r�r�r1r�rr�r�r�r�)rr+r'Zold_subpathZtemp_keyZtemp_subpathZdominant_subpathr�r�Ztmp_path�new_pathrrr r4Zs$






�zMaildir.__setitem__cCs�|�|�}ttj�|j|�d��*}|jr4|�|�}nt|�}Wd�n1sP0Ytj�|�\}}|�	|�|j
|vr�|�|�|j
�d�|�tj�
tj�|j|���|S)r=�rbNrr)r��openrrr�rrr
r��
set_subdirr��set_info�set_date�getmtime)rr+�subpath�f�msgr�r�rrr r8us
&

zMaildir.get_messagecCsPttj�|j|�|��d�� }|���td�Wd�S1sB0YdS)�2Return a bytes representation or raise a KeyError.r�riN)	r�rrr�rr�rlr}r~�rr+r�rrr rA�szMaildir.get_bytescCs$ttj�|j|�|��d�}t|�S)rCr�)r�rrr�rr��
_ProxyFiler�rrr r;�szMaildir.get_filec	csD|��|jD]0}z|�|�Wnty6YqYn0|VqdS�rDN)�_refreshr�r�r0r*rrr rF�s

zMaildir.iterkeyscCs|��||jvS�rQ)r�r�r*rrr rR�szMaildir.__contains__cCs|��t|j�S�rS)r��lenr�rErrr rT�szMaildir.__len__cCsdS)�"Write any pending changes to disk.NrrErrr r^�sz
Maildir.flushcCsdS)r_NrrErrr r`�szMaildir.lockcCsdS)raNrrErrr rb�szMaildir.unlockcCsdS�rcNrrErrr rd�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�rrV�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�rdr��O_CREAT�O_WRONLY)rr�rrVZmaildirfolder_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|vr$|�dd�}d|vr8|�dd�}dt|�t|dd�t��tj|f}tj	�
|jd|�}zt�|�WnBt
y�tjd7_zt|�WYSty�Yn0Yn0td	|��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��hostnamer�rrrr r��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�rrr r�s&


zMaildir._refreshcCs|z.tj�tj�|j|j|��r,|j|WSWnty@Yn0|��z|j|WStyvtd|�d�Yn0dS)z=Use TOC to return subpath for given key, or raise a KeyError.�No message with key: %sN)rrr�r�rr�r0r�r*rrr r�&szMaildir._lookupcCsTt|d�s|��|_z|t|j�WSty8YdStyLYqYq0qdS)z0Return the next message in a one-time iteration.�
_onetime_keysN)rYrFr�next�
StopIterationr0rErrr r4s

zMaildir.next)NT)r�r�r�r�r�r!r(r,r1r4r8rAr;rFrRrTr^r`rbrdr�r�r�r�r�r�r�r�r�rrrrr rs6
*
	
$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�}Wnpty�}zX|jtjkrZ|rNt|jd�}q|t|j��n"|jtjtj	fvrzt|jd�}n�WYd}~n
d}~00||_
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�r
rr&rrr r([s
z_singlefileMailbox.addcCs|�|�|j|=d|_dS)r)TN)r�r�rr*rrr r,es
z_singlefileMailbox.removecCs$|�|�|�|�|j|<d|_dS)r2TN)r�rr�rr3rrr r4ks
z_singlefileMailbox.__setitem__ccs|��|j��EdHdSr�)r�r�rHrErrr rFqsz_singlefileMailbox.iterkeyscCs|��||jvSr�)r�r�r*rrr rRvsz_singlefileMailbox.__contains__cCs|��t|j�Sr�)r�r�r�rErrr rT{sz_singlefileMailbox.__len__cCs|jst|j�d|_dS)r_TN)r
�
_lock_filer	rErrr r`�s
z_singlefileMailbox.lockcCs|jrt|j�d|_dS�raFN)r
�_unlock_filer	rErrr rb�s
z_singlefileMailbox.unlockc
Cs�|js |jrt|j�d|_dS|jdus.J�|j�dd�|j��}||jkrbtd|j|f��t	|j
�}z�i}|�|�t|j�
��D]x}|j|\}}|j�|�|�|�|��}|j�td||j����}|s�q�|�|�q�||��f||<|�|�q�|��|_Wn"|��t�|j��Yn0t|�|j��t�|j
�j}	t�|j|	�zt�|j|j
�Wn0t�y�t�|j
�t�|j|j
�Yn0t|j
d�|_||_d|_d|_|j�r�t|jdd�dS)	r�FNrr�z4Size of mailbox file changed (expected %i, found %i)�r)�dotlock) rr�_sync_flushr	r�r|�tellrr�_create_temporaryr�_pre_mailbox_hook�sortedrH�_pre_message_hookrl�minr�_post_message_hookrdrr,r�r�r��st_mode�chmodr�r�r�r
r)
rZcur_lenZnew_fileZnew_tocr+�start�stopZ	new_startrm�moderrr r^�sb


�



�
z_singlefileMailbox.flushcCsdS)�,Called before writing the mailbox to file f.Nr�rr�rrr r�sz$_singlefileMailbox._pre_mailbox_hookcCsdS)�-Called before writing each message to file f.Nrr#rrr r�sz$_singlefileMailbox._pre_message_hookcCsdS��,Called after writing each message to file f.Nrr#rrr r�sz%_singlefileMailbox._post_message_hookcCshz6|��Wz|jr|��W|j��qd|j��0n,z|jrH|��W|j��n|j��00dSr�)r^r
rbr	rdrErrr rd�s

�
z_singlefileMailbox.closecCsL|jdur|��|durHz|j|WStyFtd|�d�Yn0dS)z'Return (start, stop) or raise KeyError.Nr)r��
_generate_tocr0r*rrr r��s
z_singlefileMailbox._lookupcCs�|j�dd�|j��}t|j�dkr8|js8|�|j�z&|�|j�|�|�}|�	|j�Wn t
y~|j�|��Yn0|j��|j��|_
|S)z;Append message to mailbox and return (start, stop) offsets.rr�)r	r|rr�r�rrr�_install_messagerr��truncater^r)rr'�beforeZoffsetsrrr r�s


z"_singlefileMailbox._append_message)NT)N)r�r�r�r�r!r(r,r4rFrRrTr`rbr^rrrrdr�rrrrr rAs"

@

rc@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=�rirtNr)r�r	r|r�r}r~rlr�_message_factory�set_from�decode)rr+rr �	from_line�stringr�rrr r8	sz_mboxMMDF.get_messageFcCst�|�||��j|d�S)�3Return a string representation or raise a KeyError.)�unixfromr>)rr+�from_rrr rBs

��z_mboxMMDF.get_stringcCsJ|�|�\}}|j�|�|s(|j��|j�||j���}|�td�S)r2ri)r�r	r|r�rlrr}r~)rr+r4rr r1rrr rAs
z_mboxMMDF.get_bytescCs<|�|�\}}|j�|�|s(|j��t|j|j��|�S)rC)r�r	r|r��_PartialFiler)rr+r4rr rrr r;!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�|��}|dur�|�d�}|dur�dt
�t
�����}|j��}|j�|t�|�||j|j�|j��}||fS)	z1Format a message and blindly write to self._file.Nrsrirrr�r,rsFrom MAILER-DAEMON )rvr�rhr�r��find�_mboxMMDFMessage�get_fromrer?r'r	�get_unixfromr��asctime�gmtimer	rrr~r��
_mangle_from_)rr'r0�newlineZauthorrr rrr r()s0







z_mboxMMDF._install_messageN)F)F)F)
r�r�r�r�r<r8rBrAr;r(rrrr r+s


	
r+c@s2eZdZdZdZdZd
dd�Zdd�Zdd	�ZdS)rzA classic mbox mailbox.TNcCst|_t�||||�dS)zInitialize an mbox mailbox.N)rr-r+r!rrrr r!Osz
mbox.__init__cCs|�t�dSr%�rr~r#rrr rTszmbox._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.FrrsTN)r	r|rr�r�r�r�r~�dict�	enumerate�zipr�r
r)r�starts�stopsZlast_was_empty�line_posr�rrr r'Xs.






zmbox._generate_toc)NT)	r�r�r�r�r<r�r!rr'rrrr rFs
rc@s2eZdZdZddd�Zdd�Zdd	�Zd
d�ZdS)
rzAn MMDF mailbox.NTcCst|_t�||||�dS)zInitialize an MMDF mailbox.N)rr-r+r!rrrr r!}sz
MMDF.__init__cCs|�dt�dS)r$�Nr>r#rrr r�szMMDF._pre_message_hookcCs|�tdt�dS)r&rFNr>r#rrr r�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)r?rrFr�N)r	r|r�rr�r~r�r�r@rArBr�r
r)rrCrD�next_posrEr�rrr r'�s.






zMMDF._generate_toc)NT)r�r�r�r�r!rrr'rrrr 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�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�rdr�r�r��O_EXCLr�rr
rrrr r!�s�
zMH.__init__cCs�|��}t|�dkrd}nt|�d}tj�|jt|��}t|�}d}z�|j	rVt
|�zrz|�||�Wn8ty�|j	r�t
|�t|�d}t�|��Yn0t|t�r�|�||�W|j	r�t
|�n|j	r�t
|�0W|s�t|�n|s�t|�0|S)r"rr�FT)rHr��maxrrr�rr�r�r
rr�r�rr�r,rvr�_dump_sequences)rr'rHZnew_keyr�r��closedrrr r(�s>


�
�
zMH.addc
Csztj�|jt|��}zt|d�}Wn@tyb}z(|jtjkrLt	d|��n�WYd}~nd}~00|�
�t�|�dS)r)rrN)rrr�rr�r�r�r�rr0rdr,)rr+rr�r�rrr r,�sz	MH.removec
Cs�tj�|jt|��}zt|d�}Wn@tyb}z(|jtjkrLt	d|��n�WYd}~n
d}~00zz|j
rtt|�zNt�t�|tj
tjB��|�||�t|t�r�|�||�W|j
r�t|�n|j
r�t|�0Wt|�n
t|�0dS)r2rrN)rrr�rr�r�r�r�rr0r
rrdr��O_TRUNCr�rvrrKrr�)rr+r'rr�r�rrr r4�s(

�zMH.__setitem__c
Csz@|jr$ttj�|jt|��d�}nttj�|jt|��d�}Wn@ty�}z(|jtj	krjt
d|��n�WYd}~n
d}~00|�J|jr�t|�zt|�}W|jr�t
|�n|jr�t
|�0Wd�n1s�0Y|����D]\}}||vr�|�|�q�|S)r=rr�rN)r
r�rrr�rr�r�r�rr0rrr�
get_sequencesrP�add_sequence)rr+r�r�r�r��key_listrrr r8�s*

�(zMH.get_messagec
Cs�z@|jr$ttj�|jt|��d�}nttj�|jt|��d�}Wn@ty�}z(|jtj	krjt
d|��n�WYd}~n
d}~00|�`|jr�t|�z0|���
td�W|jr�t|�Wd�Sn|jr�t|�0Wd�n1s�0YdS)r�rr�rNri)r
r�rrr�rr�r�r�rr0rrlr}r~r�rr+r�r�rrr rAs(��zMH.get_bytesc
Cshzttj�|jt|��d�}Wn@ty^}z(|jtjkrHt	d|��n�WYd}~n
d}~00t
|�S)rCr�rN)r�rrr�rr�r�r�rr0r�rQrrr r;,szMH.get_filecCsttdd�t�|j�D���S)rDcss|]}|��rt|�VqdSr-)�isdigitr�)�.0r�rrr �	<genexpr>9s�zMH.iterkeys.<locals>.<genexpr>)�iterrrr�rrErrr rF7szMH.iterkeyscCstj�tj�|jt|���Sr�)rrr�r�rr�r*rrr rR<szMH.__contains__cCstt|����Sr�)r�rGrFrErrr rT@sz
MH.__len__cCs2|js.ttj�|jd�d�|_t|j�d|_dS)r_rHrTN)r
r�rrr�rr	rrErrr r`Ds
zMH.lockcCs(|jr$t|j�t|j�|`d|_dSr)r
rr	r�rErrr rbKs


z	MH.unlockcCsdS)r]NrrErrr r^SszMH.flushcCs|jr|��dSr�)r
rbrErrr rdWszMH.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�rVr�rrr r�is�z
MH.add_foldercCs`tj�|j|�}t�|�}|dgkr:t�tj�|d��n|gkrDntd|j��t�|�dS)r�rHzFolder not empty: %sN)rrr�rr�r,rr�)rr�r�entriesrrr r�ns

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�||=Wq0ty�td
|����Yq00q0Wd�n1�s
0Y|S)z=Return a name-to-key-list dictionary to define each sequence.rH�r�ASCII��encodingr�css|]}t|�VqdSr-)r�)rS�xrrr rT�r,z#MH.get_sequences.<locals>.<genexpr>�-r�csg|]}|�vr|�qSrr)rSr+�Zall_keysrr �
<listcomp>�s�z$MH.get_sequences.<locals>.<listcomp>rz"Invalid sequence specification: %sN)r�rrr�r�setrHr�rRr(r�r\�rangerr�rgr�rstrip)
r�resultsr�r�r��contentsrH�specrr rr^r rNzs(
�.zMH.get_sequencescCs
ttj�|jd�ddd�}z�t�t�|jtjtjB��|�	�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@Wt|�n
t|�0dS)z:Set sequences using the given name-to-key-list dictionary.rHzr+rYrZrr�NFr�Tr]z%s %sz %s�
)r�rrr�rrdr�r�rMrPr�rrr`r�r�)r�	sequencesr�r�rH�prevZ
completingr+rrr �
set_sequences�s.zMH.set_sequencesc	
Cs<|��}d}g}|��D]�}|d|kr�|�||df�z4t�tj�|jt|��tj�|jt|d���WnFt	t
fy�t�tj�|jt|��tj�|jt|d���Yn0t�tj�|jt|���|d7}q|d|_
t|�dkr�dS|��D]0\}}|D]"\}}||v�r|||�|�<�qq�|�|�dS)z?Re-name messages to eliminate numbering gaps. Invalidates keys.rr�N)rNrFr�rr�rr�rr�r�r�r��unlinkr
r�rP�indexri)	rrgrhZchangesr+r�rP�oldr�rrr �pack�s0��



zMH.packcCst|��}|��}|��D]0\}}||vr4|�|�q||vr||�|�=q|D]}||vrN|g||<qN|�|�dS)z;Inspect a new MHMessage and update sequences appropriately.N)rNrPr�rkri)rr'r+Zpending_sequencesZ
all_sequencesr�rP�sequencerrr rK�szMH._dump_sequences)NT)r�r�r�r�r!r(r,r4r8rAr;rFrRrTr`rbr^rdr�r�r�r�rNrirmrKrrrr r�s.
"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.>Zedited�resentZfiled�deleted�answered�unseen�	forwardedNTcCst�||||�i|_dS)zInitialize a Babyl mailbox.N)rr!�_labelsrrrr r!�szBabyl.__init__cCs(t�||�}t|t�r$|��|j|<|S)r")rr(rvr
�
get_labelsrt)rr'r+rrr r(�s
z	Babyl.addcCs"t�||�||jvr|j|=dSr�)rr,rtr*rrr r,�s
zBabyl.removecCs*t�|||�t|t�r&|��|j|<dS)r2N)rr4rvr
rurtr3rrr r4�s
zBabyl.__setitem__c
Cs�|�|�\}}|j�|�|j��t��}|j��}|dtks\|sHq\|�|�td��q,t��}|j��}|tks�|s|q�|�|�td��qd||j�	�}|dks�J�|j�
|�}|�td�}t|��|�}	|	�
|���||jvr�|	�|j|�|	S)r=�*** EOOH ***rir)r�r	r|r�rwrxr~rr}rrlr
r��set_visiblert�
set_labels)
rr+rr �original_headersr�Zvisible_headers�n�bodyr�rrr r8�s,



zBabyl.get_messagec	Cs�|�|�\}}|j�|�|j��t��}|j��}|dtks\|sHq\|�|�td��q,|j��}|tksv|s\qvq\|�	�}||j�
�}|dks�J�|j�|�}|�td�}||S)r2rvrir)r�r	r|r�rwrxr~rr}r�rrl)	rr+rr ryr�Zheadersrzr�rrr rAs"


zBabyl.get_bytescCst�|�|��dt��S)rCri)rwrxrAr}r~r*rrr r;(szBabyl.get_filecCs<|��t�}|j��D]}|�|�q|�|j�t|�S)z4Return a list of user-defined labels in the mailbox.)r�r`rtrNr\�difference_update�_special_labelsrG)r�labelsZ
label_listrrr ru,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)
r?rscSsg|]}|��r|���qSr)�strip�rS�labelrrr r_Cs�z'Babyl._generate_toc.<locals>.<listcomp>r�N�,�r�)r	r|r�rr~r�r�r�r@rArBr�rtr
r)rrCrDrGZlabel_listsrEr�r~rrr r'5s4



�zBabyl._generate_toccCsVdt}|dt7}|��}dd�|D�}|dd�|�t7}|d7}|�|�dS)	r"sBABYL OPTIONS:s
Version: 5css|]}|��VqdSr-)rer�rrr rTXr,z*Babyl._pre_mailbox_hook.<locals>.<genexpr>sLabels:r�r�N)r~rur�r)rr�Zbabylr~rrr rSszBabyl._pre_mailbox_hookcCs|�dt�dS)r$�Nr>r#rrr r]szBabyl._pre_message_hookcCs|�td�dS)r&r�Nr>r#rrr raszBabyl._post_message_hookcCsx|j��}t|t�r�g}g}|��D]$}||jvr>|�|�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,,� r�s1,,Frrirvrrjrks

r�rrNr�rmrnTrorprqru)%r	rrvr
rur}r�rrer~r?r'r	rwrxryrzr{r|r�r}�get_visiblerlr�r�r�r�r�r�r�rhr6rYrmr�r�r�)rr'rZspecial_labelsr~r�Zorig_bufferZorig_generatorr�Z
vis_bufferZ
vis_generatorrmZ
body_startZoriginal_posZ
first_passr rrr r(es�







�
�
zBabyl._install_message)NT)r�r�r�r��	frozensetr}r!r(r,r4r8rAr;rur'rrrr(rrrr r�s
	
rc@s*eZdZdZd	dd�Zdd�Zdd�ZdS)
r	z0Message 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(|dur�tjj�|�ntdt|���dS)zInitialize a Message instance.rlNru)rvr?r'r	�_become_message�copy�deepcopy�_explain_tor�r@r�Zmessage_from_stringrw�
TextIOWrapperZmessage_from_filerYZmessage_from_binary_filer!r�r�r&rrr r!�s



zMessage.__init__cCs4t|dg�}|jD]}||vr|j||j|<qdS)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��dS)z:Copy format-specific state to message insofar as possible.Nz Cannot convert to specified type)rvr	r�r&rrr r��s
zMessage._explain_to)N)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__cCs|jS)zReturn 'new' or 'cur'.)r�rErrr r�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�rg)rr�rrr r�szMaildirMessage.set_subdircCs"|j�d�r|jdd�SdSdS)�*Return as a string the flags that are set.�2,r�Nr�)r�r�rErrr �	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�r`r��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�r`r�rrr �remove_flagszMaildirMessage.remove_flagcCs|jS)z<Return delivery date of message, in seconds since the epoch.)r�rErrr r�!szMaildirMessage.get_datecCs4zt|�|_Wn ty.td|�d�Yn0dS)z9Set delivery date of message, in seconds since the epoch.zcan't convert to float: %sN)�floatr�rgr�)r�daterrr r�%szMaildirMessage.set_datecCs|jS)z%Get the message's "info" as a string.)r�rErrr r�,szMaildirMessage.get_infocCs&t|t�r||_ntdt|���dS)z Set the message's "info" string.zinfo must be a string: %sN)rvr�r�r�r�)r�inforrr r�0s
zMaildirMessage.set_infocCs�t|t�r8|�|���|�|���|�|����nht|t�r�t	|���}d|vr`|�
d�|��dkrv|�
d�d|vr�|�
d�d|vr�|�
d�d|vr�|�
d�|�d	t�
|����n�t|t��rt	|���}d|vr�|�d
�d|v�r|�d�d|v�r�|�d�n�t|t��r�t	|���}d|v�rD|�d
�d|v�rX|�d
�d|v�rl|�d�d|v�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-DAEMONrr�replied�flaggedrprq�Prs�$Cannot convert to specified type: %sN)rvr
r�r�r�r�r�r�r7r`r�r.r�r;rrOr
�	add_labelr	r�r�)rr'r�rrr r�7sP

















�zMaildirMessage._explain_to)N)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)r7z/Message with mbox- or MMDF-specific properties.�_fromNcCsV|�dd�t|tjj�rF|��}|durF|�d�rF|�|dd��t�||�dS)z'Initialize an mboxMMDFMessage instance.r�TNzFrom rt)r.rvr?r'r	r9r�r!)rr'r3rrr r!hsz_mboxMMDFMessage.__init__cCs|jS)z Return contents of "From " line.)r�rErrr r8qsz_mboxMMDFMessage.get_fromcCs4|dur*|durt��}|dt�|�7}||_dS)z>Set "From " line, formatting and appending time_ if specified.NT� )r�r;r:r�)rr4Ztime_rrr r.us
z_mboxMMDFMessage.set_fromcCs|�dd�|�dd�S)r��Statusr��X-Status)r7rErrr r�}sz_mboxMMDFMessage.get_flagscCs�t|�}d\}}dD]}||vr||7}|�|�qdD]}||vr8||7}|�|�q8|d�t|��7}z|�d|�Wnty�|�d|�Yn0z|�d|�Wnty�|�d|�Yn0dS)r�)r�r�)r�r�)r�r�r�r�r�r�N)r`r,r�r�replace_headerr0Z
add_header)rr�Zstatus_flagsZ
xstatus_flagsr�rrr r��s&z_mboxMMDFMessage.set_flagscCs$|�d�t|���t|�B��dSr�r�r�rrr r��sz_mboxMMDFMessage.add_flagcCs4d|vsd|vr0|�d�t|���t|���dS)r�r�r�r�Nr�r�rrr r��sz_mboxMMDFMessage.remove_flagc	Cs�t|t�r�t|���}d|vr(|�d�d|vr:|�d�d|vrL|�d�d|vr^|�d�d|vrp|�d�|d	=|d
=d�|����dd
��}z|�	t
�t�
|d���Wnttfy�Yn0�n
t|t�r�|�|���|�|���n�t|t��rXt|���}d|v�r"|�d�d|v�r6|�d�d|v�rJ|�d�|d	=|d
=n�t|t��r�t|���}d|v�r�|�d�d|v�r�|�d�d|v�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��statuszx-statusr����Nz%a %b %d %H:%M:%S %Yrrr�r�rprqr�)rvr
r`r�r�r�r�r8r�r��calendarZtimegmr��strptimerg�
OverflowErrorr7r�r.rrOr
r�r	r�r�)rr'r�Z
maybe_daterrr r��sb





�













�z_mboxMMDFMessage._explain_to)N)N)
r�r�r�r�r�r!r8r.r�r�r�r�r�rrrr r7cs
	
r7c@seZdZdZdS)rz&Message with mbox-specific properties.N�r�r�r�r�rrrr r�src@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__cCs|jdd�S)z4Return a list of sequences that include the message.N)r�rErrr rN�szMHMessage.get_sequencescCst|�|_dS)z3Set the list of sequences that include the message.N)rGr�)rrgrrr ri�szMHMessage.set_sequencescCs6t|t�r"||jvr2|j�|�ntdt|���dS)z8Add sequence to list of sequences including the message.zsequence type must be str: %sN)rvr�r�r�r�r��rrnrrr rO�s

zMHMessage.add_sequencecCs(z|j�|�Wnty"Yn0dS)zARemove sequence from the list of sequences including the message.N)r�r,rgr�rrr �remove_sequence�szMHMessage.remove_sequencecCsFt|t�rdt|���}d|vr*|�d�n|�d�|�d�d|vrP|�d�d|vrb|�d�n�t|t�r�t|���}d|vr�|�d�n
|�d	�d|vr�|�d�d|vr�|�d
�n�t|t�r�|��D]}|�|�q�n`t|t	��r$t|���}d|v�r|�
d�d|v�rB|�
d�nt|t��r2ntdt
|���d
S)z6Copy MH-specific state to message insofar as possible.rrr�r�r�r�r�r��ROr�r�rqr�N)rvr
r`rNr�r�r7rrOr
r�r	r�r�)rr'rgrnrrr r��sB










�zMHMessage._explain_to)N)r�r�r�r�r�r!rNrirOr�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.rt�_visibleNcCsg|_t�|_t�||�dS)z#Initialize a BabylMessage instance.N)rtr	r�r!r&rrr r!%szBabylMessage.__init__cCs|jdd�S)z'Return a list of labels on the message.N)rtrErrr ru+szBabylMessage.get_labelscCst|�|_dS)z&Set the list of labels on the message.N)rGrt)rr~rrr rx/szBabylMessage.set_labelscCs6t|t�r"||jvr2|j�|�ntdt|���dS)z+Add label to list of labels on the message.zlabel must be a string: %sN)rvr�rtr�r�r��rr�rrr r�3s

zBabylMessage.add_labelcCs(z|j�|�Wnty"Yn0dS)z4Remove label from the list of labels on the message.N)rtr,rgr�rrr �remove_label;szBabylMessage.remove_labelcCs
t|j�S)z3Return a Message representation of visible headers.�r	r�rErrr r�BszBabylMessage.get_visiblecCst|�|_dS)z2Set the Message representation of visible headers.Nr�)rZvisiblerrr rwFszBabylMessage.set_visiblecCsb|j��D](}||vr*|j�|||�q
|j|=q
dD]$}||vr8||jvr8|||j|<q8dS)z9Update and/or sensibly generate a set of visible headers.)ZDateZFromzReply-ToZToZCCZSubjectN)r�rHr�)r�headerrrr �update_visibleJs
zBabylMessage.update_visiblecCsrt|t�r~t|���}d|vr*|�d�n|�d�|�d�d|vsNd|vrX|�d�d|vrj|�d�d	|vr||�d
�n�t|t�r�t|���}d|vr�|�d�n
|�d�d	|vr�|�d
�d|vr�|�d�n�t|t��rt|���}d|v�r|�d�d|v�rn|�d�nTt|t	��rP|�
|���|��D]}|�|��q<nt|t
��r^ntdt|���dS)z9Copy Babyl-specific state to message insofar as possible.rrr�r�rsror�rqr�rpr�r�r�r�r�r�r�N)rvr
r`rur�r�r7rrOr
rwr�r�r	r�r�)rr'r~r�rrr r�UsH










�zBabylMessage._explain_to)N)r�r�r�r�r�r!rurxr�r�r�rwr�r�rrrr r
 s
r
c@seZdZdZdS)rz&Message with MMDF-specific properties.Nr�rrrr rsrc@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|��|_n||_dS)zInitialize a _ProxyFile.N)r	r�_pos)rr��posrrr r!�sz_ProxyFile.__init__cCs|�||jj�S�zRead bytes.)�_readr	rl�r�sizerrr rl�sz_ProxyFile.readcCs|�||jj�Sr�)r�r	�read1r�rrr r��sz_ProxyFile.read1cCs|�||jj�S)zRead a line.)r�r	r�r�rrr r��sz_ProxyFile.readlinecCs<g}|D].}|�|�|dur|t|�8}|dkrq8q|S)zRead multiple lines.Nr)r�r�)r�sizehintrVr�rrr �	readlines�s
z_ProxyFile.readlinesccs|��}|sdS|VqdS)zIterate over lines.N)r�)rr�rrr rM�sz_ProxyFile.__iter__cCs|jS)zReturn the position.)r�rErrr r�sz_ProxyFile.tellrcCs4|dkr|j�|j�|j�||�|j��|_dS)zChange position.r�N�r	r|r�r�r�offset�whencerrr r|�sz_ProxyFile.seekcCs4t|d�r0zt|jd�r"|j��W|`n|`0dS)zClose the file.r	rdN)rYr	rdrErrr rd�s

z_ProxyFile.closecCs2|durd}|j�|j�||�}|j��|_|S)z"Read size bytes using read_method.Nrrr�)rr��read_methodrVrrr r��sz_ProxyFile._readcCs|S)z$Context management protocol support.rrErrr �	__enter__�sz_ProxyFile.__enter__cGs|��dSr-)rd)r�excrrr �__exit__�sz_ProxyFile.__exit__cCs
|j��Sr-)r	�readablerErrr r��sz_ProxyFile.readablecCs
|j��Sr-)r	�writablerErrr r��sz_ProxyFile.writablecCs
|j��Sr-)r	�seekablerErrr r��sz_ProxyFile.seekablecCs
|j��Sr-)r	r^rErrr r^�sz_ProxyFile.flushcCs&t|d�sdSt|jd�sdS|jjS)Nr	TrLF)rYr	rLrErrr rL�s

z_ProxyFile.closed)N)N)N)N)N)r)r�r�r�r�r!rlr�r�r�rMrr|rdr�r�r�r�r�r�r^�propertyrLr�rr�rrrr r��s(





		
r�c@s<eZdZdZddd�Zdd�Zddd	�Zd
d�Zdd
�ZdS)r5z&A read-only wrapper of part of a file.NcCst�|||�||_||_dS)zInitialize a _PartialFile.N)r�r!�_start�_stop)rr�rr rrr r!�sz_PartialFile.__init__cCst�|�|jS)z*Return the position with respect to start.)r�rr�rErrr r�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�rrr r|�sz_PartialFile.seekcCsB|j|j}|dkrdS|dus0|dks0||kr4|}t�|||�S)z;Read size bytes using read_method, honoring start and stop.rr,N)r�r�r�r�)rr�r��	remainingrrr r��sz_PartialFile._readcCst|d�r|`dS)Nr	)rYr	rErrr rds
z_PartialFile.close)NN)r)	r�r�r�r�r!rr|r�rdrrrr r5�s


	r5Tc
Cs�d}�zftrrzt�|tjtjB�WnLtyp}z4|jtjtjtjfvrZt	d|j
��n�WYd}~n
d}~00|�rjzt|j
d�}|��WnHty�}z0|jtjtjfvr�WYd}~WdS�WYd}~n
d}~00z^zt
�|j
|j
d�d}Wn0ttf�y*t
�|j
|j
d�d}Yn0t
�|j
�Wn.t�yht
�|j
�t	d|j
��Yn0Wn8t�r�t�|tj�|�r�t
�|j
d��Yn0dS)z(Lock file f using lockf and dot locking.Fzlockf: lock unavailable: %sN�.lockTzdot lock unavailable: %s)�fcntl�lockfZLOCK_EXZLOCK_NBr�r��EAGAINrrrr�rrdrr�r�r�r�rjr�r,�LOCK_UN)r�rZdotlock_doner�Zpre_lockrrr rsL�
�rcCs8trt�|tj�tj�|jd�r4t�|jd�dS)z*Unlock file f using lockf and dot locking.r�N)r�r�r�rrr�r�r,�r�rrr r9src	CsDt�|tjtjBtjBd�}zt|d�Wt�|�St�|�0dS)zCCreate a file if it doesn't exist and open for reading and writing.r�rN)rr�r�rI�O_RDWRrd)r�fdrrr r�@s

�r�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�)rrrr rHs�rcCs$|��ttd�r t�|���dS)z0Ensure changes to file f are physically on disk.�fsyncN)r^rYrr��filenor�rrr rNs
rcCst|�|��dS)z:Close file f, ensuring all changes are physically on disk.N)rrdr�rrr r�Tsr�c@seZdZdZdS)rz"Raised for module-specific errors.Nr�rrrr rZsrc@seZdZdZdS)rz:The specified mailbox does not exist and won't be created.Nr�rrrr r]src@seZdZdZdS)rz>The specified mailbox is not empty and deletion was requested.Nr�rrrr r`src@seZdZdZdS)rz)Another process caused an action to fail.Nr�rrrr rcsrc@seZdZdZdS)rz)A file appears to have an invalid format.Nr�rrrr rfsr)T)2r�rr�r�r�r�r�r�r?Z
email.messageZemail.generatorrwr9�typesrr��ImportError�__all__r~rerrrr+rrrrr'r	r
r7rrr
rr�r5rrr�rrr��	Exceptionrrrrrrrrr �<module>sl
j8DB4-3z%mqH_e'
*

Zerion Mini Shell 1.0