AlkantarClanX12

Your IP : 18.190.219.178


Current Path : /opt/alt/python37/lib64/python3.7/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib64/python3.7/__pycache__/nntplib.cpython-37.opt-2.pyc

B

YI~dO��@s�ddlZddlZddlZddlZddlZyddlZWnek
rLdZYnXdZddlm	Z
ddlmZdddd	d
ddd
gZdZ
Gdd�de�ZGdd�de�ZGdd	�d	e�ZGdd
�d
e�ZGdd�de�ZGdd�de�ZdZdZdddddddddd d!d"hZd#d$d%d&d'd(d)gZd(d)d*�Zd+Ze�d,d-d.d/d0g�Ze�d1d2d3d4g�Zd5d
�Z	d6d7�Zdld8d9�Zdmd:d;�Z dnd<d=�Z!e�r�d>d?�Z"Gd@dA�dA�Z#GdBd�de#�Z$e�r�GdCdD�dDe#�Z%e�&dD�e'dEk�r|ddl(Z(e(j)dFdG�Z*e*j+dHdIdJdKdL�e*j+dMdNdOdPdL�e*j+dQdRdSe,dTeefdU�e*j+dVdWdXe,dYdU�e*j+dZd[d\dd]d^�e*�-�Z.e.j/Z/e.j�s�e/dSk�rpeZ/e$e.j0e/d_�Z1ne/dSk�r�eZ/e%e.j0e/d_�Z1e1�2�Z3d`e3k�r�e1�4�e1�5e.j5�\Z6Z7Z8Z9Z:e;dae:dbe7dce8dde9�dedf�Z<e=e,e9�e.j>dg�Z8e1�?e8e9�\Z6Z@xbe@D]Z\ZAZBe	eBd$��Cdhdg�dZDe	eBd#�ZEe,eBd)�ZFe;di�GeAe<eDdj�e<eEdk�eF���qWe1�H�dS)o�NFT)�
decode_header)�_GLOBAL_DEFAULT_TIMEOUT�NNTP�	NNTPError�NNTPReplyError�NNTPTemporaryError�NNTPPermanentError�NNTPProtocolError�
NNTPDataErrorric@seZdZdd�ZdS)rcGs>tj|f|��y|d|_Wntk
r8d|_YnXdS)NrzNo response given)�	Exception�__init__�response�
IndexError)�self�args�r�,/opt/alt/python37/lib64/python3.7/nntplib.pyrbs
zNNTPError.__init__N)�__name__�
__module__�__qualname__rrrrrr`sc@seZdZdS)rN)rrrrrrrrisc@seZdZdS)rN)rrrrrrrrmsc@seZdZdS)rN)rrrrrrrrqsc@seZdZdS)r	N)rrrrrrrr	usc@seZdZdS)r
N)rrrrrrrr
ys�wi3Z100Z101�211�215Z220Z221Z222Z224Z225Z230Z231Z282�subject�from�datez
message-idZ
referencesz:bytesz:lines)�bytes�liness
�	GroupInfo�group�last�first�flag�ArticleInfoZnumber�
message_idrcCsNg}x>t|�D]2\}}t|t�r6|�|�|p.d��q|�|�qWd�|�S)N�ascii�)�_email_decode_header�
isinstancer�append�decode�join)Z
header_str�parts�v�encrrrr�s
cCs�g}xh|D]`}|ddkr<|dd��d�\}}}d|}n|�d�\}}}|��}t�||�}|�|�q
Wt}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

r=cCs�tt�}g}x�|D]�}i}|�d�^}}t|�}x�t|�D]�\}	}
|	t|�krPq:||	}|�d�}|	|kr�|s�|d}
|
r�|
dt|
����|
kr�td��|
r�|
t|
�d�nd}
|
|||	<q:W|�||f�qW|S)N�	r/z: z?OVER/XOVER response doesn't include names of additional headers)	r6r5�split�int�	enumerate�
startswithr2r
r))rr7Zdata_process_funcZ
n_defaultsZoverviewr8ZfieldsZarticle_number�tokens�i�tokenZ
field_nameZis_metadata�hrrr�_parse_overview�s&

