Your IP : 52.14.75.147


Current Path : /opt/alt/python36/lib64/python3.6/__pycache__/
Upload File :
Current File : //opt/alt/python36/lib64/python3.6/__pycache__/nntplib.cpython-36.opt-2.pyc

3

��2aF��@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+Zejd,d-d.d/d0g�Zejd1d2d3d4g�Zd5d
�Z	d6d7�Zdkd8d9�Zdld:d;�Z dmd<d=�Z!e�r�d>d?�Z"Gd@dA�dA�Z#GdBd�de#�Z$e�r�GdCdD�dDe#�Z%ej&dD�e'dEk�r|ddl(Z(e(j)dFdG�Z*e*j+dHdIdJdKdL�e*j+dMdNdOdPdL�e*j+dQdRdne,dTeefdU�e*j+dVdWdXe,dYdU�e*j+dZd[d\dd]d^�e*j-�Z.e.j/Z/e.j�s�e/dok�rpeZ/e$e.j0e/d_�Z1ne/dpk�r�eZ/e%e.j0e/d_�Z1e1j2�Z3d`e3k�r�e1j4�e1j5e.j5�\Z6Z7Z8Z9Z:e;dae:dbe7dce8dde9�dedf�Z<e=e,e9�e.j>dS�Z8e1j?e8e9�\Z6Z@xbe@D]Z\ZAZBe	eBd$�jCdgdS�dZDe	eBd#�ZEe,eBd)�ZFe;dhjGeAe<eDdi�e<eEdj�eF���qWe1jH�dS)q�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/python36/lib64/python3.6/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|j|j|p.d��q|j|�qWdj|�S)N�ascii�)�_email_decode_header�
isinstancer�append�decode�join)Z
header_str�parts�v�encrrrr�s
cCs�g}xh|D]`}|ddkr<|dd�jd�\}}}d|}n|jd�\}}}|j�}tj||�}|j|�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}|jd�^}}t|�}x�t|�D]�\}	}
|	t|�krPq:||	}|jd�}|	|kr�|r�|d}
|
r�|
dt|
��j�|
kr�td��|
r�|
t|
�d�nd}
|
|||	<q:W|j||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|d
d��}|dkr�|d7}n|dkr�|d7}tj||||||�S)N����Fi��dili����i�������rM���rN)r@�datetime)�date_str�time_strZhoursZminutesZseconds�yearZmonthZdayrrr�_parse_datetime�s
rScCsPt|tj�sd}n
dj|�}|j}|r<|d}dj||�}ndj||�}||fS)NZ000000z({0.hour:02d}{0.minute:02d}{0.second:02d}rLz{0:02d}{1.month:02d}{1.day:02d}z{0:04d}{1.month:02d}{1.day:02d})r(rO�formatrR)Zdt�legacyrQ�yrPrrr�_unparse_datetime�s

rWcCs|dkrtj�}|j||d�S)N)Zserver_hostname)�sslZ_create_stdlib_contextZwrap_socket)�sock�contextZhostnamerrr�_encrypt_onsr[c@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|_|j�|_d|_|j�d|_|rZd|jkrZ|j�|jsZd|_|j�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__csR�fdd�}|�rNz*y�j�Wnttfk
r8YnXWd|�rL�j�XdS)Ncs
t�d�S)Nr`)�hasattrr)rrr�<lambda>ksz$_NNTPBase.__exit__.<locals>.<lambda>)�quit�OSError�EOFError�_close)rrZis_connectedr)rr�__exit__js
z_NNTPBase.__exit__cCs|jrtdt|j��|jS)Nz	*welcome*)ra�print�reprrc)rrrr�
getwelcomeusz_NNTPBase.getwelcomec
Cs�|jdkr�d|_d|_y|j�\}}Wnttfk
rDi|_Yn<X||_d|krhttt|d��|_d|kr�dj	|d�|_|jS)Nr0�VERSIONZIMPLEMENTATION� )
rd�nntp_versionZnntp_implementation�capabilitiesrr�max�mapr@r+)r�resp�capsrrrre~s
z_NNTPBase.getcapabilitiescCs
||_dS)N)ra)r�levelrrr�set_debuglevel�sz_NNTPBase.set_debuglevelcCs:|t}|jdkr tdt|��|jj|�|jj�dS)Nr0z*put*)�_CRLFrartrur`�write�flush)rr8rrr�_putline�s

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



z_NNTPBase._getlongrespcCs|j|�|j�S)N)r�rb)rr8rrr�	_shortcmd�s
z_NNTPBase._shortcmdcCs|j|�|j|�S)N)r�r�)rr8r`rrr�_longcmds
z_NNTPBase._longcmdcs.�j|��j|�\}}|�fdd�|D�fS)Ncsg|]}|j�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|jd�\}}Wn tk
rNtdd�}Yn
Xt|�}||_|S)NzLIST OVERVIEW.FMT)Z_cachedoverviewfmt�AttributeErrorr�rr5r=)rr}rr7rrr�_getoverviewfmtsz_NNTPBase._getoverviewfmtcCsdd�|D�S)NcSsg|]}t|j���qSr)rr?)r�r8rrrr�$sz(_NNTPBase._grouplist.<locals>.<listcomp>r)rrrrr�
_grouplist"sz_NNTPBase._grouplistcCs<i}|jd�\}}x |D]}|j�^}}|||<qW||fS)NZCAPABILITIES)r�r?)rr~r}rr8r9rCrrrrz&s
z_NNTPBase.capabilities)r`cCsbt|tjtjf�s$tdj|jj���t||jdk�\}}dj||�}|j	||�\}}||j
|�fS)NzAthe date parameter must be a date or datetime object, not '{:40}'rIzNEWGROUPS {0} {1})r(rOr�	TypeErrorrT�	__class__rrWryr�r�)rrr`rPrQ�cmdr}rrrr�	newgroups4sz_NNTPBase.newgroupscCsRt|tjtjf�s$tdj|jj���t||jdk�\}}dj|||�}|j	||�S)NzAthe date parameter must be a date or datetime object, not '{:40}'rIzNEWNEWS {0} {1} {2})
r(rOrr�rTr�rrWryr�)rrrr`rPrQr�rrr�newnewsDsz_NNTPBase.newnewscCs4|dk	rd|}nd}|j||�\}}||j|�fS)NzLIST ACTIVE ZLIST)r�r�)r�
group_patternr`�commandr}rrrrr�Ts

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


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

