B
    u9a"ö  ã               @   s¢  d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
Z
d dlmZ d dlmZmZ d dlZd dlmZ yd dlZW n ek
r¤   dZY nX dZej ej e¡d¡Zedk	rÐejZnG dd„ deƒZG d	d
„ d
ƒZe ¡  efZedk	reej f7 ZG dd„ deej!ƒZ"e #ed¡G dd„ de"ƒƒZ$G dd„ de j%ƒZ&dd„ Z'G dd„ dƒZ(G dd„ de(ƒZ)G dd„ dƒZ*G dd„ de*ƒZ+G dd„ de+ƒZ,G dd„ de+ƒZ-G d d!„ d!ƒZ.G d"d#„ d#e.e(ej!ƒZ/G d$d%„ d%e.e(ej!ƒZ0G d&d'„ d'e(ej!ƒZ1G d(d)„ d)e)ej!ƒZ2G d*d+„ d+ej!ƒZ3G d,d-„ d-ej!ƒZ4G d.d/„ d/ej!ƒZ5G d0d1„ d1ƒZ6e #ed¡G d2d3„ d3e5ƒƒZ7G d4d5„ d5ej!ƒZ8e9d6krže :¡  dS )7é    N)Úsupport)ÚNNTPÚ	GroupInfo)Úpatché   zkeycert3.pemc               @   s   e Zd ZdZdS )ÚSSLErrorzThis will never be raised.N)Ú__name__Ú
__module__Ú__qualname__Úreason© r   r   ú"/usr/lib/python3.7/test_nntplib.pyr      s   r   c               @   sÒ   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Ze dd¡dd„ ƒZdd„ Zd/d d!„Ze dd"¡d#d$„ ƒZd%d&„ Zd'd(„ Zd)d*„ Zed+d,„ ƒZd-d.„ ZdS )0ÚNetworkedNNTPTestsMixinc             C   s   | j  ¡ }|  tt|ƒ¡ d S )N)ÚserverZ
getwelcomeÚassertEqualÚstrÚtype)ÚselfÚwelcomer   r   r   Útest_welcome(   s    
z$NetworkedNNTPTestsMixin.test_welcomec             C   sB   | j  ¡ \}}|  | d¡|¡ x|D ]}|  tt|ƒ¡ q&W d S )Nz100 )r   ÚhelpÚ
assertTrueÚ
startswithr   r   r   )r   ÚrespÚlinesÚliner   r   r   Ú	test_help,   s    
z!NetworkedNNTPTestsMixin.test_helpc             C   sH   | j  ¡ \}}t|ƒdkrD|  tt|d ƒ¡ |  tt|d jƒ¡ d S )Nr   )r   ÚlistÚlenr   r   r   r   Úgroup)r   r   Úgroupsr   r   r   Ú	test_list2   s    z!NetworkedNNTPTestsMixin.test_listc             C   sL   | j  | j¡\}}t|ƒdkrH|  tt|d ƒ¡ |  tt|d jƒ¡ d S )Nr   )	r   r   Ú	GROUP_PATr   r   r   r   r   r   )r   r   r    r   r   r   Útest_list_active8   s    z(NetworkedNNTPTestsMixin.test_list_activec          	   C   sB   |   tj¡}| j d¡ W d Q R X |jj}|  | d¡|¡ d S )NZXYZZYz500 )	ÚassertRaisesÚnntplibÚNNTPPermanentErrorr   Z	_shortcmdÚ	exceptionÚresponser   r   )r   Úcmr   r   r   r   Útest_unknown_command>   s    z,NetworkedNNTPTestsMixin.test_unknown_commandc             C   sX   t j ¡ t jdd }| j |¡\}}t|ƒdkrT|  |d t¡ |  |d j	t
¡ d S )Né   )Zdaysr   )ÚdatetimeÚdateZtodayZ	timedeltar   Z	newgroupsr   ÚassertIsInstancer   r   r   )r   Údtr   r    r   r   r   Útest_newgroupsD   s
    z&NetworkedNNTPTestsMixin.test_newgroupsc                s`   ‡ fdd„}ˆ j  ˆ j¡}||ƒ ˆ  d|¡ ˆ j  ˆ j¡}||ƒ ˆ j  d¡}ˆ  |d¡ d S )Nc                s   ˆ   | t¡ ˆ  ˆ j| ¡ d S )N)r.   r   ÚassertNotInÚ
GROUP_NAME)Údesc)r   r   r   Ú_check_descN   s    z=NetworkedNNTPTestsMixin.test_description.<locals>._check_descÚPythonzzk.brrtt.bazÚ )r   Údescriptionr2   ÚassertInr"   r   )r   r4   r3   r   )r   r   Útest_descriptionM   s    z(NetworkedNNTPTestsMixin.test_descriptionc             C   s^   | j  | j¡\}}|  | d¡p(| d¡|¡ |  |t¡ || j }|  || j  	| j¡¡ d S )Nz215 z282 )
r   Údescriptionsr"   r   r   r.   Údictr2   r   r7   )r   r   Zdescsr3   r   r   r   Útest_descriptions]   s    
z)NetworkedNNTPTestsMixin.test_descriptionsc             C   s€   | j  | j¡}|  dt|ƒ¡ |\}}}}}|  || j¡ |  |t¡ |  |t¡ |  |t¡ |  ||¡ |  | 	d¡|¡ d S )Né   z211 )
r   r   r2   r   r   r.   ÚintÚassertLessEqualr   r   )r   Úresultr   ÚcountÚfirstÚlastr   r   r   r   Ú
test_groupf   s    z"NetworkedNNTPTestsMixin.test_groupc             C   s<   | j  ¡ \}}|  |tj¡ |  |jd¡ |  |jd¡ d S )NiË  iî  )r   r-   r.   r,   ÚassertGreaterEqualZyearr?   )r   r   r-   r   r   r   Ú	test_dateq   s    z!NetworkedNNTPTestsMixin.test_datec          
   C   sT   |   |t¡ |  | ¡ dddddddh¡ x$| ¡ D ]}|   |ttd ƒf¡ q4W d S )NÚsubjectÚfromr-   z
message-idÚ
referencesz:bytesz:lines)r.   r;   rE   ÚkeysÚvaluesr   r   )r   Úart_dictÚvr   r   r   Ú_check_art_dictx   s    
z'NetworkedNNTPTestsMixin._check_art_dictc       	      C   sz   | j  | j¡\}}}}}| j  |d |¡\}}t|ƒdkrD|  d¡ |d \}}|  ||d ¡ |  ||¡ |  |¡ d S )Nr=   r   zno articles retrieved)	r   r   r2   Úxoverr   ÚskipTestrE   r?   rN   )	r   r   rA   rB   rC   Únamer   Úart_numrL   r   r   r   Ú
test_xoverƒ   s    
z"NetworkedNNTPTestsMixin.test_xoverTzHtemporarily skipped until a permanent solution is found for issue #28971c       
      C   s   | j  | j¡\}}}}}|d }| j  |d f¡\}}|d \}}	|  |	¡ | j  ||f¡\}}|d \}}	|  ||¡ |  ||¡ |  |	¡ d S )Né
   r   éÿÿÿÿ)r   r   r2   ÚoverrN   rE   r?   )
r   r   rA   rB   rC   rQ   Ústartr   rR   rL   r   r   r   Ú	test_overŽ   s    
z!NetworkedNNTPTestsMixin.test_overc             C   sP   | j  | j¡\}}}}}| j  d|¡\}}x |D ]}|  tt|d ƒ¡ q0W d S )NrG   é   )r   r   r2   Zxhdrr   r   r   )r   r   rA   rB   rC   rQ   r   r   r   r   r   Ú	test_xhdr¡   s    
z!NetworkedNNTPTestsMixin.test_xhdrNc             C   sV   |   |tj¡ |d k	r$|  |j|¡ x|jD ]}|   |t¡ q,W |  |jd d¡ d S )NrU   )ó   .s   .
s   .
)r.   r%   ZArticleInfor   Znumberr   Úbytesr1   )r   r   ÚarticlerR   r   r   r   r   Úcheck_article_resp§   s    z*NetworkedNNTPTestsMixin.check_article_respzFIXME: see bpo-32128c                sR  | j  | j¡\}}}}}xl|||d fD ]P}y| j  |¡\}}W n4 tjk
rt } z|j d¡sb‚ w(W d d }~X Y nX P q(W |  d¡ |  	| d¡|¡ |  
|||¡ | j  |¡\}}	|  	| d¡|¡ |  
||	|¡ | j  |¡\}}
|  	| d¡|¡ |  
||
|¡ dd„ ‰ ‡ fd	d
„|jD ƒ}‡ fdd
„|
jD ƒ}|  ||dg |	j ¡ d S )NrY   z423 z(could not find a suitable article numberz221 z222 z220 c             S   s
   |   d¡S )Ns   X-Antivirus)r   )r   r   r   r   Ú<lambda>È   ó    z@NetworkedNNTPTestsMixin.test_article_head_body.<locals>.<lambda>c                s   g | ]}ˆ |ƒs|‘qS r   r   )Ú.0r   )Ú	blacklistr   r   ú
<listcomp>É   s    zBNetworkedNNTPTestsMixin.test_article_head_body.<locals>.<listcomp>c                s   g | ]}ˆ |ƒs|‘qS r   r   )ra   r   )rb   r   r   rc   Ë   s    r`   )r   r   r2   Úheadr%   ÚNNTPTemporaryErrorr(   r   rP   r   r^   Úbodyr]   r   r   )r   r   rA   rB   rC   rQ   rR   rd   Úerf   r]   Zfiltered_head_linesZfiltered_linesr   )rb   r   Útest_article_head_body°   s,    
z.NetworkedNNTPTestsMixin.test_article_head_bodyc                sD   ‡ fdd„}ˆ   ˆ jjd¡ |ˆ j ¡ ƒ ˆ j ¡ \}}||ƒ d S )Nc                s(   | d }ˆ   |ttf¡ ˆ  d|¡ d S )NÚLISTzOVERVIEW.FMT)r.   r   Útupler8   )ÚcapsZ	caps_list)r   r   r   Ú_check_capsÓ   s    z>NetworkedNNTPTestsMixin.test_capabilities.<locals>._check_capsé   )rE   r   Únntp_versionÚgetcapabilitiesZcapabilities)r   rl   r   rk   r   )r   r   Útest_capabilitiesÏ   s
    z)NetworkedNNTPTestsMixin.test_capabilitiesc             C   s&   d}d}| j tj| jj||dd d S )NZnotarealuserZnotarealpasswordF)ÚuserÚpasswordÚusenetrc)r$   r%   Ú	NNTPErrorr   Úlogin)r   ZbaduserZbadpwr   r   r   Útest_zloginÝ   s    z#NetworkedNNTPTestsMixin.test_zloginc             C   s$   t | ƒ}z| j ¡  W d d |_X d S )N)r   r   Úquit)r   Úclsr   r   r   Útest_zzquitê   s    z#NetworkedNNTPTestsMixin.test_zzquitc             C   sN   dd„ }x@t | ƒD ]4}| d¡s"qt| |ƒ}t|ƒs6qt| |||ƒƒ qW d S )Nc                s   t  ˆ ¡‡ fdd„ƒ}|S )Nc          	      s$   t  | j¡ ˆ | ƒ W d Q R X d S )N)r   Útransient_internetÚ	NNTP_HOST)r   )Úmethr   r   Úwrapped÷   s    zHNetworkedNNTPTestsMixin.wrap_methods.<locals>.wrap_meth.<locals>.wrapped)Ú	functoolsÚwraps)r|   r}   r   )r|   r   Ú	wrap_methö   s    z7NetworkedNNTPTestsMixin.wrap_methods.<locals>.wrap_methZtest_)Údirr   ÚgetattrÚcallableÚsetattr)rx   r€   rQ   r|   r   r   r   Úwrap_methodsò   s    

