U
    
HaZ.                     @   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 eZedZedZedZed	ZG d
d deZe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dZedd Ze	dd Z
ed	d
 Ze fddZe fddZe	dd Zedd Zedd Zedd Zd& fdd	Zdd Zdd Zdd Zd d! Zd"d# Zd$d% Z  ZS )'
Subversionsvnz.svncheckout)zsvn+sshzsvn+httpz	svn+httpszsvn+svnzsvn+filec                 C   s   dS )NT )cls
remote_urlr   r   @/tmp/pip-unpacked-wheel-tx790h60/pip/_internal/vcs/subversion.pyshould_add_vcs_url_prefix&   s    z$Subversion.should_add_vcs_url_prefixc                 C   s   d| gS )Nz-rr   )revr   r   r   get_base_rev_args+   s    zSubversion.get_base_rev_argsc           	      C   s   d}t |D ]\}}}| j|kr0g |dd< q|| j t j|| jd}t j|s\q| |\}}||kr|dk	s~t|d }n|r|	|sg |dd< qt
||}q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   locationrevisionbasedirs_
entries_fndirurllocalrevr   r   r   get_revision0   s$    

zSubversion.get_revisionc                    s   |dkrt  ||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   netlocscheme	__class__r   r   r4   N   s    zSubversion.get_netloc_and_authc                    s.   t  |\}}}|dr$d| }|||fS )Nzssh://zsvn+)r3   get_url_rev_and_authr&   )r   urlr   	user_passr7   r   r   r9   \   s    
zSubversion.get_url_rev_and_authc                 C   s(   g }| r|d| g7 }|r$|d|g7 }|S )Nz
--usernamez
--passwordr   )usernamepassword
extra_argsr   r   r   make_rev_argse   s    zSubversion.make_rev_argsc                 C   sT   |}t |s6|}tj|}||krtd| tq| |\}}|d krPt|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_urlp   s    zSubversion.get_remote_urlc              	   C   s  ddl m} tj|| jd}tj|rHt|}| }W 5 Q R X nd}d }|	dsn|	dsn|	drt
ttj|d}|d d= |d d	 }d
d |D dg }n|	drt|}	|	std||	d}dd t|D dg }nrzP| jdd|gddd}
t|
}	|	d k	s,t|	d}dd t|
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 |d qS rQ   rM   grouprN   mr   r   r   rP      s     infoz--xmlFTshow_stdoutZstdout_onlyc                 S   s   g | ]}t |d qS rR   rS   rU   r   r   r   rP      s    )pip._internal.exceptionsrE   r   r!   r"   r   r#   openreadr&   listmapr(   
splitlinessplit_svn_xml_url_research
ValueErrorrT   _svn_rev_refinditerrun_command_svn_info_xml_url_rer%   _svn_info_xml_rev_rer'   )r   r)   rE   entries_pathfdatar:   r   revsmatchxmlr   r   r   r   r$      sP    









zSubversion._get_svn_url_revc                 C   s   dS )z&Always assume the versions don't matchFr   )r   destnamer   r   r   is_commit_id_equal   s    zSubversion.is_commit_id_equalNc                    s(   |d krt  }|| _d | _t   d S )N)r   use_interactive_vcs_versionr3   __init__)selfrr   r7   r   r   rt      s
    zSubversion.__init__c                 C   s~   d}| j dgddd}||s$dS |t|d  d }|d	d d
}zttt|}W n tk
rx   Y d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	--versionFTrX   r   Nr   -.)	rf   r&   rL   r`   	partitiontupler^   rM   rc   )ru   version_prefixversionversion_listparsed_versionr   r   r   call_vcs_version   s      
zSubversion.call_vcs_versionc                 C   s"   | j dk	r| j S |  }|| _ |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)rs   r~   )ru   vcs_versionr   r   r   get_vcs_version   s
    
zSubversion.get_vcs_versionc                 C   s&   | j sdgS |  }|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-interactive)rQ      z--force-interactive)rr   r   )ru   svn_versionr   r   r   get_remote_call_options	  s    	z"Subversion.get_remote_call_optionsc                 C   sD   |  }td||t| tdd|  | ||}| | d S )NzChecking out %s%s to %sr   z-q)
to_displayr@   rW   r   r   r   to_argsrf   )ru   ro   r:   rev_optionsrev_displaycmd_argsr   r   r   	fetch_new)  s         zSubversion.fetch_newc                 C   s&   t d|  | ||}| | d S )Nswitchr   r   r   rf   ru   ro   r:   r   r   r   r   r   r   8  s       zSubversion.switchc                 C   s$   t d|  | |}| | d S )Nupdater   r   r   r   r   r   @  s      zSubversion.update)N)__name__
__module____qualname__rp   r   	repo_nameschemesclassmethodr   staticmethodr   r1   r4   r9   r?   rD   r$   rq   rt   r~   r   r   r   r   r   __classcell__r   r   r7   r   r      s:   






6
 r   ) loggingr   retypingr   r   r   pip._internal.utils.miscr   r   r   r   r	   pip._internal.utils.subprocessr
   r    pip._internal.vcs.versioncontrolr   r   r   r   r   	getLoggerr   r@   compilera   rd   rh   rg   r   registerr   r   r   r   <module>   s   




  -