rGcCs�|dkr |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)r@�datetime)�date_str�time_strZhoursZminutesZseconds�yearZmonthZdayrrr�_parse_datetime�s
rRcCsPt|tj�sd}n
d�|�}|j}|r<|d}d�||�}nd�||�}||fS)NZ000000z({0.hour:02d}{0.minute:02d}{0.second:02d}rMz{0:02d}{1.month:02d}{1.day:02d}z{0:04d}{1.month:02d}{1.day:02d})r(rN�formatrQ)Zdt�legacyrP�yrOrrr�_unparse_datetime�s

rVcCs|dkrt��}|j||d�S)N)Zserver_hostname)�sslZ_create_stdlib_contextZwrap_socket)�sock�contextZhostnamerrr�_encrypt_onsrZc@seZdZdZdZdefdd�Zdd�Zdd	�Zd
d�Z	dd
�Z
dd�ZeZdd�Z
dd�Zdhdd�Zdd�Zdidd�Zdd�Zdjdd�Zdkdd �Zd!d"�Zd#d$�Zd%d&�Zdd'�d(d)�Zdd'�d*d+�Zdldd'�d,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zdd'�d6d7�Zd8d9�Z d:d;�Z!dmd<d=�Z"d>d?�Z#d@dA�Z$dndBdC�Z%dodd'�dDdE�Z&dpdd'�dFdG�Z'dqdd'�dHdI�Z(dJdK�Z)dd'�dLdM�Z*dd'�dNdO�Z+dd'�dPdQ�Z,dd'�dRdS�Z-dTdU�Z.dVdW�Z/dXdY�Z0dZd[�Z1d\d]�Z2d^d_�Z3d`da�Z4drdbdc�Z5ddde�Z6e7�rdsdfdg�Z8dS)t�	_NNTPBasezutf-8�surrogateescapeNcCsj||_||_d|_|��|_d|_|��d|_|rZd|jkrZ|��|jsZd|_|��d|_	d|_
dS)NrF�READER)�host�file�	debugging�_getresp�welcome�_caps�getcapabilities�readermode_afterauth�_setreadermode�tls_on�
authenticated)rr_r^�
readermode�timeoutrrrr8s
	z_NNTPBase.__init__cCs|S)Nr)rrrr�	__enter__gsz_NNTPBase.__enter__c	sR�fdd�}|�rNz*y���Wnttfk
r8YnXWd|�rL���XdS)Ncs
t�d�S)Nr_)�hasattrr)rrr�<lambda>k�z$_NNTPBase.__exit__.<locals>.<lambda>)�quit�OSError�EOFError�_close)rrZis_connectedr)rr�__exit__js
z_NNTPBase.__exit__cCs|jrtdt|j��|jS)Nz	*welcome*)r`�print�reprrb)rrrr�
getwelcomeusz_NNTPBase.getwelcomec	Cs�|jdkr�d|_d|_y|��\}}Wnttfk
rDi|_Yn<X||_d|krhttt|d��|_d|kr�d�	|d�|_|jS)Nr0ZVERSIONZIMPLEMENTATION� )
rc�nntp_versionZnntp_implementation�capabilitiesrr�max�mapr@r+)r�resp�capsrrrrd~s
z_NNTPBase.getcapabilitiescCs
||_dS)N)r`)r�levelrrr�set_debuglevel�sz_NNTPBase.set_debuglevelcCs:|t}|jdkr tdt|��|j�|�|j��dS)Nr0z*put*)�_CRLFr`rtrur_�write�flush)rr8rrr�_putline�s

z_NNTPBase._putlinecCs2|jrtdt|��|�|j|j�}|�|�dS)Nz*cmd*)r`rtru�encode�encoding�errorsr�)rr8rrr�_putcmd�sz_NNTPBase._putcmdTcCs�|j�td�}t|�tkr$td��|jdkr<tdt|��|sDt�|r�|dd�t	krf|dd�}n|dd�t	kr�|dd�}|S)Nr0z
line too longz*get*rK���)
r_�readline�_MAXLINEr6r
r`rtrurqr�)rZ
strip_crlfr8rrr�_getline�s
z_NNTPBase._getlinecCsl|��}|jrtdt|��|�|j|j�}|dd�}|dkrHt|��|dkrXt|��|dkrht	|��|S)Nz*resp*r0�4�5Z123)
r�r`rtrur*r�r�rrr	)rr|�crrrra�sz_NNTPBase._getrespcCs�d}z�t|ttf�r"t|d�}}|��}|dd�tkrBt|��g}|dk	r�dtdf}xv|�d�}||krpP|�	d�r�|dd�}|�
|�q\Wn<d}x6|��}||kr�P|�	d�r�|dd�}|�|�q�WWd|r�|��X||fS)N�wb��.s.
Fs..r0)
r(�strr�openra�	_LONGRESPrr�r�rBr�r)�close)rr_Z
openedFiler|rZterminatorsr8�
terminatorrrr�_getlongresp�s8	