z$NetworkedNNTPTestsMixin.wrap_methodsc          
      sÖ   ‡ fdd„}yz| j | jtdd ‰ |  |ƒ ¡ |  ˆ  ¡ ¡ W d Q R X |  |ƒ ¡ | j | jtdd‰ ˆ  ¡  W d Q R X |  |ƒ ¡ W nJ tk
rÐ } z,t 	d|j
¡r¾t d|› d| j›¡‚‚ W d d }~X Y nX d S )Nc            	      s8   t ˆ dƒsdS yˆ  ¡  W n ttfk
r2   dS X dS )NÚfileFT)Úhasattrr   ÚOSErrorÚEOFErrorr   )r   r   r   Úis_connected  s    
zANetworkedNNTPTestsMixin.test_with_statement.<locals>.is_connectedF)Útimeoutrs   z(?i)KEY.TOO.SMALLzGot z connecting to )Ú
NNTP_CLASSr{   ÚTIMEOUTr   r   ÚassertFalserw   r   ÚreÚsearchr   ÚunittestÚSkipTest)r   rŠ   Ússl_errr   )r   r   Útest_with_statement  s    	z+NetworkedNNTPTestsMixin.test_with_statement)N)r   r	   r
   r   r   r!   r#   r*   r0   r9   r<   rD   rF   rN   rS   r‘   ZskipIfrX   rZ   r^   rh   rp   rv   ry   Úclassmethodr…   r”   r   r   r   r   r   &   s*   		
	r   c               @   s4   e Zd ZdZdZdZeZedd„ ƒZ	edd„ ƒZ
dS )	ÚNetworkedNNTPTestsznews.trigofacile.comzfr.comp.lang.pythonzfr.comp.lang.*c             C   s¶   t  d¡ t  | j¡– y| j| jtdd| _W nv tk
r~ } z0t 	d|j
¡rlt | › d|› d| j›¡‚‚ W d d }~X Y n* tk
r¦   t | › d| j›¡‚Y nX W d Q R X d S )NZnetworkF)r‹   rs   z(?i)KEY.TOO.SMALLz got z connecting to z  got EOF error on connecting to )r   Zrequiresrz   r{   rŒ   r   r   r   r   r   r   r‘   r’   Ú
EOF_ERRORS)rx   r“   r   r   r   Ú
setUpClass1  s    

zNetworkedNNTPTests.setUpClassc             C   s   | j d k	r| j  ¡  d S )N)r   rw   )rx   r   r   r   ÚtearDownClassB  s    
z NetworkedNNTPTests.tearDownClassN)r   r	   r
   r{   r2   r"   r   rŒ   r•   r˜   r™   r   r   r   r   r–   )  s   r–   zrequires SSL supportc               @   s,   e Zd ZdZdZdZeeddƒZdZ	dZ
dS )ÚNetworkedNNTP_SSLTestsznntp.aioe.orgzcomp.lang.pythonzcomp.lang.*ÚNNTP_SSLN)r   r	   r
   r{   r2   r"   r‚   r%   rŒ   r!   Útest_starttlsr   r   r   r   rš   G  s   rš   c               @   s<   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ ZdS )Ú_NNTPServerIOc             C   s>   t j | ¡ t  ¡ | _t  ¡ | _|| _| j | jj| j	¡ d S )N)
ÚioÚ	RawIOBaseÚ__init__ÚBytesIOÚc2sÚs2cÚhandlerrW   ÚreadlineÚ	push_data)r   r¤   r   r   r   r    d  s
    

z_NNTPServerIO.__init__c             C   s   dS )NTr   )r   r   r   r   Úreadablem  s    z_NNTPServerIO.readablec             C   s   dS )NTr   )r   r   r   r   Úwritablep  s    z_NNTPServerIO.writablec             C   s4   | j  ¡ }| j  dd¡ | j  |¡ | j  |¡ d S )Nr   rm   )r£   ÚtellÚseekÚwrite)r   ÚdataÚposr   r   r   r¦   s  s    
z_NNTPServerIO.push_datac             C   s4   | j  ¡ }| j  |¡ | j  |¡ | j ¡  t|ƒS )N)r¢   r©   r«   rª   r¤   Úprocess_pendingr   )r   Úbr­   r   r   r   r«   z  s
    

z_NNTPServerIO.writec             C   s2   | j  ¡  | j t|ƒ¡}t|ƒ}||d |…< |S )N)r¤   r®   r£   Úreadr   )r   Úbufr¯   Únr   r   r   Úreadinto‚  s
    
z_NNTPServerIO.readintoN)	r   r	   r
   r    r§   r¨   r¦   r«   r³   r   r   r   r   r   _  s   	r   c             C   s   t | ƒ}t ||¡}||fS )N)r   rž   ÚBufferedRWPair)r¤   Úsior†   r   r   r   Úmake_mock_file‹  s    r¶   c                   s4   e Zd ZdZ‡ fdd„Z‡ fdd„Zdd„ Z‡  ZS )ÚMockedNNTPTestsMixinNc                s   t ƒ  ¡  |  ¡  d S )N)ÚsuperÚsetUpÚmake_server)r   )Ú	__class__r   r   r¹   —  s    