z_NNTPBase.groupcCs|jd|�S)NZHELP)r�)rr`rrr�help�sz_NNTPBase.helpcCs8|jd�st|��|j�}t|d�}|d}|||fS)NZ22r0rI)rBrr?r@)rr}r��art_numr$rrr�
_statparse�s
z_NNTPBase._statparsecCs|j|�}|j|�S)N)r�r�)rr8r}rrr�_statcmd�s
z_NNTPBase._statcmdcCs"|r|jdj|��S|jd�SdS)NzSTAT {0}ZSTAT)r�rT)r�message_specrrr�stat�s	z_NNTPBase.statcCs
|jd�S)NZNEXT)r�)rrrr�next�sz_NNTPBase.nextcCs
|jd�S)NZLAST)r�)rrrrr �sz_NNTPBase.lastcCs0|j||�\}}|j|�\}}}|t|||�fS)N)r�r�r#)rr8r`r}rr�r$rrr�_artcmd�sz_NNTPBase._artcmdcCs$|dk	rdj|�}nd}|j||�S)NzHEAD {0}ZHEAD)rTr�)rr�r`r�rrr�head�sz_NNTPBase.headcCs$|dk	rdj|�}nd}|j||�S)NzBODY {0}ZBODY)rTr�)rr�r`r�rrr�body�sz_NNTPBase.bodycCs$|dk	rdj|�}nd}|j||�S)NzARTICLE {0}ZARTICLE)rTr�)rr�r`r�rrr�article�sz_NNTPBase.articlecCs
|jd�S)NZSLAVE)r�)rrrr�slavesz_NNTPBase.slavecsDtjd��|jdj||�|�\}}�fdd��|�fdd�|D�fS)Nz^([0-9]+) ?(.*)
?zXHDR {0} {1}cs�j|�}|r|jdd�S|S)Nr0rI)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�rT)rZhdrr�r`r}rr)r�r�r�xhdr
s	
z_NNTPBase.xhdrcCs.|jdj||�|�\}}|j�}|t||�fS)Nz
XOVER {0}-{1})r�rTr�rG)r�start�endr`r}rr7rrr�xovers	
z_NNTPBase.xoverc	Csxd|jkrdnd}t|ttf�r>|\}}|dj||p6d�7}n|dk	rR|d|}|j||�\}}|j�}|t||�fS)NZOVERZXOVERz {0}-{1}r&rx)rdr(�tupler�rTr�r�rG)	rr�r`r�r�r�r}rr7rrr�over(sz_NNTPBase.overc	Csjtjdtd�tjd�}|jd||�\}}g}x0|D](}|j|j��}|r6|j|j	dd��q6W||fS)NzFThe XGTITLE extension is not actively used, use descriptions() insteadrIz^([^ 	]+)[ 	]+(.*)$zXGTITLE r0)
�warnings�warn�DeprecationWarningr�r�r�r�r�r)r)	rrr`r�r}Z	raw_linesrr�r�rrr�xgtitleCs

z_NNTPBase.xgtitlecCsjtjdtd�|jdj|��}|jd�s0t|��y|j�\}}Wntk
r\t|��Yn
X||fSdS)Nz(The XPATH extension is not actively usedrIz	XPATH {0}Z223)	r�r�r�r�rTrBrr?�
ValueError)r�idr}Zresp_num�pathrrr�xpathUs
z_NNTPBase.xpathcCsb|jd�}|jd�st|��|j�}t|�dkr8t|��|d}t|�dkrTt|��|t|d�fS)NZDATEZ111rIr0�)r�rBrr?r6r
rS)rr}�elemrrrrris

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





z_NNTPBase._postcCs|jd|�S)NZPOST)r�)r�datarrr�post�sz_NNTPBase.postcCs|jdj|�|�S)Nz	IHAVE {0})r�rT)rr$r�rrr�ihave�sz_NNTPBase.ihavecCs|jj�|`dS)N)r`r�)rrrrrr�s
z_NNTPBase._closec
Csz|jd�}Wd|j�X|S)NZQUIT)r�rr)rr}rrrro�s
z_NNTPBase.quitcCs�|jrtd��|r"|r"td��y>|r^|r^ddl}|j�}|j|j�}|r^|d}|d}Wntk
rtYnX|s~dS|jd|�}|jd�r�|s�t|��n |jd|�}|jd�s�t	|��d|_
|j�|jr�d	|j
kr�|j
�d|_
|j�dS)
NzAlready logged in.z7At least one of `user` and `usenetrc` must be specifiedrrIzauthinfo user Z381zauthinfo pass Z281r^)rir��netrcZauthenticatorsr_rpr�rBrrrdrerfrg)r�user�password�usenetrcr�ZcredentialsZauthr}rrr�login�s<



z_NNTPBase.logincCs`y|jd�|_WnJtk
r$Yn8tk
rZ}z|jjd�rHd|_n�WYdd}~XnXdS)Nzmode readerZ480T)r�rcrrr
rBrf)r�errrrg�sz_NNTPBase._setreadermodecCs||jrtd��|jrtd��|jd�}|jd�rp|jj�t|j||j	�|_|jj
d�|_d|_d|_|j�nt
d��dS)NzTLS is already enabled.z+TLS cannot be started after authentication.�STARTTLSZ382�rwbTzTLS failed to start.)rhr�rir�rBr`r�r[rYr_�makefilerdrer)rrZr}rrr�starttls�s



z_NNTPBase.starttls)T)N)N)N)N)N)N)N)N)N)NNT)N)9rrrr�r�rrrlrsrvrer��debugr�r�r�rbr�r�r�r�r�r�rzr�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�rg�	_have_sslr�rrrrr\(sj
.	

.







		
)
r\c@s*eZdZeddddefdd�Zdd�ZdS)rNFc	Cs�||_||_tj||f|�|_d}y8|jjd�}tj|||||�|sJ|rX|j|||�Wn$|rn|j	�|jj	��YnXdS)Nr�)
r_�port�socket�create_connectionrYr�r\rr�r�)	rr_r�r�r�rjr�rkr`rrrr�s