z_NNTPBase._getlongrespcCs|�|�|��S)N)r�ra)rr8rrr�	_shortcmd�s
z_NNTPBase._shortcmdcCs|�|�|�|�S)N)r�r�)rr8r_rrr�_longcmds
z_NNTPBase._longcmdcs.��|���|�\}}|�fdd�|D�fS)Ncsg|]}|��j�j��qSr)r*r�r�)�.0r8)rrr�
<listcomp>sz,_NNTPBase._longcmdstring.<locals>.<listcomp>)r�r�)rr8r_r|�listr)rr�_longcmdstrings
z_NNTPBase._longcmdstringcCsby|jStk
rYnXy|�d�\}}Wn tk
rNtdd�}Yn
Xt|�}||_|S)NzLIST OVERVIEW.FMT)Z_cachedoverviewfmt�AttributeErrorr�rr5r=)rr|rr7rrr�_getoverviewfmtsz_NNTPBase._getoverviewfmtcCsdd�|D�S)NcSsg|]}t|����qSr)rr?)r�r8rrrr�$sz(_NNTPBase._grouplist.<locals>.<listcomp>r)rrrrr�
_grouplist"sz_NNTPBase._grouplistcCs<i}|�d�\}}x |D]}|��^}}|||<qW||fS)NZCAPABILITIES)r�r?)rr}r|rr8r9rCrrrry&s
z_NNTPBase.capabilities)r_cCsbt|tjtjf�s$td�|jj���t||jdk�\}}d�||�}|�	||�\}}||�
|�fS)NzAthe date parameter must be a date or datetime object, not '{:40}'rHzNEWGROUPS {0} {1})r(rNr�	TypeErrorrS�	__class__rrVrxr�r�)rrr_rOrP�cmdr|rrrr�	newgroups4sz_NNTPBase.newgroupscCsRt|tjtjf�s$td�|jj���t||jdk�\}}d�|||�}|�	||�S)NzAthe date parameter must be a date or datetime object, not '{:40}'rHzNEWNEWS {0} {1} {2})
r(rNrr�rSr�rrVrxr�)rrrr_rOrPr�rrr�newnewsDsz_NNTPBase.newnewscCs4|dk	rd|}nd}|�||�\}}||�|�fS)NzLIST ACTIVE ZLIST)r�r�)r�
group_patternr_�commandr|rrrrr�Ts

z_NNTPBase.listcCs�t�d�}|�d|�\}}|�d�s8|�d|�\}}i}x>|D]6}|�|���}|rB|�dd�\}	}
|sp|
S|
||	<qBW|r�||fSdSdS)Nz^(?P<group>[^ 	]+)[ 	]+(.*)$zLIST NEWSGROUPS rzXGTITLE r0rHr&)�re�compiler�rB�search�stripr)rr�Z
return_all�line_patr|r�groups�raw_line�matchr9Zdescrrr�_getdescriptionscs


z_NNTPBase._getdescriptionscCs|�|d�S)NF)r�)rrrrr�descriptionzsz_NNTPBase.descriptioncCs|�|d�S)NT)r�)rr�rrr�descriptions�sz_NNTPBase.descriptionscCs�|�d|�}|�d�s t|��|��}d}}}t|�}|dkr�|d}|dkr�|d}|dkr�|d}|dkr�|d��}|t|�t|�t|�|fS)NzGROUP rrr0rHr�rI)r�rBrr?r6r2r@)rr9r|�words�countr!r �nrrrr�s

