Your IP : 3.148.144.139


Current Path : /opt/alt/python39/lib64/python3.9/__pycache__/
Upload File :
Current File : //opt/alt/python39/lib64/python3.9/__pycache__/nntplib.cpython-39.opt-2.pyc

a

R�f?��	@s:ddlZddlZddlZddlZddlZzddlZWneyJdZYn0dZddlm	Z
ddlmZgd�ZdZ
Gdd	�d	e�ZGd
d�de�ZGdd
�d
e�ZGdd�de�ZGdd�de�ZGdd�de�ZdZdZhd�Zgd�Zddd�ZdZe�dgd��Ze�dgd��Zd d!�Z	d"d#�ZdYd$d%�ZdZd&d'�Z d[d(d)�Z!e�rVd*d+�Z"Gd,d-�d-�Z#e�r�Gd.d/�d/e#�Z$e�%d/�e&d0k�r6ddl'Z'e'j(d1d2�Z)e)j*d3d4d5d6d7�e)j*d8d9d:d;d7�e)j*d<d=d>e+d?eefd@�e)j*dAdBdCe+dDd@�e)j*dEdFdGddHdI�e)�,�Z-e-j.Z.e-j�s>e.d>k�r.eZ.e#e-j/e.dJ�Z0ne.d>k�rLeZ.e$e-j/e.dJ�Z0e0�1�Z2dKe2v�rte0�3�e0�4e-j4�\Z5Z6Z7Z8Z9e:dLe9dMe6dNe7dOe8�dPdQ�Z;e<e+e8�e-j=dR�Z7e0�>e7e8�\Z5Z?e?D]Z\Z@ZAe	eAdS��BdTdR�dZCe	eAdU�ZDe+eAd�ZEe:dV�Fe@e;eCdW�e;eDdX�eE���q�e0�G�dS)\�NFT)�
decode_header)�_GLOBAL_DEFAULT_TIMEOUT)�NNTP�	NNTPError�NNTPReplyError�NNTPTemporaryError�NNTPPermanentError�NNTPProtocolError�
NNTPDataErrorric@seZdZdd�ZdS)rcGs>tj|g|�R�z|d|_Wnty8d|_Yn0dS)NrzNo response given)�	Exception�__init__�response�
IndexError)�self�args�r�,/opt/alt/python39/lib64/python3.9/nntplib.pyrbs
zNNTPError.__init__N)�__name__�
__module__�__qualname__rrrrrr`src@seZdZdS)rN�rrrrrrrrisrc@seZdZdS)rNrrrrrrmsrc@seZdZdS)rNrrrrrrqsrc@seZdZdS)r	Nrrrrrr	usr	c@seZdZdS)r
Nrrrrrr
ysr
�wi3>Z220Z224Z282Z100Z101Z225Z231Z230�215Z222Z221�211)�subject�from�datez
message-idZ
references�:bytes�:linesrr)�bytes�lines�
�	GroupInfo)�group�last�first�flag�ArticleInfo)Znumber�
message_idr cCsJg}t|�D]2\}}t|t�r4|�|�|p,d��q|�|�qd�|�S)N�ascii�)�_email_decode_header�
isinstancer�append�decode�join)Z
header_str�parts�v�encrrrr�s
rcCs�g}|D]`}|ddkr:|dd��d�\}}}d|}n|�d�\}}}|��}t�||�}|�|�qt}t|�t|�kr�td��|dt|��|kr�td��|S)Nr�:�z$LIST OVERVIEW.FMT response too shortz*LIST OVERVIEW.FMT redefines default fields)�	partition�lower�_OVERVIEW_FMT_ALTERNATIVES�getr-�_DEFAULT_OVERVIEW_FMT�lenr
)r �fmt�line�name�_�suffix�defaultsrrr�_parse_overview_fmt�s
rAcCs�tt�}g}|D]�}i}|�d�^}}t|�}t|�D]�\}	}
|	t|�krLq6||	}|�d�}|	|kr�|s�|d}
|
r�|
dt|
����|
kr�td��|
r�|
t|
�d�nd}
|
|||	<q6|�||f�q|S)N�	r3z: z?OVER/XOVER response doesn't include names of additional headers)	r:r9�split�int�	enumerate�
startswithr6r
r-)r r;Zdata_process_funcZ
n_defaultsZoverviewr<�fieldsZarticle_number�tokens�i�token�
field_nameZis_metadata�hrrr�_parse_overview�s&
rMcCs�|dur |dd�}|dd�}t|dd��}t|dd��}t|dd��}t|dd��}t|dd��}t|dd��}|dkr�|d7}n|dkr�|d	7}t�||||||�S)
Ni�������������Fi��dil)rD�datetime)�date_str�time_strZhoursZminutesZseconds�yearZmonthZdayrrr�_parse_datetime�s
rXcCsPt|tj�sd}n
d�|�}|j}|r<|d}d�||�}nd�||�}||fS)NZ000000z({0.hour:02d}{0.minute:02d}{0.second:02d}rSz{0:02d}{1.month:02d}{1.day:02d}z{0:04d}{1.month:02d}{1.day:02d})r,rT�formatrW)ZdtZlegacyrV�yrUrrr�_unparse_datetime�s

