a �DOg?�� @s:ddlZddlZddlZddlZddlZz ddlZWneyJdZYn0dZddlm Z ddlm Z gd�Z dZ Gdd �d e�ZGd d �d e�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*de+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;ee7e8�\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�/usr/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> �215Z230Z231Z222Z220Z282Z100Z225Z101�211Z221Z224)�subject�from�datez message-idZ references�:bytes�:linesrr)�bytes�lines� � GroupInfo)�group�last�first�flag� ArticleInfo)�number� 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    rBcCs�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� r4z: z?OVER/XOVER response doesn't include names of additional headers) r;r:�split�int� enumerate� startswithr7r r.)r r<Zdata_process_funcZ n_defaultsZoverviewr=�fieldsZarticle_number�tokens�i�token� field_nameZ is_metadata�hrrr�_parse_overview�s&   rNcCs�|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)rE�datetime)�date_str�time_strZhoursZminutesZseconds�yearZmonthZdayrrr�_parse_datetime�s   rYcCsPt|tj�sd}n d�|�}|j}|r<|d}d�||�}n d�||�}||fS)NZ000000z({0.hour:02d}{0.minute:02d}{0.second:02d}rTz{0:02d}{1.month:02d}{1.day:02d}z{0:04d}{1.month:02d}{1.day:02d})r-rU�formatrX)Zdt�legacyrW�yrVrrr�_unparse_datetime�s   r]cCs|durt��}|j||d�S)N)Zserver_hostname)�sslZ_create_stdlib_contextZ wrap_socket)�sock�context�hostnamerrr� _encrypt_onsrbc@seZdZdZdZeddddefdd�Zdd�Zd d �Z d d �Z d d�Z dd�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)rrerf�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)rrorrrrj[s  zNNTP._base_initcCs|S�Nr�rrrr� __enter__}szNNTP.__enter__c s^�fdd�}|�rZz6z ���Wnttfy6Yn0W|�rZ���n|�rX���0dS)Ncs t�d�S)Nrh)�hasattrrr}rr���zNNTP.__exit__..)�quit�OSError�EOFError�_close)rrZ is_connectedrr}r�__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�auditrerf�socket�create_connection)rrqrrrrg�s zNNTP._create_socketcCs|jrtdt|j��|jS)Nz *welcome*)rs�print�reprrur}rrr� getwelcome�szNNTP.getwelcomec Cs�|jdur~d|_d|_z|��\}}WnttfyBi|_Yn<0||_d|vrfttt|d��|_d|vr~d� |d�|_|jS)Nr5�VERSIONZIMPLEMENTATION� ) rv� nntp_versionZnntp_implementation� capabilitiesrr�max�maprEr0)r�resp�capsrrrrw�s  zNNTP.getcapabilitiescCs ||_dSr|)rs)r�levelrrr�set_debuglevel�szNNTP.set_debuglevelcCsHt�d||�|t}|jdkr.tdt|��|j�|�|j��dS)Nznntplib.putliner5z*put*) r�r��_CRLFrsr�r�rh�write�flush�rr=rrr�_putline�s  z NNTP._putlinecCs2|jrtdt|��|�|j|j�}|�|�dS)Nz*cmd*)rsr�r��encode�encoding�errorsr�r�rrr�_putcmd�sz NNTP._putcmdTcCs�|j�td�}t|�tkr$td��|jdkr+s�z'NNTP._longcmdstring..r�)rr=rhr��listrr}r�_longcmdstring$s   �zNNTP._longcmdstringcCs`z|jWStyYn0z|�d�\}}WntyLtdd�}Yn 0t|�}||_|S)NzLIST OVERVIEW.FMT)Z_cachedoverviewfmt�AttributeErrorr�rr:rB)rr�r r<rrr�_getoverviewfmt.s  zNNTP._getoverviewfmtcCsdd�|D�S)NcSsg|]}t|����qSr)r"rDr�rrrr�Ar�z#NNTP._grouplist..r)rr rrr� _grouplist?szNNTP._grouplistcCs8i}|�d�\}}|D]}|��^}}|||<q||fS)NZ CAPABILITIES)r�rD)rr�r�r r=r>rIrrrr�Cs   zNNTP.capabilities)rhcCsbt|tjtjf�s$td�|jj���t||jdk�\}}d�||�}|� ||�\}}||� |�fS)N�Athe date parameter must be a date or datetime object, not '{:40}'rOzNEWGROUPS {0} {1}) r-rUr� TypeErrorrZ� __class__rr]r�r�r�)rrrhrVrW�cmdr�r rrr� newgroupsQs�� zNNTP.newgroupscCsRt|tjtjf�s$td�|jj���t||jdk�\}}d�|||�}|� ||�S)Nr�rOzNEWNEWS {0} {1} {2}) r-rUrr�rZr�rr]r�r�)rr#rrhrVrWr�rrr�newnewsas��z NNTP.newnewscCs4|durd|}nd}|�||�\}}||�|�fS)Nz LIST ACTIVE �LIST)r�r�)r� group_patternrh�commandr�r rrrr�qs  z NNTP.listc Cs�t�d�}|�d|�\}}|�d�s8|�d|�\}}i}|D]:}|�|���}|r@|�dd�\} } |sr| S| || <q@|r�||fSdSdS)Nz^(?P[^ ]+)[ ]+(.*)$zLIST NEWSGROUPS rzXGTITLE r5rOr+)�re�compiler�rG�search�stripr#) rr�Z return_allZline_patr�r �groupsZraw_line�matchr>Zdescrrr�_getdescriptions�s   zNNTP._getdescriptionscCs |�|d�S)NF�r�)rr#rrr� description�s zNNTP.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 rrr5rOr�rP)r�rGrrDr;r7rE)rr>r��words�countr%r$�nrrrr#�s    z NNTP.groupcCs |�d|�S)NZHELP)r�)rrhrrr�help�sz NNTP.helpcCs8|�d�st|��|��}t|d�}|d}|||fS)NZ22r5rO)rGrrDrE)rr�r��art_numr)rrr� _statparse�s   zNNTP._statparsecCs|�|�}|�|�Sr|)r�r�)rr=r�rrr�_statcmd�s z NNTP._statcmdcCs"|r|�d�|��S|�d�SdS)NzSTAT {0}ZSTAT)r�rZ)r� message_specrrr�stat�s z NNTP.statcCs |�d�S)NZNEXT�r�r}rrr�next�sz NNTP.nextcCs |�d�S)NZLASTr�r}rrrr$�sz NNTP.lastcCs0|�||�\}}|�|�\}}}|t|||�fSr|)r�r�r')rr=rhr�r r�r)rrr�_artcmd�sz NNTP._artcmdcCs$|durd�|�}nd}|�||�S)NzHEAD {0}ZHEAD�rZr��rr�rhr�rrr�head�s z NNTP.headcCs$|durd�|�}nd}|�||�S)NzBODY {0}ZBODYr�r�rrr�bodys z NNTP.bodycCs$|durd�|�}nd}|�||�S)Nz ARTICLE {0}ZARTICLEr�r�rrr�articles z NNTP.articlecCs |�d�S)NZSLAVE)r�r}rrr�slave!sz NNTP.slavecsDt�d��|�d�||�|�\}}�fdd��|�fdd�|D�fS)Nz^([0-9]+) ?(.*) ?z XHDR {0} {1}cs��|�}|r|�dd�S|S)Nr5rO)r�r#)r=�m)�patrr� remove_number2s z NNTP.xhdr..remove_numbercsg|] }�|��qSrrr�)r�rrr�5r�zNNTP.xhdr..)r�r�r�rZ)rZhdrr�rhr�r r)r�r�r�xhdr's  z NNTP.xhdrcCs.|�d�||�|�\}}|��}|t||�fS)Nz XOVER {0}-{1})r�rZr�rN)r�start�endrhr�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�)rvr-�tupler�rZr�r�rN) rr�rhr�r�r�r�r r<rrr�overEs z NNTP.overcCsb|�d�}|�d�st|��|��}t|�dkr8t|��|d}t|�dkrTt|��|t|d�fS)NZDATEZ111rOr5�)r�rGrrDr;r rY)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�rGrr-r� bytearray� splitlines�endswithr��rstriprhr�r�rt)rr��fr�r=rrr�_postqs      z NNTP._postcCs |�d|�S)NZPOST)r�)r�datarrr�post�sz NNTP.postcCs|�d�|�|�S)Nz IHAVE {0})r�rZ)rr)r�rrr�ihave�sz NNTP.ihavecCs4z"|jr|j��|`W|j��n |j��0dSr|)rhrlr_r}rrrr��s  z NNTP._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 specifiedrrOzauthinfo user Z381zauthinfo pass Z281rr)r{r��netrcZauthenticatorsrer�r�rGrrrvrwrxry)rrmrnrpr�Z credentialsZauthr�rrrrk�s>�      z NNTP.loginc Cs`z|�d�|_WnJty"Yn:tyZ}z"|j�d�rDd|_n�WYd}~n d}~00dS)Nz mode readerZ480T)r�rurrr rGrx)r�errrry�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.�STARTTLSZ382rdTzTLS failed to start.)rzr�r{r�rGrhrlrbr_rerirvrwr)rr`r�rrr�starttls�s    z NNTP.starttls)T)N)N)N)N)N)N)N)N)N)NNT)N):rrrr�r�� NNTP_PORTrr rjr~r�rgr�rwr��debugr�r�r�rtr�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�r�rkry� _have_sslr�rrrrr(sp � #"     .         ) rcs8eZdZedddddef�fdd� Z�fdd�Z�ZS)�NNTP_SSLNFc s"||_t��|||||||�dSr|)� ssl_context�superr ) rrerfrmrnr�rorprq�r�rrr �s�zNNTP_SSL.__init__cs@t��|�}zt||j|j�}Wn|���Yn0|SdSr|)r�rgrbr�rerl)rrqr_rrrrgs zNNTP_SSL._create_socket)rrr� NNTP_SSL_PORTrr rg� __classcell__rrrrr��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)�actionrr�)rerfr�ZGroupZhaszarticles, range�tocCs$t|�|kr |d|d�d}|S)NrPz...)r;)�sZlimrrr�cut3s r r5r�r�r r�Z nb_articlesr�Z overviewsZartnumr�rDZauthorrr rZr�rrrr�Bs�       ���    S    � �  � � �      