o
    HXîh  ã                   @   sr   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	 G dd„ dej
ƒZedkr7e ¡  dS dS )é    N)Úsupport)Ú	os_helperc                   @   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d„Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Ze ejdkd¡d d!„ ƒZd"d#„ Zd$d%„ Zd&d'„ Zd(S )*ÚNetrcTestCasec                 C   s~   t  |¡}d}tjdkr|d7 }t ¡ \}}tj||dd}| |¡ W d   ƒ n1 s.w   Y  |  	tj
|¡ t |¡S )NÚwÚcygwinÚtzutf-8)ÚmodeÚencoding)ÚtextwrapÚdedentÚsysÚplatformÚtempfileÚmkstempÚosÚfdopenÚwriteZ
addCleanupÚunlinkÚnetrc)ÚselfZ	test_datar   Ztemp_fdZtemp_filenameÚfp© r   ú9/opt/python-3.10.19/usr/lib/python3.10/test/test_netrc.pyÚmake_nrc   s   

ÿ
zNetrcTestCase.make_nrcc                 C   sP   |   d¡}|  |jd d¡ |  |jd d¡ |   | ¡ ¡}|  |j|j¡ d S )Nz‡            machine host1.domain.com login log1 password pass1 account acct1
            default login log2 password pass2
            zhost1.domain.com)Zlog1Zacct1Zpass1Údefault)Úlog2NZpass2)r   ÚassertEqualÚhostsÚ__repr__)r   ÚnrcZnrc2r   r   r   Útest_default   s   
ÿzNetrcTestCase.test_defaultc                 C   s*   |   d¡}|  |jddgddgdœ¡ d S )Nz‰            macdef macro1
            line1
            line2

            macdef macro2
            line3
            line4
            zline1
zline2
zline3
zline4
)Zmacro1Zmacro2)r   r   Zmacros)r   r   r   r   r   Útest_macros   s   
	ÿzNetrcTestCase.test_macrosc                 C   s&   |   |¡}|  |jd dd|f¡ d S )Nzhost.domain.comÚlogZacct©r   r   r   ©r   r   Úpasswdr   r   r   Ú_test_passwords,   s   
zNetrcTestCase._test_passwordsc                 C   ó   |   dd¡ d S )NzV            machine host.domain.com login log password #pass account acct
            ú#pass©r&   ©r   r   r   r   Útest_password_with_leading_hash0   ó   þz-NetrcTestCase.test_password_with_leading_hashc                 C   r'   )NzV            machine host.domain.com login log password pass# account acct
            zpass#r)   r*   r   r   r   Ú test_password_with_trailing_hash5   r,   z.NetrcTestCase.test_password_with_trailing_hashc                 C   r'   )NzV            machine host.domain.com login log password pa#ss account acct
            zpa#ssr)   r*   r   r   r   Ú test_password_with_internal_hash:   r,   z.NetrcTestCase.test_password_with_internal_hashÚpassc                 C   s8   |   |¡}|  |jd dd |f¡ |  |jd d¡ d S )Núfoo.domain.comÚbarzbar.domain.com)ZfooNr/   r#   r$   r   r   r   Ú_test_comment?   s   
zNetrcTestCase._test_commentc                 C   ó   |   d¡ d S )Nz˜            # comment
            machine foo.domain.com login bar password pass
            machine bar.domain.com login foo password pass
            ©r2   r*   r   r   r   Ú test_comment_before_machine_lineD   ó   z.NetrcTestCase.test_comment_before_machine_linec                 C   r3   )Nz—            #comment
            machine foo.domain.com login bar password pass
            machine bar.domain.com login foo password pass
            r4   r*   r   r   r   Ú)test_comment_before_machine_line_no_spaceK   r6   z7NetrcTestCase.test_comment_before_machine_line_no_spacec                 C   r3   )Nz            #
            machine foo.domain.com login bar password pass
            machine bar.domain.com login foo password pass
            r4   r*   r   r   r   Ú*test_comment_before_machine_line_hash_onlyR   r6   z8NetrcTestCase.test_comment_before_machine_line_hash_onlyc                 C   r3   )NzŒ            machine foo.domain.com login bar password pass # comment
            machine bar.domain.com login foo password pass
            r4   r*   r   r   r   Ú#test_comment_at_end_of_machine_lineY   r6   z1NetrcTestCase.test_comment_at_end_of_machine_linec                 C   r3   )Nz‹            machine foo.domain.com login bar password pass #comment
            machine bar.domain.com login foo password pass
            r4   r*   r   r   r   Ú,test_comment_at_end_of_machine_line_no_space_   r6   z:NetrcTestCase.test_comment_at_end_of_machine_line_no_spacec                 C   r'   )NzŒ            machine foo.domain.com login bar password #pass #comment
            machine bar.domain.com login foo password pass
            r(   r4   r*   r   r   r   Ú1test_comment_at_end_of_machine_line_pass_has_hashe   s   ýz?NetrcTestCase.test_comment_at_end_of_machine_line_pass_has_hashÚposixzPOSIX only testc              	   C   sø   t  d ¡m}tj |d¡}t|dƒ}| d¡ W d   ƒ n1 s"w   Y  t  ¡ /}| d|¡ t 	|d¡ t
 
