Your IP : 3.140.188.174


Current Path : /opt/alt/python35/lib64/python3.5/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/__pycache__/nntplib.cpython-35.opt-2.pyc



���]F��@sddlZddlZddlZddlZddlZyddlZWnek
rfdZYnXdZddlm	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+d)iZd,Zejd-d.d/d0d1g�Zejd2d3d4d+g�Zd5d
�Z	d6d7�Zdd8d9�Zdd:d;�Z dd<d=�Z!er.d>d?�Z"Gd@dA�dA�Z#GdBd�de#�Z$er�GdCdD�dDe#�Z%ej&dD�e'dEkr�ddl(Z(e(j)dFdG�Z*e*j+dHdIdJdKdLdM�e*j+dNdOdJdPdLdQ�e*j+dRdSdJdTdUe,dLdVeef�e*j+dWdXdJdYdUe,dLdZ�e*j+d[d\d]d^dJddLd_�e*j-�Z.e.j/Z/e.jr�e/dTkr�eZ/e$d`e.j0dae/�Z1n+e/dTkr�eZ/e%d`e.j0dae/�Z1e1j2�Z3dbe3kr�e1j4�e1j5e.j5�\Z6Z7Z8Z9Z:e;dce:dde7dee8dfe9�dgdh�Z<e=e,e9�e.j>dT�Z8e1j?e8e9�\Z6Z@x�e@D]z\ZAZBe	eBd$�jCdidT�dZDe	eBd#�ZEe,eBd)�ZFe;djjGeAe<eDdk�e<eEdl�eF��quWe1jH�dS)m�NFT)�
decode_header)�_GLOBAL_DEFAULT_TIMEOUT�NNTP�	NNTPError�NNTPReplyError�NNTPTemporaryError�NNTPPermanentError�NNTPProtocolError�
NNTPDataErrorric@seZdZdd�ZdS)rcGsCtj||�y|d|_Wntk
r>d|_YnXdS)NrzNo response given)�	Exception�__init__�response�
IndexError)�self�args�r�,/opt/alt/python35/lib64/python3.5/nntplib.pyrbs

zNNTPError.__init__N)�__name__�
__module__�__qualname__rrrrrr`sc@seZdZdS)rN)rrrrrrrrisc@seZdZdS)rN)rrrrrrrrmsc@seZdZdS)rN)rrrrrrrrqsc@seZdZdS)r	N)rrrrrrrr	usc@seZdZdS)r
N)rrrrrrrr
ys�wi3Z100Z101�211�215Z220Z221Z222Z224Z225Z230Z231Z282�subject�from�datez
message-idZ
referencesz:bytesz:lines�bytes�liness
�	GroupInfo�group�last�first�flag�ArticleInfoZnumber�
message_idcCskg}xUt|�D]G\}}t|t�rM|j|j|pCd��q|j|�qWdj|�S)N�ascii�)�_email_decode_header�
isinstancer�append�decode�join)Z
header_str�parts�v�encrrrr�scCs�g}x�|D]�}|ddkrR|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|�krtqS||	}|jd�}|	|kr|r|d}
|
r�|
dt|
��j�|
kr�td��|
r�|
t|
�d�nd}
|
|||	<qSW|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�token�
field_nameZis_metadata�hrrr�_parse_overview�s&


("rHcCs�|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�������rN���rO)r@�datetime)�date_str�time_strZhoursZminutesZseconds�yearZmonthZdayrrr�_parse_datetime�s

rTcCstt|tj�sd}ndj|�}|j}|rX|d}dj||�}ndj||�}||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(rP�formatrS)Zdt�legacyrR�yrQrrr�_unparse_datetime�s
		
rXcCs+|dkrtj�}|j|d|�S)NZserver_hostname)�sslZ_create_stdlib_contextZwrap_socket)�sock�context�hostnamerrr�_encrypt_onsr]c@s�eZdZdZdZdedd�Zdd�Zdd	�Zd
d�Z	dd
�Z
dd�ZeZdd�Z
dd�Zddd�Zdd�Zddd�Zdd�Zddd�Zddd �Zd!d"�Zd#d$�Zd%d&�Zd'dd(d)�Zd'dd*d+�Zdd'dd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd'dd6d7�Zd8d9�Z d:d;�Z!dd<d=�Z"d>d?�Z#d@dA�Z$ddBdC�Z%dd'ddDdE�Z&dd'ddFdG�Z'dd'ddHdI�Z(dJdK�Z)d'ddLdM�Z*d'ddNdO�Z+d'ddPdQ�Z,d'ddRdS�Z-dTdU�Z.dVdW�Z/dXdY�Z0dZd[�Z1d\d]�Z2d^d_�Z3d`da�Z4ddddbdc�Z5ddde�Z6e7r�ddfdg�Z8dS)h�	_NNTPBasezutf-8�surrogateescapeNcCs�||_||_d|_|j�|_d|_|j�d|_|r�d|jkr�|j�|js�d|_|j�d|_	d|_
dS)NrF�READER)�host�file�	debugging�_getresp�welcome�_caps�getcapabilities�readermode_afterauth�_setreadermode�tls_on�
authenticated)rrbra�
readermode�timeoutrrrr8s				
		
		
	z_NNTPBase.__init__cCs|S)Nr)rrrr�	__enter__gsz_NNTPBase.__enter__csc�fdd�}|�r_z-y�j�Wnttfk
