
    9
gG"                         d dl Zd dlZd dlZd dlZd dlmZ d dlZd dl	Z
d dlZ G d d      Z G d d      Z G d d      Zej                   j#                  d	      d
        Zy)    N)cleandocc                   Z    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zy)TestPackageIndexc                     d}|dz  } dj                         j                  di t               }t        j                  j
                  j                  |      sJ y )Nz&http://other_url?:action=show_md5&amp;z'digest=0123456789abcdef0123456789abcdefz
            <a href="http://some_url">Name</a>
            (<a title="MD5 hash"
            href="{hash_url}">md5</a>)
         )lstripformatlocals
setuptoolspackage_indexPYPI_MD5match)selfhash_urldocs      b/var/www/api/v1/venv_getwork_v1/lib/python3.12/site-packages/setuptools/tests/test_packageindex.py
test_regexzTestPackageIndex.test_regex   s^    ;==  FHVV	( %h	(
 ''0066s;;;    c                 :   t         j                  j                         }d}t        j                  t
        t        j                  |            5  |j                  |      }t        |t        j                  j                        sJ 	 d d d        y # 1 sw Y   y xY w)Nz.http://127.0.0.1:0/nonesuch/test_package_indexr   r   r   PackageIndexpytestraises	Exceptionreescapeopen_url
isinstanceurlliberror	HTTPErrorr   indexurlvs       r   test_bad_url_bad_portz&TestPackageIndex.test_bad_url_bad_port   se    ((557>]]9BIIcN;s#Aa!7!7888 <;;s   8BBc                 >   t         j                  j                  d      }d}t        j                  t
        t        j                  |            5  |j                  |      }t        |t        j                  j                        sJ 	 d d d        y # 1 sw Y   y xY w)Nzwww.example.comhostszMurl:%20https://svn.plone.org/svn/collective/inquant.contentmirror.plone/trunkr   r   r#   s       r   test_bad_url_typoz"TestPackageIndex.test_bad_url_typo    sm     ((55<P5Q]]]9BIIcN;s#Aa!7!7888 <;;s   8BBc                     t         j                  j                  d      }d }||_        d}t	        j
                  t        d      5  |j                  |       d d d        y # 1 sw Y   y xY w)Nr)   r*   c                  @    t         j                  j                  d      )Nline)httpclientBadStatusLine)argss    r   _urlopenz?TestPackageIndex.test_bad_url_bad_status_line.<locals>._urlopen/   s    ++++F33r   zhttp://example.comr/   r   )r   r   r   openerr   r   r   r   )r   r$   r4   r%   s       r   test_bad_url_bad_status_linez-TestPackageIndex.test_bad_url_bad_status_line,   sU    ((55<P5Q	4  "]]9G4NN3 544s   A##A,c                    t         j                  j                  d      }d}	 |j                  |       t        d      # t        j
                  j                  $ r#}t        |      }d|v s
