î
½1kdUN  ã               @   s@  d  Z  d d l m 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 d d l m Z m Z d d l m Z m Z d d l m Z d d	 l m Z d d
 l m Z d d l m Z m Z m Z d d l Z d d l  m! Z! d Z" d/ Z# d d0 d d „ Z$ y e% d d „  Z& Wn e' k
 r|d d „  Z& Yn Xd d „  Z( d d „  Z) e j* d e j+ ƒ Z, d d „  Z- d d „  Z. d d d d  d! d" „ Z/ d# d$ „  Z0 e0 d% d& „  ƒ Z1 d' d( „  Z2 d) d* „  Z3 Gd+ d, „  d, e4 ƒ Z5 Gd- d. „  d. e4 ƒ Z6 d S)1zH
Support for installing and building the "wheel" binary package format.
é    )Úwith_statementN)Úurlsafe_b64encode)ÚParser)ÚConfigParserÚStringIO)ÚInvalidWheelFilenameÚUnsupportedWheel)Údistutils_scheme)Úlogger)Ú
pep425tags)Úcall_subprocessÚnormalize_pathÚmake_path_relative)ÚScriptMakerz.whlé   Úsha256é   c          
   C   s§   t  j | ƒ } d } t |  d ƒ �O } | j | ƒ } x6 | rn | t | ƒ 7} | j | ƒ | j | ƒ } q9 WWd QXd t | j ƒ  ƒ j d ƒ j	 d ƒ } | | f S)z6Return (hash, length) for path using hashlib.new(algo)r   ÚrbNzsha256=Úlatin1ú=)
ÚhashlibÚnewÚopenÚreadÚlenÚupdater   ÚdigestÚdecodeÚrstrip)ÚpathÚalgoÚ	blocksizeÚhÚlengthÚfÚblockr   © r&   ú8/var/www/pythonscrapper/code/venv/build/pip/pip/wheel.pyÚrehash!   s    	(r(   c             C   s    t  |  t ƒ r |  j d ƒ S|  S)NÚascii)Ú
isinstanceÚunicodeÚencode)Úsr&   r&   r'   Úbinary0   s    r.   c             C   s    t  |  t ƒ r |  j d ƒ Sd  S)Nr)   )r*   Ústrr,   )r-   r&   r&   r'   r.   5   s    c             C   sI   t  j d d k  r" i  } d } n i d d 6} d } t |  | | | � S)Nr   é   ÚbÚ Únewline)ÚsysÚversion_infor   )ÚnameÚmodeÚnlÚbinr&   r&   r'   Úopen_for_csv9   s    	r:   c             C   sÜ   t  j j |  ƒ rØ t |  d ƒ } zj | j ƒ  } | j t d ƒ ƒ sI d St j j	 t j
 ƒ  ƒ } t d ƒ | t t  j ƒ } | j ƒ  } Wd | j ƒ  Xt |  d ƒ } z | j | ƒ | j | ƒ Wd | j ƒ  Xd Sd S)zLReplace #!python with #!/path/to/python
    Return True if file was changed.r   z#!pythonFz#!NÚwbT)Úosr   Úisfiler   ÚreadlineÚ
startswithr.   r4   Ú
executabler,   ÚgetfilesystemencodingÚlinesepr   ÚcloseÚwrite)r   ÚscriptÚ	firstlineÚexenameÚrestr&   r&   r'   Ú
fix_scriptB   s     rI   zZ^(?P<namever>(?P<name>.+?)(-(?P<ver>\d.+?))?)
                                \.dist-info$c             C   s·   |  j  d d ƒ } xž t j | ƒ D]� } t j | ƒ } | r" | j d ƒ | k r" t t j j | | d ƒ ƒ �: } x0 | D]( } | j	 ƒ  j
 ƒ  } | d k rz d Sqz WWd QXq" q" Wd S)	zP
    Return True if the extracted wheel in wheeldir should go into purelib.
    ú-Ú_r6   ÚWHEELzroot-is-purelib: trueTNF)Úreplacer<   ÚlistdirÚdist_info_reÚmatchÚgroupr   r   ÚjoinÚlowerr   )r6   ÚwheeldirÚname_foldedÚitemrP   ÚwheelÚliner&   r&   r'   Úroot_is_purelib\   s    !rY   c          
   C   sõ   t  j j |  ƒ s i  i  f St |  ƒ �N } t ƒ  } x. | D]& } | j | j ƒ  ƒ | j d ƒ q; W| j d ƒ Wd  QXt j	 ƒ  } | j
 | ƒ i  } i  } | j d ƒ rÄ t | j d ƒ ƒ } n  | j d ƒ rë t | j d ƒ ƒ } n  | | f S)NÚ