z_NNTPBase.groupcCs|�d|�S)NZHELP)r�)rr_rrr�help�sz_NNTPBase.helpcCs8|�d�st|��|��}t|d�}|d}|||fS)NZ22r0rH)rBrr?r@)rr|r��art_numr$rrr�
_statparse�s
z_NNTPBase._statparsecCs|�|�}|�|�S)N)r�r�)rr8r|rrr�_statcmd�s
z_NNTPBase._statcmdcCs"|r|�d�|��S|�d�SdS)NzSTAT {0}ZSTAT)r�rS)r�message_specrrr�stat�s	z_NNTPBase.statcCs
|�d�S)NZNEXT)r�)rrrr�next�sz_NNTPBase.nextcCs
|�d�S)NZLAST)r�)rrrrr �sz_NNTPBase.lastcCs0|�||�\}}|�|�\}}}|t|||�fS)N)r�r�r#)rr8r_r|rr�r$rrr�_artcmd�sz_NNTPBase._artcmdcCs$|dk	rd�|�}nd}|�||�S)NzHEAD {0}ZHEAD)rSr�)rr�r_r�rrr�head�sz_NNTPBase.headcCs$|dk	rd�|�}nd}|�||�S)NzBODY {0}ZBODY)rSr�)rr�r_r�rrr�body�sz_NNTPBase.bodycCs$|dk	rd�|�}nd}|�||�S)NzARTICLE {0}ZARTICLE)rSr�)rr�r_r�rrr�article�sz_NNTPBase.articlecCs
|�d�S)NZSLAVE)r�)rrrr�slavesz_NNTPBase.slavecsDt�d��|�d�||�|�\}}�fdd��|�fdd�|D�fS)Nz^([0-9]+) ?(.*)
?zXHDR {0} {1}cs��|�}|r|�dd�S|S)Nr0rH)r�r)r8�m)�patrr�
remove_numbers
z%_NNTPBase.xhdr.<locals>.remove_numbercsg|]}�|��qSrr)r�r8)r�rrr�sz"_NNTPBase.xhdr.<locals>.<listcomp>)r�r�r�rS)rZhdrr�r_r|rr)r�r�r�xhdr
s	
z_NNTPBase.xhdrcCs.|�d�||�|�\}}|��}|t||�fS)Nz
XOVER {0}-{1})r�rSr�rG)r�start�endr_r|rr7rrr�xovers	
z_NNTPBase.xoverc	Csxd|jkrdnd}t|ttf�r>|\}}|d�||p6d�7}n|dk	rR|d|}|�||�\}}|��}|t||�fS)NZOVERZXOVERz {0}-{1}r&rw)rcr(�tupler�rSr�r�rG)	rr�r_r�r�r�r|rr7rrr�over(sz_NNTPBase.overc	Csjt�dtd�t�d�}|�d||�\}}g}x0|D](}|�|���}|r6|�|�	dd��q6W||fS)NzFThe XGTITLE extension is not actively used, use descriptions() insteadrHz^([^ 	]+)[ 	]+(.*)$zXGTITLE r0)
�warnings�warn�DeprecationWarningr�r�r�r�r�r)r)	rrr_r�r|Z	raw_linesrr�r�rrr�xgtitleCs

z_NNTPBase.xgtitlecCslt�dtd�|�d�|��}|�d�s0t|��y|��\}}Wntk
r^t|�d�Yn
X||fSdS)Nz(The XPATH extension is not actively usedrHz	XPATH {0}Z223)	r�r�r�r�rSrBrr?�
ValueError)r�idr|Zresp_num�pathrrr�xpathUs
z_NNTPBase.xpathcCsb|�d�}|�d�st|��|��}t|�dkr8t|��|d}t|�dkrTt|��|t|d�fS)NZDATEZ111rHr0�)r�rBrr?r6r
rR)rr|�elemrrrrris

z_NNTPBase.datecCs�|�|�}|�d�st|��t|ttf�r2|��}xB|D]:}|�t�sT|�	d�t}|�d�rfd|}|j
�|�q8W|j
�d�|j
��|�
�S)N�3s
r�s.
)r�rBrr(r�	bytearray�
splitlines�endswithr��rstripr_r�r�ra)rr��fr|r8rrr�_postzs