zMockedNNTPTestsMixin.setUpc                s   t ƒ  ¡  | `d S )N)r¸   ÚtearDownr   )r   )r»   r   r   r¼   ›  s    
zMockedNNTPTestsMixin.tearDownc             O   s6   |   ¡ | _t| jƒ\| _}tj|df|ž|Ž| _| jS )Nztest.server)Úhandler_classr¤   r¶   rµ   r%   Z	_NNTPBaser   )r   ÚargsÚkwargsr†   r   r   r   rº   Ÿ  s    
z MockedNNTPTestsMixin.make_server)r   r	   r
   r½   r¹   r¼   rº   Ú__classcell__r   r   )r»   r   r·   “  s   r·   c                   s   e Zd Z‡ fdd„Z‡  ZS )ÚMockedNNTPWithReaderModeMixinc                s   t ƒ  ¡  | jdd d S )NT)Z
readermode)r¸   r¹   rº   )r   )r»   r   r   r¹   §  s    
z#MockedNNTPWithReaderModeMixin.setUp)r   r	   r
   r¹   rÀ   r   r   )r»   r   rÁ   ¦  s   rÁ   c               @   sú   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd7dd„Zdd„ Zdd „ Zd8d!d"„Zd#d$„ Zd%d&„ Zdd'œd(d)„Zdd'œd*d+„Zd,Zd-Zed. e Zd9d/d0„Zd:d1d2„Zd;d3d4„Zd5d6„ ZdS )<ÚNNTPv1Handlerz200 NNTP mock serverc             C   s0   d| _ d| _|| _|| _d| _d| _|  ¡  d S )NFT)Úin_bodyÚallow_postingÚ	_readlineÚ
_push_dataÚ
_logged_inÚ
_user_sentÚhandle_welcome)r   r¥   r¦   r   r   r   rW   ±  s    zNNTPv1Handler.startc             C   s   t |ddƒS )Nzutf-8Úsurrogateescape)r   )r   r¬   r   r   r   Ú_decode»  s    zNNTPv1Handler._decodec          
   C   s4  | j rfx*|  ¡ }|sd S | j |¡ |dkrP qW z| j\}}||d| jiŽ W d d | _d | _d| _ X xÈ|  |  ¡ ¡}|s~d S | d¡s–td |¡ƒ‚|d d… }| 	¡ ^}}t
| d| ¡  d ƒ}|d krÔ|  ¡  qhy||Ž  W n4 tk
r } ztd |¡ƒ|‚W d d }~X Y qhX | j rh||f| _g | _qhW d S )	Ns   .
rf   Fz
z line doesn't end with \r\n: {!r}éþÿÿÿZhandle_zcommand failed: {!r})rÃ   rÅ   rf   ÚappendZbody_callbackrË   ÚendswithÚ
ValueErrorÚformatÚsplitr‚   ÚupperÚhandle_unknownÚ	Exception)r   r   r|   ÚtokensÚcmdrg   r   r   r   r®   ¾  s@    


"
zNNTPv1Handler.process_pendingc             C   s
   d| _ d S )NT)rÃ   )r   r   r   r   Úexpect_bodyä  s    zNNTPv1Handler.expect_bodyc             C   s   |   |¡ d S )N)rÆ   )r   r¬   r   r   r   r¦   è  s    zNNTPv1Handler.push_datac             C   s4   t  |¡}d | ¡ ¡d }| d¡}|  |¡ d S )Nz
zutf-8)ÚtextwrapÚdedentÚjoinÚ
splitlinesÚencoder¦   )r   Zlitr   r   r   Úpush_litì  s    

zNNTPv1Handler.push_litc             C   s   |   d¡ d S )Nz	500 What?)rÝ   )r   r   r   r   rÓ   ó  s    zNNTPv1Handler.handle_unknownc             C   s   |   | j¡ d S )N)rÝ   r   )r   r   r   r   rÉ   ö  s    zNNTPv1Handler.handle_welcomec             C   s   |   d¡ d S )Nz205 Bye!)rÝ   )r   r   r   r   Úhandle_QUITù  s    zNNTPv1Handler.handle_QUITc             C   s   |   d¡ d S )Nz111 20100914001155)rÝ   )r   r   r   r   Úhandle_DATEü  s    zNNTPv1Handler.handle_DATEc             C   s(   |dkr|   d¡ n|   d |¡¡ d S )Nzfr.comp.lang.pythonz$211 486 761 1265 fr.comp.lang.pythonz411 No such group {})rÝ   rÐ   )r   r   r   r   r   Úhandle_GROUPÿ  s    zNNTPv1Handler.handle_GROUPc             C   s   |   d¡ d S )NzÉ            100 Legal commands
              authinfo user Name|pass Password|generic <prog> <args>
              date
              help
            Report problems to <root@example.org>
            .)rÝ   )r   r   r   r   Úhandle_HELP  s    zNNTPv1Handler.handle_HELPNc             C   sJ   |d kr|   d¡ n2|dkr(|   d¡ n|dkr<|   d¡ n
|   d¡ d S )Nz412 No newsgroup selectedÚ3000234z"223 3000234 <45223423@example.com>z<45223423@example.com>z223 0 <45223423@example.com>z430 No Such Article Found)rÝ   )r   Úmessage_specr   r   r   Úhandle_STAT  s    zNNTPv1Handler.handle_STATc             C   s   |   d¡ d S )Nz*223 3000237 <668929@example.org> retrieved)rÝ   )r   r   r   r   Úhandle_NEXT  s    zNNTPv1Handler.handle_NEXTc             C   s   |   d¡ d S )Nz,223 3000234 <45223423@example.com> retrieved)rÝ   )r   r   r   r   Úhandle_LAST  s    zNNTPv1Handler.handle_LASTc             C   sš   |d kr|   d¡ n‚|dkr<|dkr0|   d¡ q–|   d¡ nZ|dkrP|   d¡ nF|dkrŒ|d	krl|   d
¡ q–|dkr€|   d¡ q–|   d¡ n
|   d¡ d S )NaÑ                  215 Newsgroups in form "group high low flags".
                comp.lang.python 0000052340 0000002828 y
                comp.lang.python.announce 0000001153 0000000993 m
                free.it.comp.lang.python 0000000002 0000000002 y
                fr.comp.lang.python 0000001254 0000000760 y
                free.it.comp.lang.python.learner 0000000000 0000000001 y
                tw.bbs.comp.lang.python 0000000304 0000000304 y
                .ÚACTIVEz*distutils*zñ                    215 Newsgroups in form "group high low flags"
                    gmane.comp.python.distutils.devel 0000014104 0000000001 m
                    gmane.comp.python.distutils.cvs 0000000000 0000000001 m
                    .zW                    215 Newsgroups in form "group high low flags"
                    .zOVERVIEW.FMTa                  215 Order of fields in overview database.
                Subject:
                From:
                Date:
                Message-ID:
                References:
                Bytes:
                Lines:
                Xref:full
                .Ú
NEWSGROUPSzcomp.lang.pythonzš                    215 Descriptions in form "group description".
                    comp.lang.python	The Python computer language.
                    .zcomp.lang.python*zý                    215 Descriptions in form "group description".
                    comp.lang.python.announce	Announcements about the Python language. (Moderated)
                    comp.lang.python	The Python computer language.
                    .zW                    215 Descriptions in form "group description".
                    .z501 Unknown LIST keyword)rÝ   )r   ÚactionZparamr   r   r   Úhandle_LIST  s,    
zNNTPv1Handler.handle_LISTc             C   s‚   |dkr$|dkr$|dkr$|   d¡ nZ|dkrH|dkrH|dkrH|   d¡ n6|dkrt|dkrt|dkrt|   d	d
 d ¡ n
|   d¡ d S )Nzcomp.lang.pythonZ20100913Z082004a                  230 list of newsarticles (NNTP v2) created after Mon Sep 13 08:20:04 2010 follows
                <a4929a40-6328-491a-aaaf-cb79ed7309a2@q2g2000vbk.googlegroups.com>
                <f30c0419-f549-4218-848f-d7d0131da931@y3g2000vbm.googlegroups.com>
                .Z100913a                  230 list of newsarticles (NNTP v1) created after Mon Sep 13 08:20:04 2010 follows
                <a4929a40-6328-491a-aaaf-cb79ed7309a2@q2g2000vbk.googlegroups.com>
                <f30c0419-f549-4218-848f-d7d0131da931@y3g2000vbm.googlegroups.com>
                .)Z20100101Z100101Z090000ztoo long linei¸  z
.zK                230 An empty list of newsarticles follows
                .)rÝ   )r   r   Údate_strÚtime_strr   r   r   Úhandle_NEWNEWST  s    

zNNTPv1Handler.handle_NEWNEWSc             C   s"   |dkr|   d¡ n
|   d¡ d S )Nz57-59uL  224 Overview information for 57-58 follows
57	Re: ANN: New Plone book with strong Python (and Zope) themes throughout	Doug Hellmann <doug.hellmann-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>	Sat, 19 Jun 2010 18:04:08 -0400	<4FD05F05-F98B-44DC-8111-C6009C925F0C@gmail.com>	<hvalf7$ort$1@dough.gmane.org>	7103	16	Xref: news.gmane.org gmane.comp.python.authors:57
58	Looking for a few good bloggers	Doug Hellmann <doug.hellmann-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>	Thu, 22 Jul 2010 09:14:14 -0400	<A29863FA-F388-40C3-AA25-0FD06B09B5BF@gmail.com>		6683	16	
59	Re: Message d'erreur incomprÃ©hensible (par moi)	Eric Brunel <eric.brunel@pragmadev.nospam.com>	Wed, 15 Sep 2010 18:09:15 +0200	<eric.brunel-2B8B56.18091515092010@news.wanadoo.fr>	<4c90ec87$0$32425$ba4acef3@reader.news.orange.fr>	1641	27	Xref: saria.nerim.net fr.comp.lang.python:1265
.
z1                224 No articles
                .)rÝ   )r   rã   r   r   r   Úhandle_XOVERs  s
    zNNTPv1Handler.handle_XOVER)rf   c            C   sB   |d kr.| j r"|  d¡ |  ¡  q>|  d¡ n|  d¡ || _d S )Nz+340 Input article; end with <CR-LF>.<CR-LF>z440 Posting not permittedz240 Article received OK)rÄ   rÝ   r×   Úposted_body)r   rf   r   r   r   Úhandle_POST“  s    


zNNTPv1Handler.handle_POSTc            C   sJ   |d kr6| j r*|dkr*|  d¡ |  ¡  qF|  d¡ n|  d¡ || _d S )Nz+<i.am.an.article.you.will.want@example.com>z%335 Send it; end with <CR-LF>.<CR-LF>z435 Article not wantedz235 Article transferred OK)rÄ   rÝ   r×   rï   )r   Ú
message_idrf   r   r   r   Úhandle_IHAVEŸ  s    


zNNTPv1Handler.handle_IHAVEz×        From: "Demo User" <nobody@example.net>
        Subject: I am just a test article
        Content-Type: text/plain; charset=UTF-8; format=flowed
        Message-ID: <i.am.an.article.you.will.want@example.com>ui           This is just a test article.
        ..Here is a dot-starting line.

        -- Signed by AndrÃ©.z

c             C   sd   |d kr|   d¡ n6|dkr(|   d¡ n"|dkr<|   d¡ n|   d¡ d S |   | j¡ |   d¡ d S )Nz"220 3000237 <45223423@example.com>z<45223423@example.com>z220 0 <45223423@example.com>râ   z"220 3000234 <45223423@example.com>z430 No Such Article FoundÚ.)rÝ   Úsample_article)r   rã   r   r   r   Úhandle_ARTICLEº  s    
zNNTPv1Handler.handle_ARTICLEc             C   sd   |d kr|   d¡ n6|dkr(|   d¡ n"|dkr<|   d¡ n|   d¡ d S |   | j¡ |   d¡ d S )Nz"221 3000237 <45223423@example.com>z<45223423@example.com>z221 0 <45223423@example.com>râ   z"221 3000234 <45223423@example.com>z430 No Such Article Foundró   )rÝ   Úsample_head)r   rã   r   r   r   Úhandle_HEADÇ  s    
zNNTPv1Handler.handle_HEADc             C   sd   |d kr|   d¡ n6|dkr(|   d¡ n"|dkr<|   d¡ n|   d¡ d S |   | j¡ |   d¡ d S )Nz"222 3000237 <45223423@example.com>z<45223423@example.com>z222 0 <45223423@example.com>râ   z"222 3000234 <45223423@example.com>z430 No Such Article Foundró   )rÝ   Úsample_body)r   rã   r   r   r   Úhandle_BODYÔ  s    
zNNTPv1Handler.handle_BODYc             C   sj   | j r|  d¡ nT|dkr>| jr,|  d¡ qf|  d¡ d| _n(|dkrX|  d¡ d| _ ntd |¡ƒ‚d S )	Nz502 Already Logged Inrq   z 482 User Credential Already Sentz381 Password RequiredTÚpassz281 Login SuccessfulzUnknown cred type {})rÇ   rÝ   rÈ   rÔ   rÐ   )r   Z	cred_typer¬   r   r   r   Úhandle_AUTHINFOá  s    

zNNTPv1Handler.handle_AUTHINFO)N)NN)N)N)N)r   r	   r
   r   rW   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   r   r   r   rÂ   ¬  s8   
&	


6 


rÂ   c               @   s&   e Zd Zdd„ Zdd„ Zddd„ZdS )	ÚNNTPv2Handlerc             C   s0   d}| j s|  | d¡¡ n|  | d¡¡ d S )Na              101 Capability list:
            VERSION 2 3
            IMPLEMENTATION INN 2.5.1{}
            HDR
            LIST ACTIVE ACTIVE.TIMES DISTRIB.PATS HEADERS NEWSGROUPS OVERVIEW.FMT
            OVER
            POST
            READER
            .z
            AUTHINFO USERr6   )rÇ   rÝ   rÐ   )r   Úfmtr   r   r   Úhandle_CAPABILITIESô  s    
z!NNTPv2Handler.handle_CAPABILITIESc             C   s   t dƒ‚d S )Nz3MODE READER sent despite READER has been advertised)rÔ   )r   Ú_r   r   r   Úhandle_MODE  s    zNNTPv2Handler.handle_MODENc             C   s
   |   |¡S )N)rî   )r   rã   r   r   r   Úhandle_OVER  s    zNNTPv2Handler.handle_OVER)N)r   r	   r
   rþ   r   r  r   r   r   r   rü   ñ  s   rü   c                   s   e Zd Z‡ fdd„Z‡  ZS )ÚCapsAfterLoginNNTPv2Handlerc                s    | j s|  d¡ n
tƒ  ¡  d S )Nz480 You must log in.)rÇ   rÝ   r¸   rþ   )r   )r»   r   r   rþ     s    z/CapsAfterLoginNNTPv2Handler.handle_CAPABILITIES)r   r	   r
   rþ   rÀ   r   r   )r»   r   r    s   r  c               @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )ÚModeSwitchingNNTPv2Handlerc             C   s
   d| _ d S )NF)Ú	_switched)r   r   r   r   r      s    z#ModeSwitchingNNTPv2Handler.__init__c             C   s0   d}| j r|  | d¡¡ n|  | d¡¡ d S )Na              101 Capability list:
            VERSION 2 3
            IMPLEMENTATION INN 2.5.1
            HDR
            LIST ACTIVE ACTIVE.TIMES DISTRIB.PATS HEADERS NEWSGROUPS OVERVIEW.FMT
            OVER
            POST
            {}READER
            .r6   zMODE-)r  rÝ   rÐ   )r   rý   r   r   r   rþ     s    
z.ModeSwitchingNNTPv2Handler.handle_CAPABILITIESc             C   s   d| _ |  d¡ d S )NTz200 Posting allowed)r  rÝ   )r   Zwhatr   r   r   r   ,  s    z&ModeSwitchingNNTPv2Handler.handle_MODEN)r   r	   r
   r    rþ   r   r   r   r   r   r    s   r  c                   s  e Zd Z‡ fdd„Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zd-d.„ Zd/d0„ Zd1d2„ Zd3d4„ Zd5Zd6d7„ Zd8d9„ Zd:d;„ Z d<d=„ Z!d>d?„ Z"d@dA„ Z#‡  Z$S )BÚNNTPv1v2TestsMixinc                s   t ƒ  ¡  d S )N)r¸   r¹   )r   )r»   r   r   r¹   4  s    zNNTPv1v2TestsMixin.setUpc             C   s   |   | jj| jj¡ d S )N)r   r   r   r¤   )r   r   r   r   r   7  s    zNNTPv1v2TestsMixin.test_welcomec             C   s<   | j dkr|  d| jj¡ | j dd¡ |  d| jj¡ d S )Nrm   ÚAUTHINFOÚtestuserÚtestpw)rn   r8   r   Ú_capsru   r1   )r   r   r   r   Útest_authinfo:  s    
z NNTPv1v2TestsMixin.test_authinfoc             C   s:   | j  ¡ \}}|  |d¡ |  |t dddddd¡¡ d S )Nz111 20100914001155iÚ  é	   é   r   é   é7   )r   r-   r   r,   )r   r   r-   r   r   r   rF   B  s    zNNTPv1v2TestsMixin.test_datec             C   s6   |   | jj¡ | j ¡ }|  |d¡ |  | jj¡ d S )Nz205 Bye!)rŽ   rµ   Úclosedr   rw   r   r   )r   r   r   r   r   Ú	test_quitG  s    
zNNTPv1v2TestsMixin.test_quitc             C   s2   | j  ¡ \}}|  |d¡ |  |ddddg¡ d S )Nz100 Legal commandsz8  authinfo user Name|pass Password|generic <prog> <args>z  datez  helpz%Report problems to <root@example.org>)r   r   r   )r   r   r   r   r   r   r   M  s    zNNTPv1v2TestsMixin.test_helpc             C   s~   | j  ¡ \}}|  t|ƒd¡ |d }|  |tddddƒ¡ | j  d¡\}}|  t|ƒd¡ |d	 }|  |td
dddƒ¡ d S )Né   rY   zcomp.lang.python.announceZ
0000001153Z
0000000993Úmz*distutils*rm   r   z!gmane.comp.python.distutils.develZ
0000014104Z
0000000001)r   r   r   r   r   )r   r   r    Úgr   r   r   r!   W  s    
zNNTPv1v2TestsMixin.test_listc          	   C   sÖ   | j  d¡\}}}|  |d¡ |  |d¡ |  |d¡ | j  d¡\}}}|  |d¡ |  |d¡ |  |d¡ |  tj¡}| j  d¡ W d Q R X |  |jjd¡ |  tj¡}| j  ¡  W d Q R X |  |jjd¡ d S )	NiªÇ- z"223 3000234 <45223423@example.com>z<45223423@example.com>z223 0 <45223423@example.com>r   z<non.existent.id>z430 No Such Article Foundz412 No newsgroup selected)r   Ústatr   r$   r%   re   r'   r(   )r   r   rR   rñ   r)   r   r   r   Ú	test_state  s    zNNTPv1v2TestsMixin.test_statc             C   s8   | j  ¡ \}}}|  |d¡ |  |d¡ |  |d¡ d S )Nz*223 3000237 <668929@example.org> retrievedi­Ç- z<668929@example.org>)r   Únextr   )r   r   rR   rñ   r   r   r   Ú	test_nextu  s    zNNTPv1v2TestsMixin.test_nextc             C   s8   | j  ¡ \}}}|  |d¡ |  |d¡ |  |d¡ d S )Nz,223 3000234 <45223423@example.com> retrievediªÇ- z<45223423@example.com>)r   rC   r   )r   r   rR   rñ   r   r   r   Ú	test_last{  s    zNNTPv1v2TestsMixin.test_lastc             C   s4   | j  d¡}|  |d¡ | j  d¡}|  |d¡ d S )Nzcomp.lang.pythonzThe Python computer language.zcomp.lang.pythonxr6   )r   r7   r   )r   r3   r   r   r   r9     s    z#NNTPv1v2TestsMixin.test_descriptionc             C   sn   | j  d¡\}}|  |d¡ |  |ddi¡ | j  d¡\}}|  |dddœ¡ | j  d¡\}}|  |i ¡ d S )Nzcomp.lang.pythonz-215 Descriptions in form "group description".zThe Python computer language.zcomp.lang.python*z4Announcements about the Python language. (Moderated))zcomp.lang.pythonzcomp.lang.python.announcezcomp.lang.pythonx)r   r:   r   )r   r   r    r   r   r   r<   ‡  s    

z$NNTPv1v2TestsMixin.test_descriptionsc          	   C   sœ   | j  d¡\}}}}}|  | d¡|¡ |  |d¡ |  |d¡ |  |d¡ |  |d¡ |  tj¡}| j  d¡ W d Q R X |j}|  |j	 d¡|j	¡ d S )Nzfr.comp.lang.pythonz211 iù  iñ  iæ  zcomp.lang.python.develz411 No such group)
r   r   r   r   r   r$   r%   re   r'   r(   )r   r   rA   rB   rC   r   r)   Úexcr   r   r   rD   •  s    zNNTPv1v2TestsMixin.test_groupc             C   s   t   dddddd¡}| j d|¡\}}d | j¡}|  ||¡ |  |d	d
g¡ t   dddddd¡}| j d|¡\}}|  |d¡ |  |g ¡ d S )NiÚ  r  é   é   é   é   zcomp.lang.pythonzS230 list of newsarticles (NNTP v{0}) created after Mon Sep 13 08:20:04 2010 followszB<a4929a40-6328-491a-aaaf-cb79ed7309a2@q2g2000vbk.googlegroups.com>zB<f30c0419-f549-4218-848f-d7d0131da931@y3g2000vbm.googlegroups.com>zfr.comp.lang.pythonz)230 An empty list of newsarticles follows)r,   r   ÚnewnewsrÐ   rn   r   )r   r/   r   ZidsZexpectedr   r   r   Útest_newnews¢  s    zNNTPv1v2TestsMixin.test_newnewsc             C   sZ   |   t|ƒd¡ |   |d  d¡d¡ |   |d d¡ |   |d d¡ |   |d	 d
¡ d S )Nr  rU   zutf-8u   -- Signed by AndrÃ©.rÌ   r`   éýÿÿÿs   .Here is a dot-starting line.éüÿÿÿs   This is just a test article.)r   r   Údecode)r   r   r   r   r   Ú_check_article_bodyµ  s
    z&NNTPv1v2TestsMixin._check_article_bodyc             C   s4   |   t|ƒd¡ |   |d d¡ |   |d d¡ d S )Nr  r   s&   From: "Demo User" <nobody@example.net>é   s7   Message-ID: <i.am.an.article.you.will.want@example.com>)r   r   )r   r   r   r   r   Ú_check_article_head¼  s    z&NNTPv1v2TestsMixin._check_article_headc             C   sH   |   t|ƒd¡ |  |d d… ¡ |  |dd … ¡ |   |d d¡ d S )Nr  r  r!  r`   )r   r   r%  r#  )r   r   r   r   r   Ú_check_article_dataÁ  s    z&NNTPv1v2TestsMixin._check_article_datac          	   C   s  | j  ¡ \}}|  |d¡ |\}}}|  |d¡ |  |d¡ |  |¡ | j  d¡\}}|  |d¡ |\}}}|  |d¡ |  |d¡ |  |¡ | j  d¡\}}|  |d¡ |\}}}|  |d¡ |  |d¡ |  |¡ |  tj¡}| j  d¡ W d Q R X |  |jjd	¡ d S )
Nz"220 3000237 <45223423@example.com>i­Ç- z<45223423@example.com>iªÇ- z"220 3000234 <45223423@example.com>z220 0 <45223423@example.com>r   z<non-existent@example.com>z430 No Such Article Found)	r   r]   r   r&  r$   r%   re   r'   r(   )r   r   ÚinforR   rñ   r   r)   r   r   r   Útest_articleÇ  s*    





zNNTPv1v2TestsMixin.test_articlec             C   sŒ   t  ¡ }| jj|d\}}|  |d¡ |\}}}|  |d¡ |  |d¡ |  |g ¡ | ¡ }|  | d¡t|ƒ¡ |  | 	d¡t|ƒ¡ d S )N)r†   z"220 3000237 <45223423@example.com>i­Ç- z<45223423@example.com>sK   From: "Demo User" <nobody@example.net>
Subject: I am just a test article
sU   This is just a test article.
.Here is a dot-starting line.

-- Signed by AndrÃ©.
)
rž   r¡   r   r]   r   Úgetvaluer   r   ÚasciirÎ   )r   Úfr   r'  rR   rñ   r   r¬   r   r   r   Útest_article_fileâ  s    

z$NNTPv1v2TestsMixin.test_article_filec          	   C   s  | j  ¡ \}}|  |d¡ |\}}}|  |d¡ |  |d¡ |  |¡ | j  d¡\}}|  |d¡ |\}}}|  |d¡ |  |d¡ |  |¡ | j  d¡\}}|  |d¡ |\}}}|  |d¡ |  |d¡ |  |¡ |  tj¡}| j  d¡ W d Q R X |  |jjd	¡ d S )
Nz"221 3000237 <45223423@example.com>i­Ç- z<45223423@example.com>iªÇ- z"221 3000234 <45223423@example.com>z221 0 <45223423@example.com>r   z<non-existent@example.com>z430 No Such Article Found)	r   rd   r   r%  r$   r%   re   r'   r(   )r   r   r'  rR   rñ   r   r)   r   r   r   Ú	test_head÷  s*    





zNNTPv1v2TestsMixin.test_headc             C   sŒ   t  ¡ }| jj|d\}}|  |d¡ |\}}}|  |d¡ |  |d¡ |  |g ¡ | ¡ }|  | d¡t|ƒ¡ |  	| 
d¡t|ƒ¡ d S )N)r†   z"221 3000237 <45223423@example.com>i­Ç- z<45223423@example.com>sK   From: "Demo User" <nobody@example.net>
Subject: I am just a test article
sU   This is just a test article.
.Here is a dot-starting line.

-- Signed by AndrÃ©.
)rž   r¡   r   rd   r   r)  r   r   r*  rŽ   rÎ   )r   r+  r   r'  rR   rñ   r   r¬   r   r   r   Útest_head_file  s    

z!NNTPv1v2TestsMixin.test_head_filec          	   C   s  | j  ¡ \}}|  |d¡ |\}}}|  |d¡ |  |d¡ |  |¡ | j  d¡\}}|  |d¡ |\}}}|  |d¡ |  |d¡ |  |¡ | j  d¡\}}|  |d¡ |\}}}|  |d¡ |  |d¡ |  |¡ |  tj¡}| j  d¡ W d Q R X |  |jjd	¡ d S )
Nz"222 3000237 <45223423@example.com>i­Ç- z<45223423@example.com>iªÇ- z"222 3000234 <45223423@example.com>z222 0 <45223423@example.com>r   z<non-existent@example.com>z430 No Such Article Found)	r   rf   r   r#  r$   r%   re   r'   r(   )r   r   r'  rR   rñ   r   r)   r   r   r   Ú	test_body&  s*    





zNNTPv1v2TestsMixin.test_bodyc             C   sŒ   t  ¡ }| jj|d\}}|  |d¡ |\}}}|  |d¡ |  |d¡ |  |g ¡ | ¡ }|  | d¡t|ƒ¡ |  	| 
d¡t|ƒ¡ d S )N)r†   z"222 3000237 <45223423@example.com>i­Ç- z<45223423@example.com>sK   From: "Demo User" <nobody@example.net>
Subject: I am just a test article
sU   This is just a test article.
.Here is a dot-starting line.

-- Signed by AndrÃ©.
)rž   r¡   r   rf   r   r)  rŽ   r   r*  r   rÎ   )r   r+  r   r'  rR   rñ   r   r¬   r   r   r   Útest_body_fileA  s    

z!NNTPv1v2TestsMixin.test_body_filec             C   s”   |   | d¡|¡ |  t|ƒd¡ |d \}}|  |d¡ |  |ddddd	d
dddœ¡ |d \}}|  |d d ¡ |d \}}|  |d d¡ d S )Nz224 r$  r   é9   zEDoug Hellmann <doug.hellmann-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>zGRe: ANN: New Plone book with strong Python (and Zope) themes throughoutzSat, 19 Jun 2010 18:04:08 -0400z0<4FD05F05-F98B-44DC-8111-C6009C925F0C@gmail.com>z<hvalf7$ort$1@dough.gmane.org>Z7103Z16z+news.gmane.org gmane.comp.python.authors:57)rH   rG   r-   z
message-idrI   z:bytesz:linesÚxrefrY   r2  rm   rG   u0   Re: Message d'erreur incomprÃ©hensible (par moi))r   r   r   r   )r   r   Ú	overviewsrR   rV   r   r   r   Úcheck_over_xover_respU  s$    

z(NNTPv1v2TestsMixin.check_over_xover_respc             C   s"   | j  dd¡\}}|  ||¡ d S )Nr1  é;   )r   rO   r4  )r   r   r3  r   r   r   rS   j  s    zNNTPv1v2TestsMixin.test_xoverc             C   s    | j  d¡\}}|  ||¡ d S )N)r1  r5  )r   rV   r4  )r   r   r3  r   r   r   rX   n  s    zNNTPv1v2TestsMixin.test_overs  From: "Demo User" <nobody@example.net>
Subject: I am just a test article
Content-Type: text/plain; charset=UTF-8; format=flowed
Message-ID: <i.am.an.article.you.will.want@example.com>

This is just a test article.
.Here is a dot-starting line.

-- Signed by AndrÃ©.
c             C   sl   | j j}|  t|ƒd¡ |  |d d¡ |  |d d¡ |  |d d¡ |  |d d	¡ |  |d
 d¡ d S )NrT   rU   s   .
rÌ   s   -- Signed by AndrÃ©.
r   s   
r!  s    ..Here is a dot-starting line.
r   s(   From: "Demo User" <nobody@example.net>
)r¤   rï   r   r   )r   r   r   r   r   Ú_check_posted_body  s    z%NNTPv1v2TestsMixin._check_posted_bodyc            G   sd   | j }|||ƒf }d | j_||Ž }|  ¡  | j  dd¡}|||ƒf }d | j_||Ž }|  ¡  |S )Ns   
ó   
)Úsample_postr¤   rï   r6  Úreplace)r   ÚfuncÚfile_factoryr¾   ÚpostZ	func_argsr   r   r   r   Ú_check_post_ihave_subŠ  s    z(NNTPv1v2TestsMixin._check_post_ihave_subc             G   sÀ   | j |f|ždtiŽ}|  ||¡ | j |f|ždtiŽ}|  ||¡ | j |f|ždtjiŽ}|  ||¡ dd„ }| j |f|žd|iŽ}|  ||¡ dd„ }| j |f|žd|iŽ}|  ||¡ d S )Nr;  c             S   s   t | jddƒS )NT)Úkeepends)ÚiterrÛ   )r¯   r   r   r   Ú	iterlines¥  s    z6NNTPv1v2TestsMixin.check_post_ihave.<locals>.iterlinesc             S   s   t | jddƒS )NF)r>  )r?  rÛ   )r¯   r   r   r   r@  ª  s    )r=  r\   r   Ú	bytearrayrž   r¡   )r   r:  Zsuccess_respr¾   r   r@  r   r   r   Úcheck_post_ihaveš  s    z#NNTPv1v2TestsMixin.check_post_ihavec          	   C   sR   |   | jjd¡ d| j_|  tj¡}| j | j¡ W d Q R X |  	|j
jd¡ d S )Nz240 Article received OKFz440 Posting not permitted)rB  r   r<  r¤   rÄ   r$   r%   re   r8  r   r'   r(   )r   r)   r   r   r   Ú	test_post¯  s    
zNNTPv1v2TestsMixin.test_postc          	   C   sN   |   | jjdd¡ |  tj¡}| j d| j¡ W d Q R X |  |jj	d¡ d S )Nz235 Article transferred OKz+<i.am.an.article.you.will.want@example.com>z<another.message.id>z435 Article not wanted)
rB  r   Zihaver$   r%   re   r8  r   r'   r(   )r   r)   r   r   r   Ú
test_ihave·  s    
zNNTPv1v2TestsMixin.test_ihavec             C   s.   t   dddddd¡}|  tj| jjd|¡ d S )NiÚ  rY   r  r   zcomp.lang.python)r,   r$   r%   ÚNNTPDataErrorr   r  )r   r/   r   r   r   Útest_too_long_lines¿  s    z&NNTPv1v2TestsMixin.test_too_long_lines)%r   r	   r
   r¹   r   r
  rF   r  r   r!   r  r  r  r9   r<   rD   r  r#  r%  r&  r(  r,  r-  r.  r/  r0  r4  rS   rX   r8  r6  r=  rB  rC  rD  rF  rÀ   r   r   )r»   r   r  2  sB   
r  c               @   s   e Zd ZdZeZdd„ ZdS )ÚNNTPv1TestsrY   c             C   s:   | j  ¡ }|  |i ¡ |  | j jd¡ |  | j jd ¡ d S )NrY   )r   ro   r   rn   Únntp_implementation)r   rk   r   r   r   Ú	test_capsË  s    
zNNTPv1Tests.test_capsN)r   r	   r
   rn   rÂ   r½   rI  r   r   r   r   rG  Å  s   rG  c               @   s   e Zd ZdZeZdd„ ZdS )ÚNNTPv2Testsrm   c             C   sb   | j  ¡ }|  |ddgddgdgg dddd	d
dgg g g dœ¡ |  | j jd¡ |  | j jd¡ d S )NÚ2Ú3ZINNz2.5.1ZUSERrç   zACTIVE.TIMESzDISTRIB.PATSZHEADERSrè   zOVERVIEW.FMT)ÚVERSIONZIMPLEMENTATIONr  ZHDRri   ZOVERZPOSTÚREADERr$  z	INN 2.5.1)r   ro   r   rn   rH  )r   rk   r   r   r   rI  Ø  s    

zNNTPv2Tests.test_capsN)r   r	   r
   rn   rü   r½   rI  r   r   r   r   rJ  Ò  s   rJ  c               @   s   e Zd ZdZeZdd„ ZdS )ÚCapsAfterLoginNNTPv2Testsrm   c             C   s2   |   | jji ¡ | j dd¡ |  d| jj¡ d S )Nr  r  rM  )r   r   r	  ru   r8   )r   r   r   r   Útest_caps_only_after_loginï  s    z4CapsAfterLoginNNTPv2Tests.test_caps_only_after_loginN)r   r	   r
   rn   r  r½   rP  r   r   r   r   rO  é  s   rO  c               @   s   e Zd ZdZeZdd„ ZdS )ÚSendReaderNNTPv2Testsrm   c             C   s   |   d| jj¡ d S )NrN  )r8   r   r	  )r   r   r   r   Ú(test_we_are_in_reader_mode_after_connectý  s    z>SendReaderNNTPv2Tests.test_we_are_in_reader_mode_after_connectN)r   r	   r
   rn   r  r½   rR  r   r   r   r   rQ  õ  s   rQ  c               @   sP   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Ze	 
ed¡dd„ ƒZdS )Ú	MiscTestsc                sV   ‡ fdd„}|ddƒ |ddƒ |ddƒ |ddƒ |dd	ƒ |d
dƒ |ddƒ d S )Nc                s   ˆ   t | ¡|¡ d S )N)r   r%   Údecode_header)Úar¯   )r   r   r   Úgives  s    z+MiscTests.test_decode_header.<locals>.givesr6   za plain headerz with extra  spaces z%=?ISO-8859-15?Q?D=E9buter_en_Python?=u   DÃ©buter en Pythonz=?utf-8?q?Re=3A_=5Bsqlite=5D_probl=C3=A8me_avec_ORDER_BY_sur_des_cha?= =?utf-8?q?=C3=AEnes_de_caract=C3=A8res_accentu=C3=A9es?=uP   Re: [sqlite] problÃ¨me avec ORDER BY sur des chaÃ®nes de caractÃ¨res accentuÃ©esz,Re: =?UTF-8?B?cHJvYmzDqG1lIGRlIG1hdHJpY2U=?=u   Re: problÃ¨me de matriceu0   Re: Message d'erreur incomprÃ©hensible (par moi)r   )r   rV  r   )r   r   Útest_decode_header  s    



zMiscTests.test_decode_headerc             C   sD  dddddddg}|   t |¡dd	d
ddddg¡ dddddddg}|   t |¡dd	d
ddddg¡ dddddddg}|   t |¡dd	d
ddddg¡ dddddddddg	}|   t |¡dd	d
ddddddg	¡ dddddddddg	}|   t |¡dd	d
ddddddg	¡ ddddddddg}|   t |¡dd	d
dddddg¡ d S )NzSubject:zFrom:zDate:zMessage-ID:zReferences:z:bytesz:linesrG   rH   r-   z
message-idrI   zBytes:zLines:zsubject:zFROM:zDaTe:zmessage-ID:zBYTES:z	Xref:fullzDistribution:fullr2  Zdistributionz	Xref:FULLzDistribution:FULL)r   r%   Z_parse_overview_fmt)r   r   r   r   r   Útest_parse_overview_fmt  s@    











z!MiscTests.test_parse_overview_fmtc             C   s¾   t jdg }dg}t  ||¡}|\\}}|  |d¡ |  |dddddd	d
ddœ¡ dg}t  ||¡}|\\}}|  |d d ¡ dg}t  ||¡}|\\}}|  |d d¡ |  |d d¡ d S )Nr2  z·3000234	I am just a test article	"Demo User" <nobody@example.com>	6 Oct 1998 04:38:40 -0500	<45223423@example.com>	<45454@example.net>	1234	17	Xref: news.example.com misc.test:3000363iªÇ- zI am just a test articlez "Demo User" <nobody@example.com>z6 Oct 1998 04:38:40 -0500z<45223423@example.com>z<45454@example.net>Z1234Z17z"news.example.com misc.test:3000363)rG   rH   r-   z
message-idrI   z:bytesz:linesr2  z3000234	I am just a test article	"Demo User" <nobody@example.com>	6 Oct 1998 04:38:40 -0500	<45223423@example.com>	<45454@example.net>	1234	17		z„3000234	I am just a test article	"Demo User" <nobody@example.com>	6 Oct 1998 04:38:40 -0500	<45223423@example.com>	 	1234	17	Xref: 	rI   ú r6   )r%   Z_DEFAULT_OVERVIEW_FMTZ_parse_overviewr   )r   rý   r   ZoverviewrR   Zfieldsr   r   r   Útest_parse_overview;  s.    



zMiscTests.test_parse_overviewc          	      sh   ‡ fdd„}|dd dddddd	ƒ |d
ddddddd	ƒ |dddddddd	ƒ |dddddddd	ƒ d S )Nc                s   ˆ   t | |¡tj|Ž ¡ d S )N)r   r%   Z_parse_datetimer,   )rU  r¯   Úc)r   r   r   rV  j  s    z,MiscTests.test_parse_datetime.<locals>.givesZ19990623135624iÏ  r  é   r  é8   é   Ú19990623Ú135624Ú990623Z090623iÙ  r   )r   rV  r   )r   r   Útest_parse_datetimei  s
    zMiscTests.test_parse_datetimec          	      sŽ   ‡ fdd„}|ddddddd	d
ƒ |dddddddd
ƒ |ddddddddƒ ‡ fdd„}|dddd	dƒ |dddddƒ |dddddƒ d S )Nc       	         sF   t   | |||||¡}ˆ  t |¡||f¡ ˆ  t |d¡||f¡ d S )NF)r,   r   r%   Ú_unparse_datetime)	ÚyÚMÚdÚhr  Úsrë   rì   r/   )r   r   r   rV  w  s
    
z.MiscTests.test_unparse_datetime.<locals>.givesiÏ  r  r\  r  r]  r^  r_  r`  iÐ  Z20000623iÚ  r=   rY   rm   r$  Z20100605Ú010203c                s@   t  | ||¡}ˆ  t |¡||f¡ ˆ  t |d¡||f¡ d S )NF)r,   r-   r   r%   rc  )rd  re  rf  rë   rì   r/   )r   r   r   rV    s
    