r   Úconsole_scriptsÚgui_scripts)r<   r   Úexistsr   r   rD   ÚstripÚseekr   ÚRawConfigParserÚreadfpÚhas_sectionÚdictÚitems)ÚfilenameÚfpÚdatarX   ÚcpÚconsoleÚguir&   r&   r'   Úget_entrypointsl   s"    
	rk   FTc       #         sà  t  |  d | d | d | ƒ} t |  ˆ ƒ r: | d ‰ n
 | d ‰ g  ‰ g  ‰ ˆ j t j j ƒ t j j } i  ‰ t ƒ  ‰  g  }	 | r¦ t j | d d d d ƒn  d	 d
 „  ‰ d ‡  ‡ ‡ ‡ ‡ f d d † ‰	 d d ‡ ‡ ‡	 ‡
 f d d † }
 |
 | ˆ d ƒ ˆ st	 d ˆ
 ƒ ‚ t j j
 ˆ d d ƒ } t | ƒ \ ‰ ‰ ‡ ‡ f d d †  } x¢ ˆ D]š } d } d } x… t j t j j
 ˆ | ƒ ƒ D]e } d } | d k r¹t } | } n  t j j
 ˆ | | ƒ } | | } |
 | | d d | d | ƒq’WqaWt d | d ƒ ‰ t d2 ƒ ˆ _ d ˆ _ ‡ f d d †  } | ˆ _ d ˆ _ ˆ j d d ƒ } | rJd t j k r˜d | } |	 j ˆ j | ƒ ƒ n  t j j d d ƒ d  k réd! t j d d" … | f } |	 j ˆ j | ƒ ƒ n  d! t j d d# … | f } |	 j ˆ j | ƒ ƒ d$ d% „  ˆ Dƒ } x | D] } ˆ | =q6Wn  ˆ j d& d ƒ } | rõd t j k r”d' | } |	 j ˆ j | ƒ ƒ n  d( t j d d# … | f } |	 j ˆ j | ƒ ƒ d) d% „  ˆ Dƒ } x | D] } ˆ | =qáWn  t ˆ ƒ d k r3|	 j ˆ j d* d% „  ˆ j ƒ  Dƒ ƒ ƒ n  t ˆ ƒ d k r{|	 j ˆ j d+ d% „  ˆ j ƒ  Dƒ i d d, 6ƒ ƒ n  t j j
 ˆ d d- ƒ } t j j
 ˆ d d. ƒ } t | d/ ƒ �} t | d0 ƒ �ö } t j | ƒ } t j  | ƒ } xj | D]b } ˆ j | d | d ƒ | d <| d ˆ  k rKt! | d ƒ \ | d" <| d1 <n  | j" | ƒ qöWx6 |	 D]. }  t! |  ƒ \ }! }" | j" |  |! |" f ƒ qcWx( ˆ D]  }  | j" ˆ |  d d f ƒ qœWWd QXWd QXt# j$ | | ƒ d S)3zInstall a wheelÚuserÚhomeÚrootÚpurelibÚplatlibÚforceTÚquietc             S   s   t  |  | ƒ j t j j d ƒ S)Nú/)r   rM   r<   r   Úsep)ÚsrcÚpr&   r&   r'   Únormpath¢   s    z"move_wheel_files.<locals>.normpathFc                sB   ˆ |  ˆ ƒ } ˆ | ˆ ƒ } | ˆ | <| r> ˆ  j  | ƒ n  d S)z6Map archive RECORD paths to installation RECORD paths.N)Úadd)ÚsrcfileÚdestfileÚmodifiedÚoldpathÚnewpath)ÚchangedÚ	installedÚlib_dirrw   rT   r&   r'   Úrecord_installed¥   s
    
z*move_wheel_files.<locals>.record_installedNc                s  t  j j | ƒ s" t  j | ƒ n  xèt  j |  ƒ D]×\ } } } | t |  ƒ d  … j t  j j ƒ } | r— | j t  j j d ƒ d j	 d ƒ r— q2 n  xÞ | D]Ö }	 t  j j
 | | |	 ƒ }
 | rð | d k rð |
 j	 d ƒ rð ˆ  j |	 ƒ qž nb | rR|	 j	 d ƒ rR|	 j ƒ  j ˆ j j d d ƒ j ƒ  ƒ rRˆ sBt d ƒ ‚ ˆ j |
 ƒ n  t  j j |
 ƒ sž t  j |
 ƒ qž qž WxŽ | D]† } | r�| | ƒ r�qn  t  j j
 | | ƒ } t  j j
 | | | ƒ } t j | | ƒ d	 } | rõ| | ƒ } n  ˆ | | | ƒ qWq2 Wd  S)