¡ }|  |jd d¡ t 	|d¡ |  t
jt
j
¡ W d   ƒ n1 s]w   Y  W d   ƒ d S W d   ƒ d S 1 suw   Y  d S )	Nú.netrcZwtz‹                    machine foo.domain.com login bar password pass
                    default login foo password pass
                    ÚHOMEé€  r0   )r1   Nr/   i’  )r   Útemp_cwdr   ÚpathÚjoinÚopenr   ÚEnvironmentVarGuardÚsetÚchmodr   r   r   ÚassertRaisesZNetrcParseError)r   ÚdÚfnÚfÚenvironr   r   r   r   Útest_securityl   s$   ÿ
ÿùù"ùzNetrcTestCase.test_securityc              	   C   s‚   t  d ¡2}t  ¡ }| d|¡ |  ttj¡ W d   ƒ n1 s"w   Y  W d   ƒ d S W d   ƒ d S 1 s:w   Y  d S )Nr>   )r   r@   rD   rE   rG   ÚFileNotFoundErrorr   )r   rH   rK   r   r   r   Útest_file_not_found_in_home€   s   
þÿ"ÿz)NetrcTestCase.test_file_not_found_in_homec                 C   s   | j ttjdd d S )NZunlikely_netrc)Úfile)rG   rM   r   r*   r   r   r   Útest_file_not_found_explicit†   s   

ÿz*NetrcTestCase.test_file_not_found_explicitc              	      sø   t  d ¡m‰tj ˆd¡}t|dƒ}| d¡ W d   ƒ n1 s"w   Y  t |d¡ tjj‰g ‰ ‡ ‡‡fdd„}t	 
tjd|¡ t ¡ }| d¡\}}}|  |d	¡ W d   ƒ n1 s`w   Y  |  ˆ ¡ W d   ƒ d S 1 suw   Y  d S )
Nr=   r   z.machine foo.domain.com login bar password passr?   c                    sZ   ˆ   | ¡ t ¡ }| dˆ¡ | dˆ¡ ˆ| ƒ}|W  d   ƒ S 1 s&w   Y  d S )Nr>   ÚUSERPROFILE)Úappendr   rD   rE   )ÚsrK   Úresult©ZcalledZ	fake_homeZorig_expanduserr   r   Úfake_expanduser”   s   

$üz8NetrcTestCase.test_home_not_set.<locals>.fake_expanduserÚ
expanduserr0   r1   )r   r@   r   rA   rB   rC   r   rF   rW   r   Z	swap_attrr   Zauthenticatorsr   Z
assertTrue)r   Zfake_netrc_pathrJ   rV   r   ZloginZaccountÚpasswordr   rU   r   Útest_home_not_setŠ   s    ÿý"êzNetrcTestCase.test_home_not_setN)r/   )Ú__name__Ú
__module__Ú__qualname__r   r    r!   r&   r+   r-   r.   r2   r5   r7   r8   r9   r:   r;   ÚunittestZ
skipUnlessr   ÚnamerL   rN   rP   rY   r   r   r   r   r      s(    

r   Ú__main__)r   r   r]   r   r   r
   Útestr   Ztest.supportr   ZTestCaser   rZ   Úmainr   r   r   r   Ú<module>   s   0  ÿ