z
NNTP.__init__c
Cs ztj|�Wd|jj�XdS)N)r\rrrYr�)rrrrrr!szNNTP._close)rrr�	NNTP_PORTrrrrrrrrr�s"c@s,eZdZedddddefdd�Zdd�ZdS)�NNTP_SSLNFc	

Cs�tj||f|�|_d}	yJt|j||�|_|jjd�}	tj||	|||d�|sP|r^|j|||�Wn$|	rt|	j�|jj��YnXdS)Nr�)rjrk)	r�r�rYr[r�r\rr�r�)
rr_r�r�r�Zssl_contextrjr�rkr`rrrr+s


zNNTP_SSL.__init__c
Cs ztj|�Wd|jj�XdS)N)r\rrrYr�)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--serverznews.gmane.orgz+NNTP server hostname (default: %(default)s)z-pz--portr0z#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, rangeZtocCs$t|�|kr |d|d�d}|S)NrJz...)r6)�sZlimrrr�cutlsr��<z{:7} {:20} {:42} ({})��*)N)N)Fr�r�r�)Ir�r��collectionsrOr�rX�ImportErrorr�Zemail.headerrr'r�__all__r�rrrrrr	r
r�r�r�r5r3r��
namedtuplerr#r=rGrSrWr[r\rr�r)r�argparse�ArgumentParser�parser�add_argumentr@�
parse_argsrr�Zserverr�rer~r�rr}r�r!r r9rtr�r�Znb_articlesr�Z	overviewsZartnumr�r?ZauthorrrrTrorrrr�<module>Bs�
	


X-






 

?>