Nr   r   z.datar2   z
.dist-inforJ   rK   zMultiple .dist-info directoriesF)r<   r   r]   ÚmakedirsÚwalkr   Úlstriprt   ÚsplitÚendswithrR   ÚappendrS   r?   Úproject_namerM   ÚAssertionErrorÚshutilÚmove)ÚsourceÚdestÚis_baseÚfixerÚfilterÚdirÚsubdirsÚfilesÚbasedirr-   Ú
destsubdirr$   ry   rz   r~   )Ú	data_dirsÚinfo_dirr�   Úreqr&   r'   Úclobber­   s8    %+!*z!move_wheel_files.<locals>.clobberz!%s .dist-info directory not foundr   zentry_points.txtc                s”   |  j  ƒ  j d ƒ r( |  d  d … } nV |  j  ƒ  j d ƒ rP |  d  d … } n. |  j  ƒ  j d ƒ rx |  d  d … } n |  } | ˆ  k p“ | ˆ k S)	Nz.exeé   z
-script.pyé
   z.pyaéüÿÿÿiöÿÿÿrœ   )rS   r†   )r6   Ú	matchname)ri   rj   r&   r'   Úis_entrypoint_wrapperÖ   s    z/move_wheel_files.<locals>.is_entrypoint_wrapperÚscriptsr�   r�   r2   c                s6   ˆ  j  i |  j d 6|  j j d ƒ d d 6|  j d 6S)NÚmoduleÚ.r   Úimport_nameÚfunc)Úscript_templateÚprefixÚsuffixr…   )Úentry)Úmakerr&   r'   Ú_get_script_text   s    	
z*move_wheel_files.<locals>._get_script_textzÏ# -*- coding: utf-8 -*-
import re
import sys

from %(module)s import %(import_name)s

if __name__ == '__main__':
    sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
    sys.exit(%(func)s())
ÚpipÚENSUREPIP_OPTIONSzpip = Ú
altinstallz
pip%s = %sr   r0   c             S   s(   g  |  ] } t  j d  | ƒ r | ‘ q S)zpip(\d(\.\d)?)?$)ÚrerP   )Ú.0Úkr&   r&   r'   ú
<listcomp>A  s   	 z$move_wheel_files.<locals>.<listcomp>Úeasy_installzeasy_install = zeasy_install-%s = %sc             S   s(   g  |  ] } t  j d  | ƒ r | ‘ q S)zeasy_install(-\d\.\d)?$)r­   rP   )r®   r¯   r&   r&   r'   r°   M  s   	 c             S   s   g  |  ] } d  | ‘ q S)z%s = %sr&   )r®   Úkvr&   r&   r'   r°   T  s   	 c             S   s   g  |  ] } d  | ‘ q S)z%s = %sr&   )r®   r²   r&   r&   r'   r°   V  s   	 rj   ÚRECORDz
RECORD.pipÚrzw+é   )r2   )%r	   rY   r   r<   r   rt   ÚsetÚ
compileallÚcompile_dirr‰   rR   rk   rN   rI   r   ÚvariantsÚset_moder©   r¤   ÚpopÚenvironÚextendÚmakeÚgetr4   Úversionr   Úmake_multiplerd   r:   ÚcsvÚreaderÚwriterr(   ÚwriterowrŠ   r‹   )#r6   r˜   rT   rl   rm   rn   Ú	pycompileÚschemerŒ   Ú	generatedr™   Úep_filerž   Údatadirr�   r�   Úsubdirr�   r©   Ú
pip_scriptÚspecÚpip_epr¯   Úeasy_install_scriptÚeasy_install_epÚrecordÚtemp_recordÚ	record_inÚ
record_outrÃ   rÄ   Úrowr$   r"   Úlr&   )r~   ri   r–   rj   r—   r   r€   r¨   rw   r�   r˜   rT   r'   Úmove_wheel_files‡   s¢    
	!!!%	
$		
	#