z_NNTPBase._postcCs|�d|�S)NZPOST)r�)r�datarrr�post�sz_NNTPBase.postcCs|�d�|�|�S)Nz	IHAVE {0})r�rS)rr$r�rrr�ihave�sz_NNTPBase.ihavecCs|j��|`dS)N)r_r�)rrrrrr�s
z_NNTPBase._closecCsz|�d�}Wd|��X|S)NZQUIT)r�rr)rr|rrrro�s
z_NNTPBase.quitcCs�|jrtd��|s|std��y<|rX|sXddl}|��}|�|j�}|rX|d}|d}Wntk
rnYnX|sxdS|�d|�}|�d�r�|s�t|��n |�d|�}|�d�s�t	|��d|_
|��|jr�d	|j
kr�|�
�d|_
|��dS)
NzAlready logged in.z7At least one of `user` and `usenetrc` must be specifiedrrHzauthinfo user Z381zauthinfo pass Z281r])rhr��netrcZauthenticatorsr^rpr�rBrrrcrdrerf)r�user�password�usenetrcr�ZcredentialsZauthr|rrr�login�s<


z_NNTPBase.loginc
Cs`y|�d�|_WnJtk
r$Yn8tk
rZ}z|j�d�rHd|_n�Wdd}~XYnXdS)Nzmode readerZ480T)r�rbrrr
rBre)r�errrrf�sz_NNTPBase._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.�STARTTLSZ382�rwbTzTLS failed to start.)rgr�rhr�rBr_r�rZrXr^�makefilercrdr)rrYr|rrr�starttls�s



z_NNTPBase.starttls)T)N)N)N)N)N)N)N)N)N)NNT)N)9rrrr�r�rrrkrsrvrdr�debugr�r�r�rar�r�r�r�r�r�ryr�r�r�r�r�r�rr�r�r�r�r�r r�r�r�r�r�r�r�r�r�r�rr�r�r�rrror�rf�	_have_sslr�rrrrr[(sj
.	

.







		
)
r[c@s*eZdZeddddefdd�Zdd�ZdS)rNFc	Cs�||_||_t�||f|�|_d}y8|j�d�}t�|||||�|sJ|rX|�|||�Wn$|rn|�	�|j�	��YnXdS)Nr�)
r^�port�socket�create_connectionrXr�r[rr�r�)	rr^r�r�r�rir�rjr_rrrr�s

z
NNTP.__init__cCs zt�|�Wd|j��XdS)N)r[rrrXr�)rrrrrr!szNNTP._close)rrr�	NNTP_PORTrrrrrrrrr�s"c@s,eZdZedddddefdd�Zdd�ZdS)�NNTP_SSLNFc	
Cs�t�||f|�|_d}	yJt|j||�|_|j�d�}	tj||	|||d�|sP|r^|�|||�Wn$|	rt|	��|j���YnXdS)Nr�)rirj)	r�r�rXrZr�r[rr�r�)
rr^r�r�r�Zssl_contextrir�rjr_rrrr+s


zNNTP_SSL.__init__cCs zt�|�Wd|j��XdS)N)r[rrrXr�)rrrrrrAszNNTP_SSL._close)rrr�
NNTP_SSL_PORTrrrrrrrrr�)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�)r^r�r�ZGroupZhaszarticles, range�tocCs$t|�|kr |d|d�d}|S)NrIz...)r6)�sZlimrrr�cutlsr�r0�<z{:7} {:20} {:42} ({})��*)N)N)F)Ir�r��collectionsrNr�rW�ImportErrorr�Zemail.headerrr'r�__all__r�rrrrrr	r
r�r�r�r5r3r��
namedtuplerr#r=rGrRrVrZr[rr�r)r�argparse�ArgumentParser�parser�add_argumentr@�
parse_argsrr�Zserverr�rdr}r�rr|r�r!r r9rtr�r�Znb_articlesr�Z	overviewsZartnumr�r?ZauthorrrrSrorrrr�<module>Bs�
	


X-