rFYnXWd|�r^�j�XdS)Ncs
t�d�S)Nrb)�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*)rc�print�reprre)rrrr�
getwelcomeus	z_NNTPBase.getwelcomec
Cs�|jdkr�d|_d|_y|j�\}}Wn!ttfk
rZi|_YnTX||_d|kr�ttt|d��|_d|kr�dj	|d�|_|jS)Nr0�VERSIONZIMPLEMENTATION� )
rf�nntp_versionZnntp_implementation�capabilitiesrr�max�mapr@r+)r�resp�capsrrrrg~s			z_NNTPBase.getcapabilitiescCs
||_dS)N)rc)r�levelrrr�set_debuglevel�sz_NNTPBase.set_debuglevelcCsM|t}|jdkr,tdt|��|jj|�|jj�dS)Nr0z*put*)�_CRLFrcrvrwrb�write�flush)rr8rrr�_putline�s

z_NNTPBase._putlinecCsE|jrtdt|��|j|j|j�}|j|�dS)Nz*cmd*)rcrvrw�encode�encoding�errorsr�)rr8rrr�_putcmd�s	z_NNTPBase._putcmdTcCs�|jjtd�}t|�tkr4td��|jdkrVtdt|��|sbt�|r�|dd�t	kr�|dd�}n&|dd�t	kr�|dd�}|S)	Nr0z
line too longz*get*rJrOrO���r�)
rb�readline�_MAXLINEr6r
rcrvrwrsr�)rZ
strip_crlfr8rrr�_getline�sz_NNTPBase._getlinecCs�|j�}|jr(tdt|��|j|j|j�}|dd�}|dkrht|��|dkr�t|��|dkr�t	|��|S)Nz*resp*r0�4�5Z123)
r�rcrvrwr*r�r�rrr	)rr�crrrrd�s	z_NNTPBase._getrespc
CsDd}z t|ttf�r1t|d�}}|j�}|dd�tkr_t|��g}|dk	r�dtdf}x�|jd�}||kr�P|j	d�r�|dd�}|j
|�q�WnRd}xI|j�}||kr�P|j	d�r|dd�}|j|�q�WWd|r9|j�X||fS)N�wb��.s.
Fs..r0)
r(�strr�openrd�	_LONGRESPrr�r�rBr�r)�close)rrbZ
openedFilerrZterminatorsr8�
terminatorrrr�_getlongresp�s8	z_NNTPBase._getlongrespcCs|j|�|j�S)N)r�rd)rr8rrr�	_shortcmd�s
z_NNTPBase._shortcmdcCs|j|�|j|�S)N)r�r�)rr8rbrrr�_longcmds
z_NNTPBase._longcmdcs?�j|��j|�\}}|�fdd�|D�fS)Ncs(g|]}|j�j�j��qSr)r*r�r�)�.0r8)rrr�
<listcomp>s	z,_NNTPBase._longcmdstring.<locals>.<listcomp>)r�r�)rr8rbr�listr)rr�_longcmdstrings
z_NNTPBase._longcmdstringcCswy|jSWntk
rYnXy|jd�\}}Wn"tk
r]tdd�}Yn
Xt|�}||_|S)NzLIST OVERVIEW.FMT)Z_cachedoverviewfmt�AttributeErrorr�rr5r=)rrrr7rrr�_getoverviewfmts

	z_NNTPBase._getoverviewfmtcCsdd�|D�S)NcSs"g|]}t|j���qSr)rr?)r�r8rrrr�$s	z(_NNTPBase._grouplist.<locals>.<listcomp>r)rrrrr�
_grouplist"sz_NNTPBase._grouplistcCsRi}|jd�\}}x*|D]"}|j�^}}|||<q"W||fS)NZCAPABILITIES)r�r?)rr�rrr8r9rCrrrr|&s
z_NNTPBase.capabilitiesrbcCs�t|tjtjf�s6tdj|jj���t||jdk�\}}dj||�}|j	||�\}}||j
|�fS)NzAthe date parameter must be a date or datetime object, not '{:40}'rJzNEWGROUPS {0} {1})r(rPr�	TypeErrorrU�	__class__rrXr{r�r�)rrrbrQrR�cmdrrrrr�	newgroups4sz_NNTPBase.newgroupscCsyt|tjtjf�s6tdj|jj���t||jdk�\}}dj|||�}|j	||�S)NzAthe date parameter must be a date or datetime object, not '{:40}'rJzNEWNEWS {0} {1} {2})
r(rPrr�rUr�rrXr{r�)rrrrbrQrRr�rrr�newnewsDsz_NNTPBase.newnewscCsJ|dk	rd|}nd}|j||�\}}||j|�fS)NzLIST ACTIVE �LIST)r�r�)r�
group_patternrb�commandrrrrrr�Ts

z_NNTPBase.listcCs�tjd�}|jd|�\}}|jd�sP|jd|�\}}i}xU|D]M}|j|j��}|r]|jdd�\}	}
|s�|
S|
||	<q]W|r�||fSdSdS)Nz^(?P<group>[^ 	]+)[ 	]+(.*)$zLIST NEWSGROUPS rzXGTITLE r0rJr&)�re�compiler�rB�search�stripr)rr�Z
return_all�line_patrr�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 rrr0rJr�rK)r�rBrr?r6r2r@)rr9r�words�countr!r �nrrrr�s