,6!*r×   c                s%   t  j ˆ  ƒ ‡  f d d †  ƒ } | S)Nc              ?   sH   t  ƒ  } x8 ˆ  |  | Ž  D]' } | | k r | j | ƒ | Vq q Wd  S)N)r¶   rx   )ÚargsÚkwÚseenrV   )Úfnr&   r'   Úuniquek  s
    	z_unique.<locals>.unique)Ú	functoolsÚwraps)rÛ   rÜ   r&   )rÛ   r'   Ú_uniquej  s    !rß   c             c   s¼   d d l  m } t j | |  j d ƒ ƒ ƒ } x‡ | D] } t j j |  j | d ƒ } | V| j	 d ƒ r5 t j j
 | ƒ \ } } | d d … } t j j | | d ƒ } | Vq5 q5 Wd S)	a  
    Yield all the uninstallation paths for dist based on RECORD-without-.pyc

    Yield paths to all the files in RECORD. For each .py file in RECORD, add
    the .pyc in the same directory.

    UninstallPathSet.add() takes care of the __pycache__ .pyc.
    r   )ÚFakeFiler³   z.pyNr0   z.pycéýÿÿÿ)Úpip.reqrà   rÂ   rÃ   Úget_metadata_linesr<   r   rR   Úlocationr†   r…   )Údistrà   r´   rÕ   r   ÚdnrÛ   Úbaser&   r&   r'   Úuninstallation_pathsu  s    
rè   c             C   s�   yz d d „  t  j d |  ƒ Dƒ d } | j d ƒ } t ƒ  j | ƒ } | d j ƒ  } t t t | j	 d ƒ ƒ ƒ } | SWn d SYn Xd S)	z†
    Return the Wheel-Version of an extracted wheel, if possible.

    Otherwise, return False if we couldn't parse / extract it.
    c             S   s   g  |  ] } | ‘ q Sr&   r&   )r®   Údr&   r&   r'   r°   ’  s   	 z!wheel_version.<locals>.<listcomp>Nr   rL   zWheel-Versionr¡   F)
Úpkg_resourcesÚfind_on_pathÚget_metadatar   Úparsestrr^   ÚtupleÚmapÚintr…   )Ú
source_dirrå   Ú
wheel_datarÀ   r&   r&   r'   Úwheel_version‹  s    #ró   c             C   sŽ   |  s t  d | ƒ ‚ n  |  d t d k rX t  d | d j t t |  ƒ ƒ f ƒ ‚ n2 |  t k rŠ t j d d j t t |  ƒ ƒ ƒ n  d S)aê  
    Raises errors or warns if called with an incompatible Wheel-Version.

    Pip should refuse to install a Wheel-Version that's a major series
    ahead of what it's compatible with (e.g 2.0 > 1.1); and warn when
    installing a version only minor version ahead (e.g 1.2 > 1.1).

    version: a 2-tuple representing a Wheel-Version (Major, Minor)
    name: name of wheel or package to raise exception about

    :raises UnsupportedWheel: when an incompatible Wheel-Version is given
    z(%s is in an unsupported or invalid wheelr   zB%s's Wheel-Version (%s) is not compatible with this version of pipr¡   z*Installing from a newer Wheel-Version (%s)N)r   ÚVERSION_COMPATIBLErR   rï   r/   r
   Úwarn)rÀ   r6   r&   r&   r'   Úcheck_compatibilityž  s    %	rö   c               @   sU   e  Z d  Z d Z e j d e j ƒ Z d d „  Z d d d „ Z	 d d d	 „ Z
 d S)
ÚWheelzA wheel filezž^(?P<namever>(?P<name>.+?)-(?P<ver>\d.*?))
                ((-(?P<build>\d.*?))?-(?P<pyver>.+?)-(?P<abi>.+?)-(?P<plat>.+?)
                \.whl|\.dist-info)$c                sê   ˆ  j  j | ƒ } | s+ t d | ƒ ‚ n  | ˆ  _ | j d ƒ j d d ƒ ˆ  _ | j d ƒ j d d ƒ ˆ  _ | j d ƒ j d ƒ ˆ  _	 | j d ƒ j d ƒ ˆ  _
 | j d	 ƒ j d ƒ ˆ  _ t ‡  f d
 d †  ˆ  j	 Dƒ ƒ ˆ  _ d S)zX
        :raises InvalidWheelFilename: when the filename is invalid for a wheel
        z!%s is not a valid wheel filename.r6   rK   rJ   ÚverÚpyverr¡   ÚabiÚplatc             3   s>   |  ]4 } ˆ  j  D]$ } ˆ  j D] } | | | f Vq q q d  S)N)ÚabisÚplats)r®   ÚxÚyÚz)Úselfr&   r'   ú	<genexpr>Õ  s    z!Wheel.__init__.<locals>.<genexpr>N)Úwheel_file_rerP   r   re   rQ   rM   r6   rÀ   r…   Ú