r[cCs|durt��}|j||d�S)N)Zserver_hostname)�sslZ_create_stdlib_contextZwrap_socket)�sock�contextZhostnamerrr�_encrypt_onsr_c@seZdZdZdZeddddefdd�Zdd�Zd	d
�Z	dd�Z
d
d�Zdd�Zdd�Z
dd�ZeZdd�Zdd�Zdidd�Zdd�Zdjdd�Zd d!�Zdkd"d#�Zdld$d%�Zd&d'�Zd(d)�Zd*d+�Zdd,�d-d.�Zdd,�d/d0�Zdmdd,�d1d2�Zd3d4�Zd5d6�Zd7d8�Z d9d:�Z!dd,�d;d<�Z"d=d>�Z#d?d@�Z$dndAdB�Z%dCdD�Z&dEdF�Z'dodGdH�Z(dpdd,�dIdJ�Z)dqdd,�dKdL�Z*drdd,�dMdN�Z+dOdP�Z,dd,�dQdR�Z-dd,�dSdT�Z.dd,�dUdV�Z/dWdX�Z0dYdZ�Z1d[d\�Z2d]d^�Z3d_d`�Z4dadb�Z5dsdcdd�Z6dedf�Z7e8�rdtdgdh�Z9dS)urzutf-8�surrogateescapeNFcCs~||_||_|�|�|_d|_z2|j�d�|_|�|�|s@|rN|�|||�Wn(|jrh|j��|j���Yn0dS)N�rwb)	�host�port�_create_socketr]�file�makefile�
_base_init�login�close)rrbrc�user�password�
readermode�usenetrc�timeoutrrrr8s


z
NNTP.__init__cCs^d|_|��|_d|_|��d|_|rNd|jvrN|��|jsNd|_|��d|_d|_dS)NrF�READER)	�	debugging�_getresp�welcome�_caps�getcapabilities�readermode_afterauth�_setreadermode�tls_on�
authenticated)rrlrrrrg[s
	zNNTP._base_initcCs|S�Nr�rrrr�	__enter__}szNNTP.__enter__c	s^�fdd�}|�rZz6z���Wnttfy6Yn0W|�rZ���n|�rX���0dS)Ncs