Ú000000r   )r   rV  r   )r   r   Útest_unparse_datetimet  s    zMiscTests.test_unparse_datetimec          	      sŽ   ‡ fdd„}|ddddddd	d
ƒ |dddddddd
ƒ |ddddddddƒ ‡ fdd„}|dddd	dƒ |dddddƒ |dddddƒ d S )Nc       	         s0   t   | |||||¡}ˆ  t |d¡||f¡ d S )NT)r,   r   r%   rc  )	rd  re  rf  rg  r  rh  rë   rì   r/   )r   r   r   rV  Ž  s    z5MiscTests.test_unparse_datetime_legacy.<locals>.givesiÏ  r  r\  r  r]  r^  ra  r`  iÐ  Z000623iÚ  r=   rY   rm   r$  Z100605ri  c                s*   t  | ||¡}ˆ  t |d¡||f¡ d S )NT)r,   r-   r   r%   rc  )rd  re  rf  rë   rì   r/   )r   r   r   rV  –  s    rj  r   )r   rV  r   )r   r   Útest_unparse_datetime_legacy‹  s    z&MiscTests.test_unparse_datetime_legacyzrequires SSL supportc             C   s   |   ttdƒ¡ d S )Nr›   )r   r‡   r%   )r   r   r   r   Útest_ssl_supportž  s    zMiscTests.test_ssl_supportN)r   r	   r
   rW  rX  rZ  rb  rk  rl  r‘   Ú
skipUnlessÚsslrm  r   r   r   r   rS    s   (.rS  c               @   s   e Zd Zdd„ ZdS )ÚPublicAPITestsc             C   sP   |   ttdƒ¡ dddddddd	g}td k	r6| d
¡ |  ttjƒt|ƒ¡ d S )NÚ__all__r   rt   ÚNNTPReplyErrorre   r&   ÚNNTPProtocolErrorrE  rT  r›   )r   r‡   r%   ro  rÍ   r   Úsetrq  )r   Z
target_apir   r   r   Útest_module_all_attribute¦  s    

z(PublicAPITests.test_module_all_attributeN)r   r	   r
   ru  r   r   r   r   rp  £  s   rp  c               @   sD   e Zd ZejZddd„Zdd„ Zdd„ Zdd	„ Z	d
d„ Z
dd„ ZdS )ÚMockSocketTestsNc          
      s–   G ‡ fdd„dƒ}G ‡‡‡fdd„dƒ‰ d‰g ‰t d|ƒ. |  ||¡ | jd||d W d Q R X W d Q R X |  ˆ¡ xˆD ]}|  |j¡ q~W d S )	Nc                   s   e Zd Z‡ fdd„ZdS )zNMockSocketTests.check_constructor_error_conditions.<locals>.mock_socket_modulec                s   ˆ ƒ S )Nr   )Zaddressr‹   )Ú
MockSocketr   r   Úcreate_connection¼  s    z`MockSocketTests.check_constructor_error_conditions.<locals>.mock_socket_module.create_connectionN)r   r	   r
   rx  r   )rw  r   r   Úmock_socket_module»  s   ry  c                   s&   e Zd Z‡fdd„Z‡ ‡fdd„ZdS )zFMockSocketTests.check_constructor_error_conditions.<locals>.MockSocketc                s   d‰ d S )NTr   )r   )Úsocket_closedr   r   ÚcloseÀ  s    zLMockSocketTests.check_constructor_error_conditions.<locals>.MockSocket.closec                s    ˆƒ }t |ƒ\}}ˆ  |¡ |S )N)r¶   rÍ   )ÚsocketÚmoder¤   rÿ   r†   )Úfilesr½   r   r   ÚmakefileÄ  s    