pyversionsrü   rý   r¶   Ú	file_tags)r  re   Ú
wheel_infor&   )r  r'   Ú__init__Ä  s    	zWheel.__init__Nc                sH   ˆ  d k r t  j ‰  n  ‡  f d d †  |  j Dƒ } | rD t | ƒ Sd S)a"  
        Return the lowest index that one of the wheel's file_tag combinations
        achieves in the supported_tags list e.g. if there are 8 supported tags,
        and one of the file tags is first in the list, then return 0.  Returns
        None is the wheel is not supported.
        Nc                s+   g  |  ]! } | ˆ  k r ˆ  j  | ƒ ‘ q Sr&   )Úindex)r®   Úc)Útagsr&   r'   r°   á  s   	 z+Wheel.support_index_min.<locals>.<listcomp>)r   Úsupported_tagsr  Úmin)r  r
  Úindexesr&   )r
  r'   Úsupport_index_minØ  s    zWheel.support_index_minc             C   s4   | d k r t  j } n  t t | ƒ j |  j ƒ ƒ S)z'Is this wheel supported on this system?N)r   r  Úboolr¶   Úintersectionr  )r  r
  r&   r&   r'   Ú	supportedä  s    zWheel.supported)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r­   ÚcompileÚVERBOSEr  r  r  r  r&   r&   r&   r'   r÷   ¹  s   r÷   c               @   s@   e  Z d  Z d Z g  g  d d „ Z d d „  Z d d „  Z d S)	ÚWheelBuilderz#Build wheels from a RequirementSet.c             C   s7   | |  _  | |  _ t | ƒ |  _ | |  _ | |  _ d  S)N)Úrequirement_setÚfinderr   Ú	wheel_dirÚbuild_optionsÚglobal_options)r  r  r  r  r  r  r&   r&   r'   r  î  s
    			zWheelBuilder.__init__c             C   s³   t  j d d | j g t |  j ƒ } t j d | j ƒ t j d |  j ƒ | d d |  j g |  j	 } y! t
 | d | j d d	 ƒd
 SWn  t j d | j ƒ d	 SYn Xd S)zBuild one wheel.z-czjimport setuptools;__file__=%r;exec(compile(open(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))z#Running setup.py bdist_wheel for %szDestination directory: %sÚbdist_wheelz-dÚcwdÚshow_stdoutFTzFailed building wheel for %sN)r4   r@   Úsetup_pyÚlistr  r
   Únotifyr6   r  r  r   rñ   Úerror)r  r˜   Ú	base_argsÚ
wheel_argsr&   r&   r'   Ú
_build_oneõ  s    	
zWheelBuilder._build_onec             C   s5  |  j  j |  j ƒ |  j  j j ƒ  } d d „  | Dƒ } | sB d St j d d j d d „  | Dƒ ƒ ƒ t j d 7_ g  g  } } x: | D]2 } |  j	 | ƒ r± | j
 | ƒ qŒ | j
 | ƒ qŒ Wt j d 8_ | rt j d d	 j d
 d „  | Dƒ ƒ ƒ n  | r1t j d d	 j d d „  | Dƒ ƒ ƒ n  d S)zBuild wheels.c             S   s   g  |  ] } | j  s | ‘ q Sr&   )Úis_wheel)r®   r˜   r&   r&   r'   r°     s   	 z&WheelBuilder.build.<locals>.<listcomp>Nz*Building wheels for collected packages: %sú,c             S   s   g  |  ] } | j  ‘ q Sr&   )r6   )r®   r˜   r&   r&   r'   r°     s   	 rµ   zSuccessfully built %sú c             S   s   g  |  ] } | j  ‘ q Sr&   )r6   )r®   r˜   r&   r&   r'   r°   %  s   	 zFailed to build %sc             S   s   g  |  ] } | j  ‘ q Sr&   )r6   )r®   r˜   r&   r&   r'   r°   '  s   	 )r  Úprepare_filesr  ÚrequirementsÚvaluesr
   r#  rR   Úindentr'  r‡   )r  ÚreqsetÚbuildsetÚbuild_successÚbuild_failurer˜   r&   r&   r'   Úbuild  s&    *zWheelBuilder.buildN)r  r  r  r  r  r'  r3  r&   r&   r&   r'   r  ë  s   r  )r   r   i   )7r  Ú
__future__r   r·   rÂ   rÝ   r   r<   r­   rŠ   r4   Úbase64r   Úemail.parserr   Zpip.backwardcompatr   r   Úpip.exceptionsr   r   Úpip.locationsr	   Úpip.logr
   rª   r   Úpip.utilr   r   r   rê   Údistlib.scriptsr   Ú	wheel_extrô   r(   r+   r.   Ú	NameErrorr:   rI   r  r  rO   rY   rk   r×   rß   rè   ró   rö   Úobjectr÷   r  r&   r&   r&   r'   Ú<module>   sR   		â2