d|v sd|v sJ Y d}~yd}~ww xY w)	zO
        A bad URL with a double scheme should raise a DistutilsError.
        r)   r*   z2http://http://svn.pythonpaste.org/Paste/wphp/trunkznonnumeric portzgetaddrinfo failedzName or service not knownNzDid not raise)	r   r   r   r   	distutilserrorsDistutilsErrorstrRuntimeError)r   r$   r%   r!   msgs        r   test_bad_url_double_schemez+TestPackageIndex.test_bad_url_double_scheme7   s     ((55<P5Q C		NN3 ?++ .. 	e*C!S('3..#56 	s   A   B A;;B c                 p    t         j                  j                  d      }d}|j                  |d      sJ y )Nr)   r*   zfile:///tmp/test_package_indexT)r   r   r   url_ok)r   r$   r%   s      r   test_url_okzTestPackageIndex.test_url_okK   s5    ((55<P5Q.||C&&&r   c                     t         j                  j                  } |d      }d}||k(  sJ  |d      }d}||k(  sJ  |d      }d}||k(  sJ  |d      }d}||k(  sJ y )	Nzreportlab-2.5.win32-py2.4.exe)reportlab-2.5z2.4win32zreportlab-2.5.win32.exe)rC   NrD   z!reportlab-2.5.win-amd64-py2.7.exe)rC   z2.7	win-amd64zreportlab-2.5.win-amd64.exe)rC   NrE   )r   r   parse_bdist_wininst)r   parseactualexpecteds       r   test_parse_bdist_wininstz)TestPackageIndex.test_parse_bdist_wininstP   s    ((<<672!!!011!!!:;6!!!455!!!r   c                 ~    t         j                  j                  j                  } |d      \  }}|dk(  sJ |dk(  sJ y)zA
        Test the basic usage of _vcs_split_rev_from_url
        zhttps://example.com/bar@2995zhttps://example.com/bar2995N)r   r   r   _vcs_split_rev_from_url)r   vsrfur%   revs       r   test__vcs_split_rev_from_urlz-TestPackageIndex.test__vcs_split_rev_from_urlc   sE     ((55MM78S////f}}r   c                 >   |dz  }|j                  d      5 }|j                  d       ddd       dt        j                  j	                  t        |            z   dz   }t        j                  j                  |      }d|j                         v sJ y# 1 sw Y   kxY w)zR
        local_open should be able to read an index from the file system.
        z
index.htmlwz<div>content</div>Nzfile:/content)
openwriter    requestpathname2urlr;   r   r   
local_openread)r   tmpdir
index_filefr%   ress         r   test_local_indexz!TestPackageIndex.test_local_indexl   s     l*
__S!QGG() "33CK@@3F&&11#6CHHJ&&&	 "!s   BBc                    ddg}g d}g d}dg}dg}g d}|D 	
cg c]H  }|D ]A  }t        |||gdg      D ],  }	|D ]%  }
|
D cg c]  }dj                  |||	|g       c}' . C J }}
}	}}}|D ]X  \  }}t        t        j                  j                  d|z               }|d	   j                  dk(  sJ |d
   j                  |k(  rXJ  yc c}w c c}}
}	}}w )z6
        EGG fragments must comply to PEP 440
         z1!)0z0.0z0.0.0)a0b0rc0z.post0z.dev0))ra   ra   )	+ubuntu.0rf   )z	+ubuntu-0rf   )z	+ubuntu_0rf   z3http://example.com/example-foo.zip#egg=example-foo-r      N)sumjoinlistr   r   distros_for_urlversion)r   epochreleasesprepostdevlocalerplocslocversionsr&   vcdistss                   r   test_egg_fragmentz"TestPackageIndex.test_egg_fragmentw   s(   
 




 z

 
#tS)B40	 155RWWaAs^$5 	 6 1 6 6 	 
 EAr((88IAME
 8##r)))8##r)))  6
s   &CC!CCc                     d}t         j                  j                         }|dz  }|j                  dddd|g       |j                  dd|ddd	g       |j	                  ||      }|t        |      k(  sJ t        |j                        d
k(  sJ y )Nz7git+https://github.example/group/project@master#egg=foozproject@mastergitclone--quiet$https://github.example/group/projectz-Ccheckoutmaster   )r   r   r   registerdownloadr;   lencalls)r   tmp_pathfpr%   r$   expected_dirresults          r   test_download_git_with_revz+TestPackageIndex.test_download_git_with_rev   s    G((557"22
2
 	 	UD,
IxPQX.\****288}!!!r   c                     d}t         j                  j                         }|dz  }|j                  dddd|g       |j	                  ||       y )Nz0git+https://github.example/group/project#egg=fooprojectr}   r~   r   r   )r   r   r   r   r   )r   r   r   r%   r$   r   s         r   test_download_git_no_revz)TestPackageIndex.test_download_git_no_rev   sU    @((557)+
2
 	 	sH%r   c                     d}t         j                  j                         }d}t        j                  t
        j                  j                  |      5  |j                  ||       d d d        y # 1 sw Y   y xY w)Nz'svn+https://svn.example/project#egg=fooz!.*SVN download is not supported.*r   )	r   r   r   r   r   r8   r9   r:   r   )r   r   r%   r$   r=   s        r   test_download_svnz"TestPackageIndex.test_download_svn   sU    7((5572]]9++::#FNN3) GFFs   A..A7N)__name__