z_NNTPBase.groupcCs|jd|�S)NZHELP)r�)rrbrrr�help�sz_NNTPBase.helpcCsN|jd�st|��|j�}t|d�}|d}|||fS)NZ22r0rJ)rBrr?r@)rrr��art_numr$rrr�
_statparse�s
z_NNTPBase._statparsecCs|j|�}|j|�S)N)r�r�)rr8rrrr�_statcmd�sz_NNTPBase._statcmdcCs-|r|jdj|��S|jd�SdS)NzSTAT {0}ZSTAT)r�rU)r�message_specrrr�stat�s	z_NNTPBase.statcCs
|jd�S)NZNEXT)r�)rrrr�next�sz_NNTPBase.nextcCs
|jd�S)NZLAST)r�)rrrrr �sz_NNTPBase.lastcCsF|j||�\}}|j|�\}}}|t|||�fS)N)r�r�r#)rr8rbrrr�r$rrr�_artcmd�sz_NNTPBase._artcmdcCs4|dk	rdj|�}nd}|j||�S)NzHEAD {0}ZHEAD)rUr�)rr�rbr�rrr�head�sz_NNTPBase.headcCs4|dk	rdj|�}nd}|j||�S)NzBODY {0}ZBODY)rUr�)rr�rbr�rrr�body�sz_NNTPBase.bodycCs4|dk	rdj|�}nd}|j||�S)NzARTICLE {0}ZARTICLE)rUr�)rr�rbr�rrr�article�sz_NNTPBase.articlecCs
|jd�S)NZSLAVE)r�)rrrr�slavesz_NNTPBase.slavecsbtjd��|jdj||�|�\}}�fdd��|�fdd�|D�fS)Nz^([0-9]+) ?(.*)
?zXHDR {0} {1}cs)�j|�}|r%|jdd�S|S)Nr0rJ)r�r)r8�m)�patrr�
remove_numbersz%_NNTPBase.xhdr.<locals>.remove_numbercsg|]}�|��qSrr)r�r8)r�rrr�s	z"_NNTPBase.xhdr.<locals>.<listcomp>)r�r�r�rU)rZhdrr�rbrrr)r�r�r�xhdr
s	$z_NNTPBase.xhdrcCsC|jdj||�|�\}}|j�}|t||�fS)Nz
XOVER {0}-{1})r�rUr�rH)r�start�endrbrrr7rrr�xovers	z_NNTPBase.xoverc	Cs�d|jkrdnd}t|ttf�r[|\}}|dj||pQd�7}n|dk	ru|d|}|j||�\}}|j�}|t||�fS)NZOVERZXOVERz {0}-{1}r&rz)rfr(�tupler�rUr�r�rH)	rr�rbr�r�r�rrr7rrr�over(sz_NNTPBase.overc	Cs�tjdtd�tjd�}|jd||�\}}g}xB|D]:}|j|j��}|rK|j|j	dd��qKW||fS)NzFThe XGTITLE extension is not actively used, use descriptions() insteadrJz^([^ 	]+)[ 	]+(.*)$zXGTITLE r0)
�warnings�warn�DeprecationWarningr�r�r�r�r�r)r)	rrrbr�rZ	raw_linesrr�r�rrr�xgtitleCs	

z_NNTPBase.xgtitlecCs�tjdtd�|jdj|��}|jd�sFt|��y|j�\}}Wntk
r|t|��YnX||fSdS)Nz(The XPATH extension is not actively usedrJz	XPATH {0}Z223)	r�r�r�r�rUrBrr?�
ValueError)r�idrZresp_num�pathrrr�xpathUs	

z_NNTPBase.xpathcCs�|jd�}|jd�s*t|��|j�}t|�dkrTt|��|d}t|�dkr|t|��|t|d�fS)NZDATEZ111rJr0�)r�rBrr?r6r
rT)rr�elemrrrrris
z_NNTPBase.datecCs�|j|�}|jd�s*t|��t|ttf�rK|j�}xY|D]Q}|jt�sz|j	d�t}|jd�r�d|}|j
j|�qRW|j
jd�|j
j�|j
�S)N�3s
r�s.
)r�rBrr(r�	bytearray�
splitlines�endswithr��rstriprbr�r�rd)rr��frr8rrr�_postzs


z_NNTPBase._postcCs|jd|�S)NZPOST)r�)r�datarrr�post�sz_NNTPBase.postcCs|jdj|�|�S)Nz	IHAVE {0})r�rU)rr$r�rrr�ihave�sz_NNTPBase.ihavecCs|jj�|`dS)N)rbr�)rrrrrt�s
z_NNTPBase._closec
Cs%z|jd�}Wd|j�X|S)NZQUIT)r�rt)rrrrrrq�sz_NNTPBase.quitcCsT|jrtd��|r/|r/td��yU|r�|r�ddl}|j�}|j|j�}|r�|d}|d}Wntk
r�YnX|s�dS|jd|�}|jd�r|s�t|��n.|jd|�}|jd�st	|��d|_
|j�|jrPd	|j
krP|j
�d|_
|j�dS)
NzAlready logged in.z7At least one of `user` and `usenetrc` must be specifiedrrJzauthinfo user Z381zauthinfo pass Z281r`)rkr��netrcZauthenticatorsrarrr�rBrrrfrgrhri)r�user�password�usenetrcr�ZcredentialsZauthrrrr�login�s<		


	

	z_NNTPBase.logincCsty|jd�|_WnWtk