zOMockSocketTests.check_constructor_error_conditions.<locals>.MockSocket.makefileN)r   r	   r
   r{  r  r   )r~  r½   rz  r   r   rw  ¿  s   rw  Fznntplib.socketZdummy)rq   rr   )r   ZassertRaisesRegexÚ
nntp_classr   r  )r   r½   Zexpected_error_typeZexpected_error_msgru   rr   ry  r+  r   )rw  r~  r½   rz  r   Ú"check_constructor_error_conditions¶  s    $

z2MockSocketTests.check_constructor_error_conditionsc             C   s&   G dd„ dt ƒ}|  |tj|j¡ d S )Nc               @   s   e Zd ZdZdS )z1MockSocketTests.test_bad_welcome.<locals>.HandlerzBad WelcomeN)r   r	   r
   r   r   r   r   r   ÚHandlerÕ  s   r‚  )rÂ   r  r%   rs  r   )r   r‚  r   r   r   Útest_bad_welcomeÓ  s    z MockSocketTests.test_bad_welcomec             C   s&   G dd„ dt ƒ}|  |tj|j¡ d S )Nc               @   s   e Zd ZdZdS )zEMockSocketTests.test_service_temporarily_unavailable.<locals>.Handlerz#400 Service temporarily unavailableN)r   r	   r
   r   r   r   r   r   r‚  Ü  s   r‚  )rÂ   r  r%   re   r   )r   r‚  r   r   r   Ú$test_service_temporarily_unavailableÚ  s    z4MockSocketTests.test_service_temporarily_unavailablec             C   s&   G dd„ dt ƒ}|  |tj|j¡ d S )Nc               @   s   e Zd ZdZdS )zEMockSocketTests.test_service_permanently_unavailable.<locals>.Handlerz#502 Service permanently unavailableN)r   r	   r
   r   r   r   r   r   r‚  ã  s   r‚  )rÂ   r  r%   r&   r   )r   r‚  r   r   r   Ú$test_service_permanently_unavailableá  s    z4MockSocketTests.test_service_permanently_unavailablec                s,   G ‡ fdd„dt ƒ}d‰ |  |tjˆ ¡ d S )Nc                   s   e Zd Z‡ fdd„ZdS )z6MockSocketTests.test_bad_capabilities.<locals>.Handlerc                s   |   ˆ ¡ d S )N)rÝ   )r   )Úcapabilities_responser   r   rþ   ë  s    zJMockSocketTests.test_bad_capabilities.<locals>.Handler.handle_CAPABILITIESN)r   r	   r
   rþ   r   )r†  r   r   r‚  ê  s   r‚  z201 bad capability)rÂ   r  r%   rr  )r   r‚  r   )r†  r   Útest_bad_capabilitiesè  s    z%MockSocketTests.test_bad_capabilitiesc                s8   d}d}G ‡ fdd„dt ƒ}d‰ |  |tjˆ ||¡ d S )Nzt@e.comZpythonc                   s   e Zd Z‡ fdd„ZdS )z3MockSocketTests.test_login_aborted.<locals>.Handlerc                s   |   ˆ ¡ d S )N)rÝ   )r   r¾   )Úauthinfo_responser   r   rû   ö  s    zCMockSocketTests.test_login_aborted.<locals>.Handler.handle_AUTHINFON)r   r	   r
   rû   r   )rˆ  r   r   r‚  õ  s   r‚  z503 Mechanism not recognized)rÂ   r  r%   r&   )r   ru   rr   r‚  r   )rˆ  r   Útest_login_abortedñ  s    z"MockSocketTests.test_login_aborted)NN)r   r	   r
   r%   r   r€  r  rƒ  r„  r…  r‡  r‰  r   r   r   r   rv  ¯  s   
	rv  c               @   s   e Zd Zdd„ ZdS )Úbypass_contextc             K   s   | S )Nr   )Úsockr¾   r   r   r   Úwrap_socketÿ  s    zbypass_context.wrap_socketN)r   r	   r
   rŒ  r   r   r   r   rŠ  ý  s   rŠ  c               @   s   e Zd Zedd„ ƒZdS )ÚMockSslTestsc              O   s   t j| dti|—ŽS )NZssl_context)r%   r›   rŠ  )r­   Úkwr   r   r   r€    s    zMockSslTests.nntp_classN)r   r	   r
   Ústaticmethodr€  r   r   r   r   r    s   r  c               @   s0   e Zd Zdd„ Zdd„ Ze ed¡dd„ ƒZdS )	ÚLocalServerTestsc             C   st   t   ¡ }t |¡}| ¡  tj| j|fd| _| j ¡  |  	| jj
