3
ûâdeL-  ã               @   sÄ   d dl Z d dlZd dlZd dlmZmZmZ d dlmZm	Z	m
Z
mZmZ d dlmZmZ d dlmZmZmZmZmZ e jeƒZejdƒZejdƒZejdƒZejd	ƒZG d
d„ deƒZejeƒ dS )é    N)ÚListÚOptionalÚTuple)Ú
HiddenTextÚdisplay_pathÚis_console_interactiveÚis_installable_dirÚsplit_auth_from_netloc)ÚCommandArgsÚmake_command)ÚAuthInfoÚRemoteNotFoundErrorÚ
RevOptionsÚVersionControlÚvcszurl="([^"]+)"zcommitted-rev="(\d+)"z\s*revision="(\d+)"z<url>(.*)</url>c            	       s°  e Zd ZdZdZdZd5Zeee	d	œd
d„ƒZ
eeee dœdd„ƒZeeedœdd„ƒZeeeeeeee ee f f dœ‡ fdd„ƒZeeeeee ef dœ‡ fdd„ƒZeee ee edœdd„ƒZeeedœdd„ƒZeeeee ef dœdd„ƒZeeee e	dœd d!„ƒZd6e	d"d#œ‡ fd$d%„Zeed&f d'œd(d)„Zeed&f d'œd*d+„Zed'œd,d-„Zeeed"d.œd/d0„Z eeed"d.œd1d2„Z!eeed"d.œd3d4„Z"‡  Z#S )7Ú
SubversionÚsvnz.svnÚcheckoutúsvn+sshúsvn+httpú	svn+httpsúsvn+svnúsvn+file)Ú
remote_urlÚreturnc             C   s   dS )NT© )Úclsr   r   r   ú;/tmp/pip-build-red6nood/pip/pip/_internal/vcs/subversion.pyÚshould_add_vcs_url_prefix$   s    z$Subversion.should_add_vcs_url_prefix)Úrevr   c             C   s   d| gS )Nz-rr   )r   r   r   r   Úget_base_rev_args(   s    zSubversion.get_base_rev_args)Úlocationr   c       	      C   sÀ   d}x²t j|ƒD ]¤\}}}| j|kr2g |dd…< q|j| jƒ t jj|| jdƒ}t jj|ƒs^q| j|ƒ\}}||krŠ|dk	s€t‚|d }n | sœ|j	|ƒ rªg |dd…< qt
||ƒ}qW t|ƒS )zR
        Return the maximum revision for all files under a given location
        r   NÚentriesú/)ÚosÚwalkÚdirnameÚremoveÚpathÚjoinÚexistsÚ_get_svn_url_revÚAssertionErrorÚ
startswithÚmaxÚstr)	r   r!   ÚrevisionÚbaseÚdirsÚ_Ú
entries_fnÚdirurlÚlocalrevr   r   r   Úget_revision,   s$    

zSubversion.get_revision)ÚnetlocÚschemer   c                s   |dkrt ƒ j||ƒS t|ƒS )z™
        This override allows the auth information to be passed to svn via the
        --username and --password options instead of via the URL.
        Ússh)ÚsuperÚget_netloc_and_authr	   )r   r8   r9   )Ú	__class__r   r   r<   I   s    zSubversion.get_netloc_and_auth)Úurlr   c                s.   t ƒ j|ƒ\}}}|jdƒr$d| }|||fS )Nzssh://zsvn+)r;   Úget_url_rev_and_authr-   )r   r>   r   Ú	user_pass)r=   r   r   r?   X   s    