__module____qualname__r   r'   r,   r6   r>   rA   rJ   rP   r_   r{   r   r   r   r   r   r   r   r      sD    <9
9	 ,('
"&	'**X"&&*r   r   c                   *    e Zd Zd Zd Zd Zd Zd Zy)TestContentCheckersc                     t         j                  j                  j                  d      }|j	                  dj                  d             |j                  j                         dk(  sJ |j                         sJ y )N3http://foo/bar#md5=f12895fdffbd45007040d2e44df98478z$You should probably not be using MD5ascii f12895fdffbd45007040d2e44df98478)	r   r   HashCheckerfrom_urlfeedencodehash	hexdigestis_validr   checkers     r   test_md5zTestContentCheckers.test_md5   si    **66??A
 	;BB7KL||%%'+MMMM!!!r   c                     t         j                  j                  j                  d      }|j	                  dj                  d             |j                         sJ y)z<Content checks should succeed silently if no hash is presentz1http://foo/bar#something%20completely%20differentanythingr   Nr   r   r   r   r   r   r   r   s     r   test_other_fragmentz'TestContentCheckers.test_other_fragment   sL    **66???
 	Z&&w/0!!!r   c                     t         j                  j                  j                  d      }|j	                  dj                  d             |j                         sJ y)z0Content checks should succeed if a hash is emptyzhttp://foo/bar#md5=r   r   Nr   r   s     r   test_blank_md5z"TestContentCheckers.test_blank_md5   sH    **66??@UVZ&&w/0!!!r   c                 x    t         j                  j                  j                  d      }|j                  dk(  sJ y )Nr   md5)r   r   r   r   	hash_namer   s     r   test_get_hash_name_md5z*TestContentCheckers.test_get_hash_name_md5   s7    **66??A
   E)))r   c                     t         j                  j                  j                  d      }|j	                  d d      }|dk(  sJ y )Nr   c                     | S )Nr   )xs    r   <lambda>z1TestContentCheckers.test_report.<locals>.<lambda>   s    qr   zMy message about %szMy message about md5)r   r   r   r   report)r   r   reps      r   test_reportzTestContentCheckers.test_report   sC    **66??A
 nn[*?@,,,,r   N)r   r   r   r   r   r   r   r   r   r   r   r   r      s    """*-r   r   c                       e Zd Zd Zy)TestPyPIConfigc                     |dz  }|j                  t        d      d       t        j                  j	                         }|j
                  d   }|j                  dk(  sJ |j                  dk(  sJ y )Nz.pypircz
                [pypi]
                repository=https://pypi.org
                username=jaraco
                password=pity%
                zutf-8)encodingzhttps://pypi.orgjaracozpity%)
write_textr   r   r   
PyPIConfigcreds_by_repositoryusernamepassword)r   tmp_home_dirpypirccfgcreds        r   test_percent_in_passwordz'TestPyPIConfig.test_percent_in_password   s|    	)  	 
	
 &&113&&'9:}}(((}}'''r   N)r   r   r   r   r   r   r   r   r      s    (r   r   rg   c                  V    t         j                  j                  j                  d       y)z;
    REL should not hang on a contrived attack string.
    a  < rel=                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                N)r   r   RELsearchr   r   r   test_REL_DoSr     s    
   ''(>?r   )http.clientr0   r   urllib.errorr    urllib.requestinspectr   r   setuptools.package_indexr   distutils.errorsr8   r   r   r   marktimeoutr   r   r   r   <module>r      sd     	      |* |*~"- "-J( (( Q@ @r   