¡ ttj|dd ¡ | _|  	| jjd d d ¡ d S )N)Útargetr¾   F)rs   )r|  r   Z	bind_portZlistenÚ	threadingZThreadÚ
run_serverZ
backgroundrW   Z
addCleanuprÚ   r   ZHOSTÚ	__enter__ÚnntpÚ__exit__)r   r‹  Zportr   r   r   r¹   
  s    

zLocalServerTests.setUpc          	   C   sô   | |  ¡ \}}W d Q R X t ¡ Æ}| |¡ | | d¡¡}| d¡ xš| ¡ }|dkrh| d¡ qL|dkr¾| ¡  | d¡ t 	¡ }| 
t¡ |j|dd}| |¡ | | d¡¡}qL|d	krÔ| d
¡ P qLtd |¡ƒ‚qLW W d Q R X d S )NÚrbs   200 Server ready
s   CAPABILITIES
s.   101 Capability list:
VERSION 2
STARTTLS
.
s
   STARTTLS
s   382 Begin TLS negotiation now
T)Zserver_sides   QUIT
s
   205 Bye!
zUnexpected command {!r})ZacceptÚ
contextlibÚ	ExitStackÚenter_contextr  Zsendallr¥   r{  ro  Z
SSLContextZload_cert_chainÚcertfilerŒ  rÏ   rÐ   )r   r‹  Zclientrÿ   ZcleanupÚreaderrÖ   Úcontextr   r   r   r“    s0    







zLocalServerTests.run_serverzrequires SSL supportc             C   s`   | j j}| j j}| j  ¡  |  || j j¡ |  || j j¡ |  | j jtj¡ |  t	| j j¡ d S )N)
r•  r†   r‹  ZstarttlsZassertNotEqualr.   ro  Z	SSLSocketr$   rÏ   )r   r†   r‹  r   r   r   rœ   6  s    
zLocalServerTests.test_starttlsN)	r   r	   r
   r¹   r“  r‘   rn  ro  rœ   r   r   r   r   r  	  s    r  Ú__main__);rž   r|  r,   rØ   r‘   r~   r˜  Zos.pathÚosr   r’  Ztestr   r%   r   r   Zunittest.mockr   ro  ÚImportErrorr   ÚpathrÚ   ÚdirnameÚ__file__r›  r   rÔ   r   r…   r‰   r—   ZSSLEOFErrorZTestCaser–   rn  rš   rŸ   r   r¶   r·   rÁ   rÂ   rü   r  r  r  rG  rJ  rO  rQ  rS  rp  rv  rŠ  r  r  r   Úmainr   r   r   r   Ú<module>   sx   

 |
,  G
    #N<