zSubversion.get_url_rev_and_auth)ÚusernameÚpasswordr   c             C   s(   g }| r|d| g7 }|r$|d|g7 }|S )Nz
--usernamez
--passwordr   )rA   rB   Ú
extra_argsr   r   r   Úmake_rev_args`   s    zSubversion.make_rev_argsc             C   sX   |}x4t |ƒs8|}tjj|ƒ}||krtjd|ƒ t‚qW | j|ƒ\}}|d krTt‚|S )NzMCould not find Python project for directory %s (tried all parent directories))r   r$   r(   r&   ÚloggerÚwarningr   r+   )r   r!   Úorig_locationÚlast_locationr>   Z_revr   r   r   Úget_remote_urll   s    
zSubversion.get_remote_urlc             C   sŠ  ddl m} tjj|| jdƒ}tjj|ƒrHt|ƒ�}|jƒ }W d Q R X nd}d }|j	dƒsn|j	dƒsn|j	dƒr°t
ttj|jdƒƒƒ}|d d= |d d	 }d
d„ |D ƒdg }n¾|j	dƒrütj|ƒ}	|	sÖtd|›�ƒ‚|	jdƒ}dd„ tj|ƒD ƒdg }nryP| jdd|gddd�}
tj|
ƒ}	|	d k	�s,t‚|	jdƒ}dd„ tj|
ƒD ƒ}W n  |k
�rl   d g  }}Y nX |�r~t|ƒ}nd}||fS )Nr   )ÚInstallationErrorr"   Ú Ú8Ú9Ú10z

é   c             S   s,   g | ]$}t |ƒd kr|d  rt|d  ƒ‘qS )é	   )ÚlenÚint)Ú.0Údr   r   r   ú
<listcomp>”   s    z/Subversion._get_svn_url_rev.<locals>.<listcomp>z<?xmlzBadly formatted data: é   c             S   s   g | ]}t |jd ƒƒ‘qS )rV   )rR   Úgroup)rS   Úmr   r   r   rU   š   s    Úinfoz--xmlFT)Úshow_stdoutÚstdout_onlyc             S   s   g | ]}t |jd ƒƒ‘qS )rV   )rR   rW   )rS   rX   r   r   r   rU   «   s    )Zpip._internal.exceptionsrJ   r$   r(   r)   r&   r*   ÚopenÚreadr-   ÚlistÚmapr/   Ú
splitlinesÚsplitÚ_svn_xml_url_reÚsearchÚ
ValueErrorrW   Ú_svn_rev_reÚfinditerÚrun_commandÚ_svn_info_xml_url_rer,   Ú_svn_info_xml_rev_rer.   )r   r!   rJ   Úentries_pathÚfÚdatar>   r"   ÚrevsÚmatchÚxmlr   r   r   r   r+   „   sB    







zSubversion._get_svn_url_rev)ÚdestÚnamer   c             C   s   dS )z&Always assume the versions don't matchFr   )r   rp   rq   r   r   r   Úis_commit_id_equal¶   s    zSubversion.is_commit_id_equalN)Úuse_interactiver   c                s(   |d krt ƒ }|| _d | _tƒ jƒ  d S )N)r   rs   Ú_vcs_versionr;   Ú__init__)Úselfrs   )r=   r   r   ru   »   s
    zSubversion.__init__.)r   c             C   s|   d}| j dgddd�}|j|ƒs$f S |t|ƒd… jƒ d }|jdƒd jd	ƒ}yttt|ƒƒ}W n tk
rv   f S X |S )
a  Query the version of the currently installed Subversion client.

        :return: A tuple containing the parts of the version information or
            ``()`` if the version returned from ``svn`` could not be parsed.
        :raises: BadCommand: If ``svn`` is not installed.
        zsvn, version z	--versionFT)rZ   r[   Nr   ú-Ú.)	rg   r-   rQ   ra   Ú	partitionÚtupler_   rR   rd   )rv   Zversion_prefixÚversionZversion_listÚparsed_versionr   r   r   Úcall_vcs_versionÉ   s    
zSubversion.call_vcs_versionc             C   s"   | j dk	r| j S | jƒ }|| _ |S )a�  Return the version of the currently installed Subversion client.

        If the version of the Subversion client has already been queried,
        a cached value will be used.

        :return: A tuple containing the parts of the version information or
            ``()`` if the version returned from ``svn`` could not be parsed.
        :raises: BadCommand: If ``svn`` is not installed.
        N)rt   r}   )rv   Zvcs_versionr   r   r   Úget_vcs_versionå   s
    

zSubversion.get_vcs_versionc             C   s&   | j sdgS | jƒ }|dkr"dgS g S )aC  Return options to be used on calls to Subversion that contact the server.

        These options are applicable for the following ``svn`` subcommands used
        in this class.

            - checkout
            - switch
            - update

        :return: A list of command line arguments to pass to ``svn``.
        z--non-interactiverV   é   z--force-interactive)rV   r   )rs   r~   )rv   Zsvn_versionr   r   r   Úget_remote_call_optionsù   s    	z"Subversion.get_remote_call_options)rp   r>   Úrev_optionsr   c             C   sD   |j ƒ }tjd||t|ƒƒ tdd| jƒ |jƒ ||ƒ}| j|ƒ d S )NzChecking out %s%s to %sr   z-q)Z
to_displayrE   rY   r   r   r€   Úto_argsrg   )rv   rp   r>   r�   Úrev_displayÚcmd_argsr   r   r   Ú	fetch_new  s    
zSubversion.fetch_newc             C   s&   t d| jƒ |jƒ ||ƒ}| j|ƒ d S )NÚswitch)r   r€   r‚   rg   )rv   rp   r>   r�   r„   r   r   r   r†   *  s    zSubversion.switchc             C   s$   t d| jƒ |jƒ |ƒ}| j|ƒ d S )NÚupdate)r   r€   r‚   rg   )rv   rp   r>   r�   r„   r   r   r   r‡   4  s    zSubversion.update)r   r   r   r   r   )N)$Ú__name__Ú
__module__Ú__qualname__rq   r&   Ú	repo_nameÚschemesÚclassmethodr/   Úboolr   Ústaticmethodr   r    r7   r   r   r<   r   r?   r   r
   rD   rI   rR   r+   rr   ru   r}   r~   r€   r   r…   r†   r‡   Ú__classcell__r   r   )r=   r   r      s>   ,$	1
r   ) Úloggingr$   ÚreÚtypingr   r   r   Zpip._internal.utils.miscr   r   r   r   r	   Zpip._internal.utils.subprocessr
   r   Z pip._internal.vcs.versioncontrolr   r   r   r   r   Ú	getLoggerrˆ   rE   Úcompilerb   re   ri   rh   r   Úregisterr   r   r   r   Ú<module>   s   




  "