t�d�S)Nre)�hasattrrrzrr�<lambda>��zNNTP.__exit__.<locals>.<lambda>)�quit�OSError�EOFError�_close)rrZis_connectedrrzr�__exit__�s
�z
NNTP.__exit__cCs<|dur|std��t�d||j|j�t�|j|jf|�S)Nz0Non-blocking socket (timeout=0) is not supportedznntplib.connect)�
ValueError�sys�auditrbrc�socketZcreate_connection)rrnrrrrd�szNNTP._create_socketcCs|jrtdt|j��|jS)Nz	*welcome*)rp�print�reprrrrzrrr�
getwelcome�szNNTP.getwelcomec	Cs�|jdur~d|_d|_z|��\}}WnttfyBi|_Yn<0||_d|vrfttt|d��|_d|vr~d�	|d�|_|jS)Nr4ZVERSIONZIMPLEMENTATION� )
rs�nntp_versionZnntp_implementation�capabilitiesrr�max�maprDr/)r�resp�capsrrrrt�s
zNNTP.getcapabilitiescCs
||_dSry)rp)r�levelrrr�set_debuglevel�szNNTP.set_debuglevelcCsHt�d||�|t}|jdkr.tdt|��|j�|�|j��dS)Nznntplib.putliner4z*put*)	r�r��_CRLFrpr�r�re�write�flush�rr<rrr�_putline�s
z
NNTP._putlinecCs2|jrtdt|��|�|j|j�}|�|�dS)Nz*cmd*)rpr�r��encode�encoding�errorsr�r�rrr�_putcmd�szNNTP._putcmdTcCs�|j�td�}t|�tkr$td��|jdkr<tdt|��|sDt�|r�|dd�t	krf|dd�}n|dd�t	vr�|dd�}|S)Nr4z
line too longz*get*rQ���)
re�readline�_MAXLINEr:r
rpr�r�r�r�)rZ
strip_crlfr<rrr�_getline�s
z
NNTP._getlinecCsl|��}|jrtdt|��|�|j|j�}|dd�}|dkrHt|��|dkrXt|��|dvrht	|��|S)Nz*resp*r4�4�5Z123)
r�rpr�r�r.r�r�rrr	)rr��crrrrq�sz
NNTP._getrespcCs�d}z�t|ttf�r"t|d�}}|��}|dd�tvrBt|��g}|dur�dtdf}|�d�}||vrnq�|�	d�r�|dd�}|�
|�qZn8d}|��}||kr�q�|�	d�r�|dd�}|�|�q�W|r�|��n|r�|��0||fS)N�wb��.s.
Fs..r4)
r,�strr�openrq�	_LONGRESPrr�r�rFr�r-ri)rreZ
openedFiler�r Zterminatorsr<�
terminatorrrr�_getlongresp�s8	



�
zNNTP._getlongrespcCs|�|�|��Sry)r�rqr�rrr�	_shortcmds
zNNTP._shortcmdcCs|�|�|�|�Sry�r�r�)rr<rerrr�_longcmds
z
NNTP._longcmdcs.��|���|�\}}|�fdd�|D�fS)Ncsg|]}|��j�j��qSr)r.r�r���.0r<rzrr�
<listcomp>+s�z'NNTP._longcmdstring.<locals>.<listcomp>r�)rr<rer��listrrzr�_longcmdstring$s