r*YnFtk
ro}z&|jjd�rZd|_n�WYdd}~XnXdS)Nzmode readerZ480T)r�rerrr
rBrh)r�errrri�s
z_NNTPBase._setreadermodecCs�|jrtd��|jr*td��|jd�}|jd�r�|jj�t|j||j	�|_|jj
d�|_d|_d|_|j�nt
d��dS)NzTLS is already enabled.z+TLS cannot be started after authentication.�STARTTLSZ382�rwbTzTLS failed to start.)rjr�rkr�rBrbr�r]rZra�makefilerfrgr)rr[rrrr�starttls�s		
		
z_NNTPBase.starttls)9rrrr�r�rrrnrurxrgr��debugr�r�r�rdr�r�r�r�r�r�r|r�r�r�r�r�r�rr�r�r�r�r�r r�r�r�r�r�r�r�r�r�r�rr�r�r�rtrqr�ri�	_have_sslr�rrrrr^(sj
.	.



		)
r^c@s:eZdZeddddedd�Zdd�ZdS)rNFc	Cs�||_||_tj||f|�|_d}yN|jjd�}tj|||||�|sm|r�|j|||�Wn(|r�|j	�|jj	��YnXdS)Nr�)
ra�port�socket�create_connectionrZr�r^rr�r�)	rrar�r�r�rlr�rmrbrrrr�s		


z
NNTP.__init__c
Cs&ztj|�Wd|jj�XdS)N)r^rtrZr�)rrrrrt!szNNTP._close)rrr�	NNTP_PORTrrrtrrrrr�s	"c	@s=eZdZedddddedd�Zdd�ZdS)�NNTP_SSLNFc	
Cs�tj||f|�|_d}	ylt|j||�|_|jjd�}	tj||	|d|d|�|sy|r�|j|||�Wn(|	r�|	j�|jj��YnXdS)Nr�rlrm)	r�r�rZr]r�r^rr�r�)
rrar�r�r�Zssl_contextrlr�rmrbrrrr+s


zNNTP_SSL.__init__c
Cs&ztj|�Wd|jj�XdS)N)r^rtrZr�)rrrrrtAszNNTP_SSL._close)rrr�
NNTP_SSL_PORTrrrtrrrrr�)s
	r��__main__r�zJ        nntplib built-in demo - display the latest articles in a newsgroupz-gz--group�defaultzgmane.comp.python.generalr�z3group to fetch messages from (default: %(default)s)z-sz--serverznews.gmane.orgz+NNTP server hostname (default: %(default)s)z-pz--portr0�typez#NNTP port number (default: %s / %s)z-nz
--nb-articles�
z2number of articles to fetch (default: %(default)s)z-Sz--ssl�action�
store_truezuse NNTP over SSLrar�r�ZGroupZhaszarticles, rangeZtocCs.t|�|kr*|d|d�d}|S)NrKz...)r6)�sZlimrrr�cutlsr��<z{:7} {:20} {:42} ({})��*)Ir�r��collectionsrPr�rY�ImportErrorr�Zemail.headerrr'r�__all__r�rrrrrr	r
r�r�r�r5r3r��
namedtuplerr#r=rHrTrXr]r^rr�r)r�argparse�ArgumentParser�parser�add_argumentr@�
parse_argsrr�Zserverr�rgr�r�rrr�r!r r9rvr�r�Znb_articlesr�Z	overviewsZartnumr�r?ZauthorrrrUrqrrrr�<module>Bs�
							���-
			



! 	)

?>