a
    eÖ0h1  ã                   @   sü   d dl mZ d dlZd dlZd dlZd dlmZ d dlmZm	Z	m
Z
mZ d dlmZ d dlmZ d dlmZmZ e d¡Ze d	¡Ze d
¡Ze d¡ZerÔd dlmZmZ d dlmZ d dlmZ d dlmZmZ e e ¡Z!G dd„ deƒZ"e #e"¡ dS )é    )Úabsolute_importN)Ú
indent_log)Údisplay_pathÚis_console_interactiveÚrmtreeÚsplit_auth_from_netloc)Úmake_command)ÚMYPY_CHECK_RUNNING)ÚVersionControlÚvcszurl="([^"]+)"zcommitted-rev="(\d+)"z\s*revision="(\d+)"z<url>(.*)</url>)ÚOptionalÚTuple)Ú
HiddenText)ÚCommandArgs)ÚAuthInfoÚ
RevOptionsc                       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d&d'„ Z‡  ZS ))Ú
SubversionÚsvnz.svnÚcheckout)r   zsvn+sshzsvn+httpz	svn+httpszsvn+svnc                 C   s   dS )NT© )ÚclsÚ
remote_urlr   r   úJ/var/www/auris/lib/python3.9/site-packages/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_args0   s    zSubversion.get_base_rev_argsc           	      C   s¨   d}t  |¡D ]”\}}}| j|vr0g |dd…< q| | j¡ t j || jd¡}t j |¡s\q|  |¡\}}||kr||d }n|rŠ| |¡s˜g |dd…< qt	||ƒ}q|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Ú
startswithÚmax)	r   ÚlocationÚrevisionÚbaseÚdirsÚ_Ú
entries_fnÚdirurlÚlocalrevr   r   r   Úget_revision4   s"    

zSubversion.get_revisionc                    s"   |dkrt 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)Úsuperr   Úget_netloc_and_authr   )r   ÚnetlocÚscheme©Ú	__class__r   r   r3   P   s    zSubversion.get_netloc_and_authc                    s2   t t| ƒ |¡\}}}| d¡r(d| }|||fS )Nzssh://zsvn+)r2   r   Úget_url_rev_and_authr&   )r   Úurlr   Ú	user_passr6   r   r   r8   ]   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_argsf   s    zSubversion.make_rev_argsc                 C   sR   |}t j t j |d¡¡sD|}t j |¡}||krt d|¡ d S q|  |¡d S )Nzsetup.pyzGCould not find setup.py for directory %s (tried all parent directories)r   )r   r"   r$   r#   r    ÚloggerÚwarningr%   )r   r(   Úorig_locationÚlast_locationr   r   r   Úget_remote_urlq   s    ýzSubversion.get_remote_urlc                 C   s  ddl m} tj || jd¡}tj |¡r\t|ƒ}| ¡ }W d   ƒ q`1 sP0    Y  nd}| 	d¡s~| 	d¡s~| 	d¡rÀt
ttj| d¡ƒƒ}|d d= |d d	 }d
d„ |D ƒdg }n´| 	d¡rt |¡}|sðtdjf i tƒ ¤Žƒ‚| d¡}dd„ t |¡D ƒdg }n^z>| jdd|gddd}	t |	¡ d¡}dd„ t |	¡D ƒ}W n |yr   d g  }}Y n0 |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>—   ó    z/Subversion._get_svn_url_rev.<locals>.<listcomp>z<?xmlzBadly formatted data: {data!r}é   c                 S   s   g | ]}t | d ¡ƒ‘qS ©rQ   ©rL   Úgroup©rM   Úmr   r   r   rO   ž   rP   Úinfoz--xmlFT©Úshow_stdoutÚstdout_onlyc                 S   s   g | ]}t | d ¡ƒ‘qS rR   rS   rU   r   r   r   rO   ­   s   )Úpip._internal.exceptionsrD   r   r"   r#   r    r$   ÚopenÚreadr&   ÚlistÚmapÚstrÚ
splitlinesÚsplitÚ_svn_xml_url_reÚsearchÚ
ValueErrorÚformatÚlocalsrT   Ú_svn_rev_reÚfinditerÚrun_commandÚ_svn_info_xml_url_reÚ_svn_info_xml_rev_rer'   )r   r(   rD   Úentries_pathÚfÚdatar9   ÚrevsÚmatchÚxmlr   r   r   r   r%   †   sN    
(
ÿþ

ÿ
ýÿ

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 u rt ƒ }|| _d | _tt| ƒ ¡  d S )N)r   Úuse_interactiveÚ_vcs_versionr2   r   Ú__init__)Úselfrv   r6   r   r   rx   ¿   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yv   Y dS 0 |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   ú-Ú.)	rj   r&   rK   rb   Ú	partitionÚtupler_   rL   re   )ry   Úversion_prefixÚversionÚversion_listÚparsed_versionr   r   r   Úcall_vcs_versionÎ   s    ÿ
zSubversion.call_vcs_versionc                 C   s"   | j du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)rw   r‚   )ry   Ú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 )aX  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
            - export
            - switch
            - update

        :return: A list of command line arguments to pass to ``svn``.
        z--non-interactive)rQ   é   z--force-interactive)rv   r„   )ry   Úsvn_versionr   r   r   Úget_remote_call_options  s    	z"Subversion.get_remote_call_optionsc                 C   s€   |   |¡\}}t d||¡ tƒ J tj |¡r8t|ƒ td|  	¡ | 
¡ ||ƒ}| j|dd W d  ƒ n1 sr0    Y  dS )z@Export the svn repository at the url to the destination locationz!Exporting svn repository %s to %sÚexportF)rY   N)Úget_url_rev_optionsr?   rW   r   r   r"   r$   r   r   r‡   Úto_argsrj   )ry   r(   r9   Úrev_optionsÚcmd_argsr   r   r   rˆ   #  s    
þzSubversion.exportc                 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‡   rŠ   rj   )ry   rs   r9   r‹   Úrev_displayrŒ   r   r   r   Ú	fetch_new4  s    ü

þzSubversion.fetch_newc                 C   s&   t d|  ¡ | ¡ ||ƒ}|  |¡ d S )NÚswitch©r   r‡   rŠ   rj   ©ry   rs   r9   r‹   rŒ   r   r   r   r   C  s
    þzSubversion.switchc                 C   s$   t d|  ¡ | ¡ |ƒ}|  |¡ d S )NÚupdater‘   r’   r   r   r   r“   K  s
    þzSubversion.update)N)Ú__name__Ú
__module__Ú__qualname__rt   r    Ú	repo_nameÚschemesÚclassmethodr   Ústaticmethodr   r0   r3   r8   r>   rC   r%   ru   rx   r‚   r„   r‡   rˆ   r   r   r“   Ú__classcell__r   r   r6   r   r   &   s<   






3
!r   )$Ú
__future__r   Úloggingr   ÚreÚpip._internal.utils.loggingr   Úpip._internal.utils.miscr   r   r   r   Úpip._internal.utils.subprocessr   Úpip._internal.utils.typingr	   Ú pip._internal.vcs.versioncontrolr
   r   Úcompilerc   rh   rl   rk   Útypingr   r   r   r   r   r   Ú	getLoggerr”   r?   r   Úregisterr   r   r   r   Ú<module>   s,   




  0