�zNNTP._longcmdstringcCs`z|jWStyYn0z|�d�\}}WntyLtdd�}Yn
0t|�}||_|S)NzLIST OVERVIEW.FMT)Z_cachedoverviewfmt�AttributeErrorr�rr9rA)rr�r r;rrr�_getoverviewfmt.szNNTP._getoverviewfmtcCsdd�|D�S)NcSsg|]}t|����qSr)r"rCr�rrrr�Ar~z#NNTP._grouplist.<locals>.<listcomp>r)rr rrr�
_grouplist?szNNTP._grouplistcCs8i}|�d�\}}|D]}|��^}}|||<q||fS)NZCAPABILITIES)r�rC)rr�r�r r<r=rHrrrr�Cs
zNNTP.capabilities)recCsbt|tjtjf�s$td�|jj���t||jdk�\}}d�||�}|�	||�\}}||�
|�fS)N�Athe date parameter must be a date or datetime object, not '{:40}'rNzNEWGROUPS {0} {1})r,rTr�	TypeErrorrY�	__class__rr[r�r�r�)rrrerUrV�cmdr�r rrr�	newgroupsQs��zNNTP.newgroupscCsRt|tjtjf�s$td�|jj���t||jdk�\}}d�|||�}|�	||�S)Nr�rNzNEWNEWS {0} {1} {2})
r,rTrr�rYr�rr[r�r�)rr#rrerUrVr�rrr�newnewsas��zNNTP.newnewscCs4|durd|}nd}|�||�\}}||�|�fS)NzLIST ACTIVE ZLIST)r�r�)r�
group_patternre�commandr�r rrrr�qs

z	NNTP.listcCs�t�d�}|�d|�\}}|�d�s8|�d|�\}}i}|D]:}|�|���}|r@|�dd�\}	}
|sr|
S|
||	<q@|r�||fSdSdS)Nz^(?P<group>[^ 	]+)[ 	]+(.*)$zLIST NEWSGROUPS rzXGTITLE r4rNr*)�re�compiler�rF�search�stripr#)rr�Z
return_allZline_patr�r �groupsZraw_line�matchr=Zdescrrr�_getdescriptions�s


zNNTP._getdescriptionscCs|�|d�S)NF�r�)rr#rrr�description�szNNTP.descriptioncCs|�|d�S)NTr�)rr�rrr�descriptions�szNNTP.descriptionscCs�|�d|�}|�d�s t|��|��}d}}}t|�}|dkr�|d}|dkr�|d}|dkr�|d}|dkr�|d��}|t|�t|�t|�|fS)NzGROUP rrr4rNr�rO)r�rFrrCr:r6rD)rr=r��words�countr%r$�nrrrr#�s

z
NNTP.groupcCs|�d|�S)NZHELP)r�)rrerrr�help�sz	NNTP.helpcCs8|�d�st|��|��}t|d�}|d}|||fS)NZ22r4rN)rFrrCrD)rr�r��art_numr(rrr�
_statparse�s
zNNTP._statparsecCs|�|�}|�|�Sry)r�r�)rr<r�rrr�_statcmd�s
z
NNTP._statcmdcCs"|r|�d�|��S|�d�SdS)NzSTAT {0}ZSTAT)r�rY)r�message_specrrr�stat�s	z	NNTP.statcCs
|�d�S)NZNEXT�r�rzrrr�next�sz	NNTP.nextcCs
|�d�S)NZLASTr�rzrrrr$�sz	NNTP.lastcCs0|�||�\}}|�|�\}}}|t|||�fSry)r�r�r')rr<rer�r r�r(rrr�_artcmd�szNNTP._artcmdcCs$|durd�|�}nd}|�||�S)NzHEAD {0}ZHEAD�rYr��rr�rer�rrr�head�sz	NNTP.headcCs$|durd�|�}nd}|�||�S)NzBODY {0}ZBODYr�r�rrr�bodysz	NNTP.bodycCs$|durd�|�}nd}|�||�S)NzARTICLE {0}ZARTICLEr�r�rrr�articleszNNTP.articlecCs
|�d�S)NZSLAVE)r�rzrrr�slave!sz
NNTP.slavecsDt�d��|�d�||�|�\}}�fdd��|�fdd�|D�fS)Nz^([0-9]+) ?(.*)
?zXHDR {0} {1}cs��|�}|r|�dd�S|S)Nr4rN)r�r#)r<�m)�patrr�
remove_number2s
z NNTP.xhdr.<locals>.remove_numbercsg|]}�|��qSrrr�)r�rrr�5r~zNNTP.xhdr.<locals>.<listcomp>)r�r�r�rY)rZhdrr�rer�r r)r�r�r�xhdr's	
z	NNTP.xhdrcCs.|�d�||�|�\}}|��}|t||�fS)Nz
XOVER {0}-{1})r�rYr�rM)r�start�endrer�r r;rrr�xover7s
	�z
NNTP.xoverc	Csxd|jvrdnd}t|ttf�r>|\}}|d�||p6d�7}n|durR|d|}|�||�\}}|��}|t||�fS)NZOVERZXOVERz {0}-{1}r*r�)rsr,�tupler�rYr�r�rM)	rr�rer�r�r�r�r r;rrr�overEsz	NNTP.overcCsb|�d�}|�d�st|��|��}t|�dkr8t|��|d}t|�dkrTt|��|t|d�fS)NZDATEZ111rNr4�)r�rFrrCr:r
rX)rr��elemrrrrr`s

z	NNTP.datecCs�|�|�}|�d�st|��t|ttf�r2|��}|D]:}|�t�sR|�	d�t}|�d�rdd|}|j
�|�q6|j
�d�|j
��|�
�S)N�3r!r�s.
)r�rFrr,r�	bytearray�
splitlines�endswithr��rstriprer�r�rq)rr��fr�r<rrr�_postqs




z
NNTP._postcCs|�d|�S)NZPOST)r�)r�datarrr�post�sz	NNTP.postcCs|�d�|�|�S)Nz	IHAVE {0})r�rY)rr(r�rrr�ihave�sz
NNTP.ihavecCs4z"|jr|j��|`W|j��n|j��0dSry)rerir]rzrrrr��s

zNNTP._closecCs&z|�d�}W|��n
|��0|S)NZQUIT)r�r�)rr�rrrr�sz	NNTP.quitcCs�|jrtd��|s|std��z<|rX|sXddl}|��}|�|j�}|rX|d}|d}WntylYn0|svdS|�d|�}|�d�r�|s�t|��n |�d|�}|�d�s�t	|��d|_
|��|jr�d	|j
vr�|�
�d|_
|��dS)
NzAlready logged in.z7At least one of `user` and `usenetrc` must be specifiedrrNzauthinfo user Z381zauthinfo pass Z281ro)rxr��netrcZauthenticatorsrbr�r�rFrrrsrtrurv)rrjrkrmr�ZcredentialsZauthr�rrrrh�s>�


z
NNTP.loginc
Cs`z|�d�|_WnJty"Yn:tyZ}z"|j�d�rDd|_n�WYd}~n
d}~00dS)Nzmode readerZ480T)r�rrrrr
rFru)r�errrrv�szNNTP._setreadermodecCs||jrtd��|jrtd��|�d�}|�d�rp|j��t|j||j	�|_|j�
d�|_d|_d|_|��nt
d��dS)NzTLS is already enabled.z+TLS cannot be started after authentication.�STARTTLSZ382raTzTLS failed to start.)rwr�rxr�rFrerir_r]rbrfrsrtr)rr^r�rrr�starttls�s



z
NNTP.starttls)T)N)N)N)N)N)N)N)N)N)NNT)N):rrrr�r��	NNTP_PORTrrrgr{r�rdr�rtr��debugr�r�r�rqr�r�r�r�r�r�r�r�r�r�r�r�r�r#r�r�r�r�r�r$r�r�r�r�r�r�r�r�rr�r�r�r�rrhrv�	_have_sslr�rrrrr(sp
�
#"		

.







		
)
rcs8eZdZedddddef�fdd�	Z�fdd�Z�ZS)�NNTP_SSLNFc			s"||_t��|||||||�dSry)�ssl_context�superr)	rrbrcrjrkr�rlrmrn�r�rrr�s�zNNTP_SSL.__init__cs@t��|�}zt||j|j�}Wn|���Yn0|SdSry)r�rdr_r�rbri)rrnr]r�rrrdszNNTP_SSL._create_socket)rrr�
NNTP_SSL_PORTrrrd�
__classcell__rrr�rr��s�r��__main__zJ        nntplib built-in demo - display the latest articles in a newsgroup)r�z-gz--groupzgmane.comp.python.generalz3group to fetch messages from (default: %(default)s))�defaultr�z-sz--serverz
news.gmane.ioz+NNTP server hostname (default: %(default)s)z-pz--portr�z#NNTP port number (default: %s / %s))r��typer�z-nz
--nb-articles�
z2number of articles to fetch (default: %(default)s)z-Sz--ssl�
store_truezuse NNTP over SSL)�actionr�r�)rbrcr�ZGroupZhaszarticles, range�tocCs$t|�|kr |d|d�d}|S)NrOz...)r:)�sZlimrrr�cut3srr4r�<rz{:7} {:20} {:42} ({})��*)N)N)F)Hr�r��collectionsrTr�r\�ImportErrorr�Zemail.headerrr+r�__all__r�rrrrrr	r
r�r�r�r9r7r��
namedtupler"r'rArMrXr[r_rr�r-r�argparse�ArgumentParser�parser�add_argumentrD�
parse_argsrrcZserverrrtr�r�r#r�r�r%r$r=r�rr�Znb_articlesr�Z	overviewsZartnumr�rCZauthorrr rYrrrrr�<module>Bs�

	���


S


�
�
���


�


?>