B
    é¹`1«  ã               @   sÔ  d 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	 G dd„ dƒZ
G dd„ dƒZG dd	„ d	ƒZeƒ Zd
ZejdkrŽed7 Zed Zg fdd„Zdd„ Zefdd„Zdd„ ZG dd„ de	jƒZdd„ ZG dd„ deƒZdd„ Zd d¡Zejekre ej¡ ejdkZe  d ej!¡Z"d!d"„ Z#d<d$d%„Z$d&d'„ Z%G d(d)„ d)e&ƒZ'e  d*¡Z(G d+d,„ d,e	jƒZ)G d-d.„ d.ƒZ*G d/d0„ d0e*ƒZ+G d1d2„ d2ƒZ,d3d4„ Z-e  d5¡fd6d7„Z.g fd8d9„Z/G d:d;„ d;ƒZ0dS )=zm
svn-Command based Implementation of a Subversion WorkingCopy Path.

  SvnWCCommandPath  is the main class.

é    N)Úcommonc               @   s   e Zd Zi Zi Zi Zi ZdS )ÚcacheN)Ú__name__Ú
__module__Ú__qualname__ÚproplistÚinfoÚentriesÚprop© r   r   úV/home/kop/projects/devel/pgwui/test_venv/lib/python3.7/site-packages/py/_path/svnwc.pyr      s   r   c               @   s   e Zd Zdd„ Zdd„ ZdS )Ú	RepoEntryc             C   s   || _ || _|| _d S )N)ÚurlÚrevÚ	timestamp)Úselfr   r   r   r   r   r   Ú__init__   s    zRepoEntry.__init__c             C   s   d| j | j| jf S )Nzrepo: %s;%s  %s)r   r   r   )r   r   r   r   Ú__str__    s    zRepoEntry.__str__N)r   r   r   r   r   r   r   r   r   r      s   r   c               @   s6   e Zd ZdZdZdd„ Zdd„ Zddd	„Zd
d„ ZdS )Ú	RepoCachezž The Repocache manages discovered repository paths
    and their revisions.  If inside a timeout the cache
    will even return the revision of the root.
    é   c             C   s
   g | _ d S )N)Úrepos)r   r   r   r   r   *   s    zRepoCache.__init__c             C   s
   g | _ d S )N)r   )r   r   r   r   Úclear-   s    zRepoCache.clearNc             C   s`   |d krd S |d krt   ¡ }x>| jD ]}||jkr$||_||_P q$W t|||ƒ}| j |¡ d S )N)Útimer   r   r   r   r   Úappend)r   r   r   r   Úentryr   r   r   Úput0   s    
zRepoCache.putc             C   sR   t   ¡ }x@| jD ]6}| |j¡r||j| j k r<|j|jfS |jdfS qW |dfS )Néÿÿÿÿ)r   r   Ú
startswithr   r   Útimeoutr   )r   r   Únowr   r   r   r   ÚgetA   s    zRepoCache.get)N)	r   r   r   Ú__doc__r   r   r   r   r    r   r   r   r   r   #   s   
r   z_ -/\=$.~+%Úwin32ú:z@:c             C   sX   y| d S  t k
rR   tj d¡}| ¡  d | d¡d d… ¡}|  |¡ |S X d S )Nr   zsvn -q --versionÚ.é   )Ú
IndexErrorÚpyÚprocessÚcmdexecÚstripÚjoinÚsplitr   )ÚverÚvr   r   r   Ú_getsvnversionU   s    
r/   c             C   s&   t | ƒ} tjdkr"t | ƒ dd¡} | S )Nr"   ú$z\$)ÚstrÚsysÚplatformÚreplace)Útextr   r   r   Ú_escape_helper_   s    
r6   c             C   s,   x&t | ƒD ]}| ¡ rq
||kr"q
dS W dS )NTF)r1   Úisalnum)r5   Úallowed_charsÚcr   r   r   Ú_check_for_bad_charse   s    r:   c             C   sN   |   dd¡\}}|dkrJ|  dd¡\}}t|tƒs<t|tƒrJtd| f ƒ‚d S )Nz://é   Úfileú/zbad char in %r)r,   r:   ÚALLOWED_CHARS_HOSTÚALLOWED_CHARSÚ
ValueError)r   ÚprotoÚuriÚhostZuripathr   r   r   Úcheckbadcharsn   s    

rD   c               @   sœ   e Zd ZdZdZdd„ ZeedddƒZdd„ Zd	d
„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZG dd „ d ejƒZdS )!ÚSvnPathBasez2 Base implementation for SvnPath implementations. r=   c             C   s   | j S )N)Ústrpath)r   r   r   r   Ú_geturl   s    zSvnPathBase._geturlNzurl of this svn-path.c             C   s   | j S )z7 return a string representation (including rev-number) )rF   )r   r   r   r   r   ƒ   s    zSvnPathBase.__str__c             C   s
   t | jƒS )N)ÚhashrF   )r   r   r   r   Ú__hash__‡   s    zSvnPathBase.__hash__c             K   sÚ   t  | j¡}| d| j¡|_| d| j¡|_|  d¡\}}}}d|krdd|ksVd|kržtd| ƒ‚n:| d|¡}| d|¡}|r’| 	d¡s’d| }|| |d< | d	|¡ | d
| j
¡ |d rÌd| |_n
d| |_|S )aÈ   create a modified version of this path. A 'rev' argument
            indicates a new revision.
            the following keyword arguments modify various path parts::

              http://host.com/repo/path/file.ext
              |-----------------------|          dirname
                                        |------| basename
                                        |--|     purebasename
                                            |--| ext
        r   Úauthz!dirname,basename,purebasename,extÚbasenameÚpurebasenameÚextzinvalid specification %rr$   ÚdirnameÚsepz%(dirname)s%(sep)s%(basename)sz%(dirname)s)ÚobjectÚ__new__Ú	__class__r    r   rJ   Ú
_getbyspecr@   Ú
setdefaultr   rO   rF   )r   ÚkwÚobjrN   rK   rL   rM   Zpbr   r   r   ÚnewŠ   s&    
zSvnPathBase.newc       	      C   sâ   g }| j  | j¡}xÊ| d¡D ]¼}| ¡ }|dkrN| | j |dd… ¡¡ q|dkrf| |d ¡ q|d }| d¡}|dkrŒ|d }}n|d|… ||d…  }}|dkrº| |¡ q|d	krÎ| |¡ qtd
| ƒ‚qW |S )aø   get specified parts of the path.  'arg' is a string
            with comma separated path parts. The parts are returned
            in exactly the order of the specification.

            you may specify the following parts:

            http://host.com/repo/path/file.ext
            |-----------------------|          dirname
                                      |------| basename
                                      |--|     purebasename
                                          |--| ext
        ú,rN   Nr   rK   r$   Ú rL   rM   zDon't know part %r)rF   r,   rO   r*   r   r+   ÚrfindÚ	NameError)	r   ÚspecÚresÚpartsÚnamerK   ÚirL   rM   r   r   r   rS   ¬   s&    
zSvnPathBase._getbyspecc             C   s(   t | ƒt |ƒko&| j|jkp&| j|jkS )z3 return true if path and rev attributes each match )r1   r   )r   Úotherr   r   r   Ú__eq__Ð   s    zSvnPathBase.__eq__c             C   s
   | |k S )Nr   )r   ra   r   r   r   Ú__ne__Õ   s    zSvnPathBase.__ne__c                sH   |sˆ S t ‡ fdd„|D ƒƒ}ˆ jf| }ˆ  ˆ j |¡ˆ jˆ j¡}|S )z‡ return a new Path (with the same revision) which is composed
            of the self Path followed by 'args' path components.
        c                s   g | ]}|  ˆ j¡‘qS r   )r*   rO   )Ú.0Úarg)r   r   r   ú
<listcomp>ß   s    z$SvnPathBase.join.<locals>.<listcomp>)ÚtuplerF   rR   rO   r+   r   rJ   )r   Úargsr^   Únewpathr   )r   r   r+   Ø   s    zSvnPathBase.joinc             C   s   |   |¡}|S )z+ return the content of the given property. )Z_propget)r   r_   Úvaluer   r   r   Úpropgetä   s    
zSvnPathBase.propgetc             C   s   |   ¡ }|S )z list all property names. )Z	_proplist)r   Úcontentr   r   r   r   é   s    zSvnPathBase.proplistc             C   s
   |   ¡ jS )z2 Return the size of the file content of the Path. )r   Úsize)r   r   r   r   rm   î   s    zSvnPathBase.sizec             C   s
   |   ¡ jS )z0 Return the last modification time of the file. )r   Úmtime)r   r   r   r   rn   ò   s    zSvnPathBase.mtimec             C   s   t |ƒS )N)r6   )r   Úcmdr   r   r   Ú_escapeø   s    zSvnPathBase._escapec               @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
zSvnPathBase.Checkersc             C   s2   y| j  ¡ jdkS  tjjk
r,   |  ¡ S X d S )NÚdir)Úpathr   Úkindr'   ÚerrorÚErrorÚ_listdirworks)r   r   r   r   rq     s    zSvnPathBase.Checkers.dirc             C   s0   y| j  ¡  W n tjjk
r&   dS X dS d S )NFT)rr   Úlistdirr'   rt   ÚENOENT)r   r   r   r   rv     s
    z"SvnPathBase.Checkers._listdirworksc             C   s.   y| j  ¡ jdkS  tjjk
r(   dS X d S )Nr<   F)rr   r   rs   r'   rt   rx   )r   r   r   r   r<   #  s    zSvnPathBase.Checkers.filec             C   s,   y
| j  ¡ S  tjjk
r&   |  ¡ S X d S )N)rr   r   r'   rt   rx   rv   )r   r   r   r   Úexists)  s    
zSvnPathBase.Checkers.existsN)r   r   r   rq   rv   r<   ry   r   r   r   r   ÚCheckers  s   rz   )r   r   r   r!   rO   rG   Úpropertyr   r   rI   rW   rS   rb   rc   r+   rk   r   rm   rn   rp   r   rz   r   r   r   r   rE   {   s"   "$rE   c             C   s@   |   d¡}|dkrtd|  ƒ‚| d |… } t | d¡}t |¡S )Nr$   r   zcould not parse %sz%Y-%m-%dT%H:%M:%S)rZ   r@   r   ÚstrptimeÚmktime)Útimestrr`   Ú
parsedtimer   r   r   Úparse_apr_time/  s    
r€   c               @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚPropListDictzD a Dictionary which fetches values (InfoSvnCommand instances) lazilyc             C   s    t  | dd„ |D ƒ¡ || _d S )Nc             S   s   g | ]}|d f‘qS )Nr   )rd   Úxr   r   r   rf   :  s    z)PropListDict.__init__.<locals>.<listcomp>)Údictr   rr   )r   rr   Zkeynamesr   r   r   r   9  s    zPropListDict.__init__c             C   s2   t  | |¡}|d kr.| j |¡}t  | ||¡ |S )N)rƒ   Ú__getitem__rr   rk   Ú__setitem__)r   Úkeyrj   r   r   r   r„   =  s
    zPropListDict.__getitem__N)r   r   r   r!   r   r„   r   r   r   r   r   7  s   r   c               C   s   t jdkrdS dS )Nr"   z	LC_ALL=C rY   )r2   r3   r   r   r   r   Ú	fixlocaleD  s    
r‡   z* | \ / : < > ? 	 
   ú z^([a-z]\:\\)?[^:]+$c             C   sd   t d d … }| j}tr2| d¡ t |¡s2tdƒ‚x,|D ]$}|tjksN||kr8td|f ƒ‚q8W d S )Nr#   z path may not contain a colon (:)zillegal character %r in path)	ÚILLEGAL_CHARSrF   Ú	ISWINDOWSÚremoveÚ_reg_allow_diskÚmatchr@   ÚstringÚ	printable)rr   ÚillegalÚspÚcharr   r   r   Ú_check_pathO  s    


r“   Tc             C   s>   t | ƒ | j}|r,| jdkr,d|| jf }n|r:d|f }|S )Nr   z%s@%sz%s@HEAD)r“   rF   r   )rr   Zaddatr‘   r   r   r   Úpath_to_fspathZ  s    
r”   c             C   s¬   t | dƒ}ddlm} trvt |¡}| dd¡}| d¡rld| d¡ dd¡||t| d¡ƒd … ƒf }q~||ƒ}n||ƒ}| j	dkr˜d	|| j	f }n
d
|f }d|f S )NFr   )Úquoteú\r=   r;   z/%s%sr   z%s@%sz%s@HEADz	file://%s)
r”   Úurllibr•   rŠ   rŒ   r   r4   ÚgroupÚlenr   )rr   Úfspathr•   r   r   r   r   Úurl_from_pathc  s    


 


r›   c               @   s*   e Zd ZdZd
dd„Zdd„ Zdd„ Zd	S )ÚSvnAuthz/ container for auth information for Subversion Tc             C   s   || _ || _|| _|| _d S )N)ÚusernameÚpasswordÚ
cache_authÚinteractive)r   r   rž   rŸ   r    r   r   r   r   x  s    zSvnAuth.__init__c             C   sr   | j  dd¡}| j dd¡}g }|r4| d|f ¡ |rH| d|f ¡ | jsX| d¡ | jsh| d¡ d |¡S )Nú"z\"z--username="%s"z--password="%s"z--no-auth-cachez--non-interactiverˆ   )r   r4   rž   r   rŸ   r    r+   )r   ÚunameÚpasswdÚretr   r   r   Úmakecmdoptions~  s    

zSvnAuth.makecmdoptionsc             C   s   d| j f S )Nz<SvnAuth username=%s ...>)r   )r   r   r   r   r   Œ  s    zSvnAuth.__str__N)TT)r   r   r   r!   r   r¥   r   r   r   r   r   rœ   v  s   
rœ   z\s*(\d+)\s+(\S+) (.*)c               @   sò  e Zd ZdZejZdndd„Zedd„ dddƒZedd„ ddd	ƒZ	d
d„ Z
dd„ ZeedddƒZdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdodd„Zdd„ Zdd „ Zdpd!d"„Zdqd%d&„Zdrd(d)„Zd*d+„ Zd,d-„ Zd.d/„ Zd0d1„ Zd2d3„ Zdsd5d6„Zd7d8„ Zd9d:„ Z d;d<„ Z!d=d>„ Z"d?d@„ Z#dtdBdC„Z$dudDdE„Z%dFdG„ Z&e' (dHe'j)¡Z*dvdJdK„Z+dLdM„ Z,dNdO„ Z-dPdQ„ Z.dwdRdS„Z/dxdTdU„Z0dVdW„ Z1dXdY„ Z2dydZd[„Z3dzd\d]„Z4d{d_d`„Z5dadb„ Z6G dcdd„ dde7j8j9j:ƒZ:d|dfdg„Z;dhdi„ Z<djdk„ Z=dldm„ Z>dS )}ÚSvnWCCommandPathz¿ path implementation offering access/modification to svn working copies.
        It has methods similar to the functions in os.path and similar to the
        commands of the svn client.
    Nc             C   s\   t  | ¡}t|| ƒr(|j| kr"|S |j}tt|ƒtƒrDtd|f ƒ‚t	j
 |¡|_||_|S )Nzbad char in wcpath %s)rP   rQ   Ú
isinstancerR   Ú	localpathr:   r1   r?   r@   r'   rr   ÚlocalrJ   )ÚclsÚwcpathrJ   r   r   r   r   rQ   ˜  s    


zSvnWCCommandPath.__new__c             C   s
   t | jƒS )N)r1   r¨   )r‚   r   r   r   Ú<lambda>¥  ó    zSvnWCCommandPath.<lambda>zstring pathc             C   s   | j ddjS )Nr   )Úusecache)r   r   )r‚   r   r   r   r¬   ¦  r­   Úrevisionc             C   s   | j t|dd ƒkS )Nr¨   )r¨   Úgetattr)r   ra   r   r   r   rb   ¨  s    zSvnWCCommandPath.__eq__c             C   s:   t | dd ƒd kr |  ¡ }|j| _t| jtjjƒs4t‚| jS )NÚ_url)	r°   r   r   r±   r§   r'   ÚbuiltinZ_basestringÚAssertionError)r   r   r   r   r   rG   «  s
    zSvnWCCommandPath._geturlzurl of this WC itemc             C   s   t |ƒS )N)r6   )r   ro   r   r   r   rp   ´  s    zSvnWCCommandPath._escapec             C   s   | j  |¡S )z! pickle object into path location)r¨   Údump)r   rV   r   r   r   r´   ·  s    zSvnWCCommandPath.dumpc             C   s   |   ¡ }tj |j¡S )z* return current SvnPath for this WC-item. )r   r'   rr   Úsvnurlr   )r   r   r   r   r   rµ   »  s    zSvnWCCommandPath.svnurlc             C   s
   d| j  S )Nz	svnwc(%r))rF   )r   r   r   r   Ú__repr__À  s    zSvnWCCommandPath.__repr__c             C   s
   t | jƒS )N)r1   r¨   )r   r   r   r   r   Ã  s    zSvnWCCommandPath.__str__c             C   s   | j d krdS | j  ¡ S )NrY   )rJ   r¥   )r   r   r   r   Ú_makeauthoptionsÆ  s    
z!SvnWCCommandPath._makeauthoptionsc             C   s.   |rt |ƒpg }| |  ¡ ¡ | j|f|žŽ S )N)Úlistr   r·   Ú_svn)r   ro   rh   r   r   r   Ú_authsvnË  s    zSvnWCCommandPath._authsvnc       
   	      sR  d| g}‡ fdd„|D ƒ}|  |¡ | dˆ  ˆ j¡ ¡ tƒ d |¡ }yJz*d}tj |¡}dtj|< t	j
 |¡}W d |rŠ|tj|< ntj|= X W n¶ t	j
jjk
rL   t ¡ d }|j ¡ }	|	 d	¡d
kràt	j ˆ ¡‚n|	 d¡d
krút	j ˆ ¡‚|	 d¡d
ks:|	 d¡d
ks:|	 d¡d
ks:|	 d¡d
krFt	j |	¡‚‚ Y nX |S )Nzsvn %sc                s   g | ]}ˆ   |¡‘qS r   )rp   )rd   Úitem)r   r   r   rf   Ò  s    z)SvnWCCommandPath._svn.<locals>.<listcomp>z"%s"rˆ   ÚLC_MESSAGESÚCr;   z	not foundr   zE200009:zfile existszfile already existszw150002:zcan't create directory)Úextendr   rp   rF   r‡   r+   ÚosÚenvironr    r'   r(   r)   ru   r2   Úexc_infoÚerrÚlowerÚfindrt   rx   ÚEEXIST)
r   ro   rh   ÚlrŽ   r†   ZholdÚoutÚeZstrerrr   )r   r   r¹   Ð  s8    



zSvnWCCommandPath._svnc             C   s   |   d|g¡ dS )z switch to given URL. ÚswitchN)rº   )r   r   r   r   r   rÉ   ñ  s    zSvnWCCommandPath.switchc             C   s„   g }|dkr| j }|dks"|dkr@tjdkrjtƒ dkrj|d7 }n*tƒ dkrX|d| 7 }n| dt|ƒ ¡ | |¡ |  d|¡ dS )	z$ checkout from url to local wcpath. Nr   r"   z1.3z@HEADz@%dz-rÚco)r   r2   r3   r/   r   r1   rº   )r   r   r   rh   r   r   r   Úcheckoutõ  s    




zSvnWCCommandPath.checkoutÚHEADTc             C   s&   d|g}|s|  d¡ |  d|¡ dS )z= update working copy item to given revision. (None -> HEAD). z-rz--non-interactiveZupN)r   rº   )r   r   r    Úoptsr   r   r   Úupdate  s    
zSvnWCCommandPath.updateÚwc             C   s   | j  ||¡ dS )z) write content into local filesystem wc. N)r¨   Úwrite)r   rl   Úmoder   r   r   rÐ     s    zSvnWCCommandPath.writec             G   s   | j | jj|Ž | jdS )z0 return the directory Path of the current Path. )rJ   )rR   r¨   ÚdirpathrJ   )r   rh   r   r   r   rÒ     s    zSvnWCCommandPath.dirpathc             C   s4   |   ¡ }|jddr| ¡  | jddr0|  ¡  | S )Nr   )rq   )rÒ   ÚcheckÚ_ensuredirsÚmkdir)r   Úparentr   r   r   rÔ     s    zSvnWCCommandPath._ensuredirsc             O   sd   | j |Ž }| ¡ r*|jddr&| ¡  |S | dd¡r>| ¡ S | ¡ }| ¡  | d¡ | ¡  |S )zÄ ensure that an args-joined path exists (by default as
            a file). if you specify a keyword argument 'directory=True'
            then the path is forced  to be a directory path.
        F)Ú	versionedrq   r   rY   )r+   rÓ   Úaddr    rÔ   rÒ   rÐ   )r   rh   ÚkwargsÚprÖ   r   r   r   Úensure  s    

zSvnWCCommandPath.ensurec             G   s$   |r| j |Ž  ¡ S |  d¡ | S dS )z1 create & return the directory joined with args. rÕ   N)r+   rÕ   r¹   )r   rh   r   r   r   rÕ   /  s    
zSvnWCCommandPath.mkdirc             C   s   |   d¡ dS )z add ourself to svn rØ   N)r¹   )r   r   r   r   rØ   7  s    zSvnWCCommandPath.addr;   c             C   sP   |st dƒ‚| jdds,tj | ¡ ¡  dS g }|r>| d¡ | jd|žŽ  dS )zœ remove a file or a directory tree. 'rec'ursive is
            ignored and considered always true (because of
            underlying svn semantics.
        z!svn cannot remove non-recursivelyT)r×   Nz--forcer‹   )r‹   )r³   rÓ   r'   rr   r©   r‹   r   r¹   )r   ÚrecÚforceÚflagsr   r   r   r‹   ;  s    
zSvnWCCommandPath.removec             C   s    t j dt| ƒt|ƒf ¡ dS )z copy path to target.zsvn copy %s %sN)r'   r(   r)   r1   )r   Útargetr   r   r   ÚcopyJ  s    zSvnWCCommandPath.copyc             C   s    t j dt| ƒt|ƒf ¡ dS )z rename this path to target. zsvn move --force %s %sN)r'   r(   r)   r1   )r   rß   r   r   r   ÚrenameN  s    zSvnWCCommandPath.renamec             C   s   |   d¡ ¡ }|stdƒ‚dS )z( set a lock (exclusive) on the resource Úlockz!unknown error in svn lock commandN)rº   r*   r@   )r   rÇ   r   r   r   râ   R  s    zSvnWCCommandPath.lockc             C   s,   |   d¡ ¡ }| d¡r(t|dd… ƒ‚dS )z unset a previously set lock Úunlockzsvn:é   N)rº   r*   r   Ú	Exception)r   rÇ   r   r   r   rã   Y  s    
zSvnWCCommandPath.unlockc             C   s   y|   ¡  W n   Y nX dS )z$ remove any locks from the resource N)rã   )r   r   r   r   Úcleanup`  s    zSvnWCCommandPath.cleanupr   c             C   s¢   |rt dƒ‚nd}|rd}nd}|r*d}nd}yd|||f }|  |¡}W nB tjjjk
rŒ   d|||f }|  |¡}t| ƒ || ¡}Y nX t| ƒ || ¡}|S )z2 return (collective) Status object for this file. z1XXX cannot perform status() on external items yetrY   z--non-recursivez-uz$status -v --xml --no-ignore %s %s %szstatus -v --no-ignore %s %s %s)	r@   rº   r'   r(   r)   ru   ÚWCStatusÚ
fromstringÚXMLWCStatus)r   ZupdatesrÜ   Z	externalsro   rÇ   Ú
rootstatusr   r   r   Ústatush  s(    

zSvnWCCommandPath.statusc             C   s*   g }|dk	r|  d| ¡ |  d|¡}|S )zj return a diff of the current path against revision rev (defaulting
            to the last one).
        Nz-r %dÚdiff)r   rº   )r   r   rh   rÇ   r   r   r   rì   Ž  s
    zSvnWCCommandPath.diffc             C   sŠ   |   d¡}g }| ¡ }tj | j¡ ¡ }x\tt||ƒƒD ]J\}\}}t	 
|¡}|s`td|f ƒ‚| ¡ \}	}
}| t|	ƒ|
|f¡ q8W |S )z[ return a list of tuples of three elements:
            (revision, commiter, line)
        Úblamez:output line %r of svn blame does not match expected format)r¹   Ú
splitlinesr'   rr   rµ   r   Ú	readlinesÚ	enumerateÚzipÚ	rex_blamer   r@   Úgroupsr   Úint)r   rÇ   ÚresultZ
blamelinesZ	reallinesr`   Z	blamelineÚlineÚmr   r_   Ú_r   r   r   rí   ˜  s    


zSvnWCCommandPath.blamez.*Committed revision (\d+)\.$rY   c             C   sl   d|  dd¡f }|s|d7 }|  |¡}ytj| = W n tk
rH   Y nX |rh| j |¡}t| d¡ƒS dS )z/ commit with support for non-recursive commits zcommit -m "%s" --force-logr¡   z\"z -Nr;   N)	r4   rº   r   r   ÚKeyErrorÚ_rex_commitr   rô   r˜   )r   ÚmsgrÜ   ro   rÇ   r÷   r   r   r   Úcommit«  s    
zSvnWCCommandPath.commitc             G   sN   t jj ¡ }z2| d¡}| |¡ | jd|dt|ƒf|žŽ  W d| ¡  X dS )z* set property name to value on this path. rj   Úpropsetz--fileN)	r'   rr   r©   Úmkdtempr+   rÐ   r¹   r1   r‹   )r   r_   rj   rh   ÚdrÚ   r   r   r   rý   º  s    

zSvnWCCommandPath.propsetc             C   s   |   d|¡}|dd… S )z! get property name on this path. rk   Nr   )r¹   )r   r_   r]   r   r   r   rk   Ä  s    zSvnWCCommandPath.propgetc             C   s   |   d|¡}|dd… S )z$ delete property name on this path. ÚpropdelNr   )r¹   )r   r_   r]   r   r   r   r   É  s    zSvnWCCommandPath.propdelc             C   sP   |r|   d¡}t| |ƒS |   d¡}| d¡}dd„ |dd… D ƒ}t| |ƒS dS )z… return a mapping of property names to property values.
If rec is True, then return a dictionary mapping sub-paths to such mappings.
zproplist -Rr   Ú
c             S   s   g | ]}|  ¡ ‘qS r   )r*   )rd   r‚   r   r   r   rf   Ø  s    z-SvnWCCommandPath.proplist.<locals>.<listcomp>r;   N)r¹   Úmake_recursive_propdictr,   r   )r   rÜ   r]   Úlinesr   r   r   r   Î  s    



zSvnWCCommandPath.proplistc             C   s   |r|   d¡}n
|   d¡}|S )zK revert the local changes of this path. if rec is True, do so
recursively. z	revert -RÚrevert)r¹   )r   rÜ   rõ   r   r   r   r  Û  s    
zSvnWCCommandPath.revertc             K   s*   |r| j jf |Ž}n| j }| j|| jdS )aÇ   create a modified version of this path. A 'rev' argument
            indicates a new revision.
            the following keyword arguments modify various path parts:

              http://host.com/repo/path/file.ext
              |-----------------------|          dirname
                                        |------| basename
                                        |--|     purebasename
                                            |--| ext
        )rJ   )r¨   rW   rR   rJ   )r   rU   r¨   r   r   r   rW   ä  s    zSvnWCCommandPath.newc             O   s&   |s| S | j j||Ž}| j|| jdS )z‡ return a new Path (with the same revision) which is composed
            of the self Path followed by 'args' path components.
        )rJ   )r¨   r+   rR   rJ   )r   rh   rÙ   r¨   r   r   r   r+   õ  s    zSvnWCCommandPath.joinc             C   s  |ot j | ¡}|sy|  d¡}W nj tjjjk
rŽ   t 	¡ d }|j
 d¡dkrhtj | |j
¡‚n |j
 d¡dkrˆtj | |j
¡‚‚ Y nX | ¡ dks®| ¡  d¡dkr¼tj | |¡‚t|ƒ}tjdkrø|j| jkrøtj | d	d
|j| jf  ¡‚|t j| < |S )z9 return an Info structure with svn-provided information. r   r;   z$Path is not a working copy directoryr   zis not under version controlrY   znot a versioned resourcer"   znot a versioned resource:z	 %s != %s)r   r   r    r¹   r'   r(   r)   ru   r2   rÁ   rÂ   rÄ   rt   rx   r*   rÃ   ÚInfoSvnWCCommandr3   rr   r¨   )r   r®   r   ÚoutputrÈ   r   r   r   r   þ  s*    


zSvnWCCommandPath.infoc             C   st   t |tƒrt |¡}dd„ }g }xB| j |¡D ]2}| j|| jd}||ƒr.|rV||ƒr.| |¡ q.W |  	||¡ |S )z‘ return a sequence of Paths.

        listdir will return either a tuple or a list of paths
        depending on implementation choices.
        c             S   s
   | j dkS )Nz.svn)rK   )rr   r   r   r   Únotsvn$  s    z(SvnWCCommandPath.listdir.<locals>.notsvn)rJ   )
r§   r1   r   Z	FNMatcherr¨   rw   rR   rJ   r   Z	_sortlist)r   ZfilÚsortr  Úpathsr¨   rÚ   r   r   r   rw     s    

zSvnWCCommandPath.listdirÚrc             C   s   t | j|ƒS )z, return an opened file with the given mode. )ÚopenrF   )r   rÑ   r   r   r   r  /  s    zSvnWCCommandPath.openc             C   s   | j  |¡S )N)r¨   rS   )r   r\   r   r   r   rS   3  s    zSvnWCCommandPath._getbyspecc               @   s   e Zd Zdd„ Zdd„ ZdS )zSvnWCCommandPath.Checkersc             C   s   || _ |j| _d S )N)Ú	svnwcpathr¨   rr   )r   rr   r   r   r   r   7  s    z"SvnWCCommandPath.Checkers.__init__c          	   C   sŠ   y| j  ¡ }W nr tjjtjjfk
r.   dS  tjjjk
r€   t	 
¡ d }|j d¡dkrbdS |j ¡  d¡dkrzdS ‚ Y nX dS d S )NFr;   zis not a working copyr   znot a versioned resourceT)r  r   r'   rt   rx   rÅ   r(   r)   ru   r2   rÁ   rÂ   rÄ   rÃ   )r   ÚsrÈ   r   r   r   r×   :  s    z#SvnWCCommandPath.Checkers.versionedN)r   r   r   r   r×   r   r   r   r   rz   6  s   rz   Fc             C   s"  |   ¡ st‚|dkrdp|}|dkr(dp*|}|dkrB|dkrBd}nd||f }|rVdpXd}tƒ }|  ¡ }|d|||| jf  }tj|tjtjdd	}	|	 ¡ \}
}t	j
 |
t ¡ ¡}
tƒ \}}y| |
¡}W n |k
ræ   td
ƒ‚Y nX g }x0td|jjƒD ]}|j|jkrü| t|ƒ¡ qüW |S )zø return a list of LogEntry instances for this path.
rev_start is the starting revision (defaulting to the first one).
rev_end is the last revision (defaulting to HEAD).
if verbose is True, then the LogEntry instances also know which files changed.
NrÌ   r;   rY   z-r %s:%sz-vzsvn log --xml %s %s %s "%s"T)ÚstdoutÚstderrÚshellzno such revision)rÓ   r³   r‡   r·   rF   Ú
subprocessÚPopenÚPIPEÚcommunicater'   r²   Z_totextr2   ÚgetdefaultencodingÚ	importxmlÚparseStringr@   ÚfilterÚ
firstChildÚ
childNodesÚnodeTypeÚELEMENT_NODEr   ÚLogEntry)r   Z	rev_startZrev_endÚverboseZrev_optZverbose_optZ
locale_envZauth_optro   Úpopenr  r  ÚminidomÚ
ExpatErrorÚtreerõ   Úlogentryr   r   r   ÚlogI  s6    
zSvnWCCommandPath.logc             C   s
   |   ¡ jS )z2 Return the size of the file content of the Path. )r   rm   )r   r   r   r   rm   s  s    zSvnWCCommandPath.sizec             C   s
   |   ¡ jS )z0 Return the last modification time of the file. )r   rn   )r   r   r   r   rn   w  s    zSvnWCCommandPath.mtimec             C   s   t | j| j| jfƒS )N)rH   rF   rR   rJ   )r   r   r   r   rI   {  s    zSvnWCCommandPath.__hash__)NN)N)NN)rÌ   T)rÏ   )r;   r;   )r   r   r   )N)rY   r;   )r   )r   )r;   )NN)r
  )Nr;   F)?r   r   r   r!   r¿   rO   rQ   r{   rF   r   rb   rG   r   rp   r´   rµ   r¶   r   r·   rº   r¹   rÉ   rË   rÎ   rÐ   rÒ   rÔ   rÛ   rÕ   rØ   r‹   rà   rá   râ   rã   ræ   rë   rì   rí   ÚreÚcompileÚDOTALLrú   rü   rý   rk   r   r   r  rW   r+   r   rw   r  rS   r'   rr   r©   rz   r$  rm   rn   rI   r   r   r   r   r¦   ‘  sh   

!




&





		



*r¦   c               @   s@   e Zd ZdZddd„Zddd„Ze d¡Zdd	d
„Z	e
e	ƒZ	dS )rç   )ÚmodifiedÚaddedÚconflictÚ	unchangedÚexternalÚdeletedÚprop_modifiedÚunknownÚupdate_availableÚ
incompleteÚkindmismatchÚignoredÚlockedÚreplacedNc             C   s8   || _ || _|| _|| _x| jD ]}t| |g ƒ q W d S )N)r«   r   ÚmodrevÚauthorÚ	attrnamesÚsetattr)r   r«   r   r6  r7  r_   r   r   r   r   …  s    zWCStatus.__init__Tc             K   sX   i }x:| j D ]0}||ks || rxt| |ƒD ]}d||< q,W qW | ¡ }|rT| ¡  |S )Nr;   )r8  r°   Úkeysr  )r   r  rU   rÿ   r_   rr   rÆ   r   r   r   ÚallpathŽ  s    zWCStatus.allpathz$\s+(\d+|-)\s+(\S+)\s+(.+?)\s{2,}(.*)c          	   C   s  t ||||ƒ}d}xê|  d¡D ]Ú}| ¡ s0q |dd… |dd…  }}	|\}
}}}}}}}|
dkrð| dd¡d }|
dkrš|j|dd}|j |¡ q |
dkrÌ|j|jj|dd|jd	}|j	 |¡ q |
d
kr |j|dd}|j
 |¡ q t j |	¡}|s€|dkr0|	 ¡ }|j|dd}|j |¡ q | ¡  d¡dkr\t|	 d¡d  ¡ ƒ}q | ¡  d¡dkrrq td| ƒ‚n| ¡ \}}}}|j|dd}|
dkrÌ|jdds¾tdƒ‚|j |¡ n¾|
dksà|dkrî|j |¡ nœ|
dkr|j |¡ n„|
dkr|j |¡ nl|
dkr6|j |¡ nT|
dkrN|j |¡ n<|
dkrf|j |¡ n$|
 ¡ s~|j |¡ ntd|
 ƒ‚|dkr |j |¡ |dks´|dkrÀ|j |¡ |dkrÖ|j |¡ ||kr ||_ ||_!||_"|r ||_#q q W |S )z4 return a new WCStatus object from data 's'
        Nr  é   z?XIr;   ú?)ÚabsÚX)rJ   ÚIÚ*zagainst revision:r   r#   zstatus on externalzcould not parse line %rÚM)r<   z3didn't expect a directory with changed content hereÚAú+ÚDr½   ú~ú!ÚRzreceived flag %rÚLÚK)$rç   r,   r*   r+   r/  r   rR   r¨   rJ   r,  r3  Ú_rex_statusr   r0  rÃ   rÄ   rô   r@   ró   rÓ   r³   r(  r)  r-  r*  r2  r1  r5  r+  ÚNotImplementedErrorr.  r4  r   r6  r7  Ú
update_rev)ÚdataÚ
rootwcpathr   r6  r7  rê   rM  rö   rÞ   ÚrestZc0Zc1Úc2Úc3Zc4Zc5Zx6Zc7Úfnr«   r÷   r   r   r   rè   ž  sˆ    










zWCStatus.fromstring)NNN)T)NNN)r   r   r   r8  r   r;  r%  r&  rK  rè   Ústaticmethodr   r   r   r   rç     s   
	


]rç   c               @   s   e Zd Zddd„ZeeƒZdS )ré   Nc             C   s  t ||||ƒ}d}tƒ \}}y| | ¡}	W n, |k
rV   t ¡ d }
tt|
ƒƒ‚Y nX |	 d¡}|rv|d  d¡|_	xˆ|	 d¡D ]x}| d¡}| d¡d	 }| d
¡}|dkrÒ|j
|dd}|j |¡ q„n„|dkr|j|jj
|dd|jd}|j |¡ q„nN|dkr0|j
|dd}|j |¡ q„n&|dkrV|j
|dd}|j |¡ q„| d¡}|dkst|dkr†d}d}d}d}nˆ|dkr’n|| d¡d	 }|r| d¡}d}| d¡}|räx|d	 jD ]}||j7 }qÐW d}x$| d¡d	 jD ]}||j7 }qúW |j
|dd}|dks<|jdds<tdƒ‚ddddd œ ||¡}t||ƒ}| |¡ | d!¡}|d"kr†|j |¡ ||kr¨||_||_||_||_| d#¡}|rà|d	 }| d
¡}|d$krà|j |¡ | d%¡}t|ƒr„|j  |¡ q„W |S )&zL parse 'data' (XML string as outputted by svn st) into a status obj
        Nr;   Zagainstr   r¯   r   rr   z	wc-statusr   r»   Úunversioned)r>  r,  )rJ   r3  r1  r)  ÚnoneÚ0r=  rY   r5  rü   r7  Údater(  )r<   z2did't expect a directory with changed content herer+  r/  r*  )ÚnormalrU  Z
conflictedrV  Úprops)rV  rY  zrepos-status)r)  r(  râ   )!rç   r  r  r2   rÁ   r@   r1   ZgetElementsByTagNameÚgetAttributerM  r+   r/  r   rR   r¨   rJ   r,  r3  r1  r  Ú	nodeValuerÓ   r³   r    r°   r.  r   r6  r7  rX  r0  r™   r4  )rN  rO  r   r6  r7  rê   rM  r   r!  ÚdocrÈ   ZurevelsZentryelrr   ZstatuselZ
itemstatusr«   rX  ZcommitelZ
author_elsr9   ZitemattrnameÚattrZpropsstatusZ
rstatuselsZ	rstatuselZritemstatusZlockelsr   r   r   rè   þ  s     	




















zXMLWCStatus.fromstring)NNN)r   r   r   rè   rT  r   r   r   r   ré   ý  s   
iré   c               @   s   e Zd Zdd„ Zdd„ ZdS )r  c             C   s6  i }xL|  d¡D ]>}| ¡ sq|  dd¡\}}| ¡  dd¡}| ¡ }|||< qW y|d | _W n tk
r|   tdƒ‚Y nX |d d	krŽd
p”|d | _yt|d ƒ| _	W n tk
rÄ   d | _	Y nX t
j |d ¡| _| j ¡ | _d|krút|d ƒ| _d|kr|d | _d|kr2t|d ƒ| _| jd | _d S )Nr  r#   r;   rˆ   rY   r   zNot a versioned resourceZnodekindÚ	directoryrq   r¯   rr   ZlastchangedrevZlastchangedauthorZlastchangeddatei@B )r,   r*   rÃ   r4   r   rù   r@   rs   rô   r   r'   rr   r©   rm   Zcreated_revZlast_authorÚparse_wcinfotimern   r   )r   r  rÿ   rö   r†   rj   r   r   r   r   j  s4    


zInfoSvnWCCommand.__init__c             C   s   | j |j kS )N)Ú__dict__)r   ra   r   r   r   rb   “  s    zInfoSvnWCCommand.__eq__N)r   r   r   r   rb   r   r   r   r   r  i  s   )r  c             C   s>   t  d| ¡}|std|  ƒ‚| ¡ \} }t | d¡}t |¡S )z# Returns seconds since epoch, UTC. z&(\d+-\d+-\d+ \d+:\d+:\d+) ([+-]\d+) .*ztimestring %r does not matchz%Y-%m-%d %H:%M:%S)r%  r   r@   ró   r   r|   ÚcalendarÚtimegm)r~   r÷   Útimezoner   r   r   r   r`  –  s    r`  zProperties on '(.*)':c             C   s²   dd„ |  d¡D ƒ}i }x”|r¬| d¡}| |¡}|sBtd| ƒ‚| ¡ d }| j|dd}g }	x.|rŽ|d  d¡rŽ| d¡ ¡ }
|	 |
¡ qbW |	sœt	d	ƒ‚t
||	ƒ||< qW |S )
z5 Return a dictionary of path->PropListDict mappings. c             S   s   g | ]}|r|‘qS r   r   )rd   r‚   r   r   r   rf   ¥  s    z+make_recursive_propdict.<locals>.<listcomp>r  r   z could not parse propget-line: %rr;   )r>  z  zmust have found properties!)r,   Úpopr   r@   ró   r+   r   r*   r   r³   r   )Zwcrootr  Zrexr  Úpdictrö   r÷   rr   r«   Z	propnamesZpropnamer   r   r   r  ¡  s     

r  c             C   s2   | r| S ddl m} ddlm} |  ||g¡ | S )Nr   )r   )r!  )Úxml.domr   Úxml.parsers.expatr!  r¾   )r   r   r!  r   r   r   r  ·  s    r  c               @   s   e Zd Zdd„ Zdd„ ZdS )r  c             C   sÐ   t | d¡ƒ| _xºtd |jƒD ]ª}|j|jkr|jdkrD|jj	| _
q|jdkrh|jr`|jj	| _qÈd| _q|jdkr†|jj	}t|ƒ| _q|jdkrg | _x0td |jƒD ] }|j|jkr¤| j t|ƒ¡ q¤W qW d S )Nr¯   r7  rû   rY   rX  r	  )rô   r[  r   r  r  r  r  ÚnodeNamer  r\  r7  rû   r€   rX  Zstrpathsr   Z	PathEntry)r   r#  Zlpartr~   Zppartr   r   r   r   À  s"    



zLogEntry.__init__c             C   s   d| j | j| jf S )Nz#<Logentry rev=%d author=%s date=%s>)r   r7  rX  )r   r   r   r   r¶   Ô  s    zLogEntry.__repr__N)r   r   r   r   r¶   r   r   r   r   r  ¿  s   r  )T)1r!   r¿   r2   r   r%  rb  r'   r  Zpy._pathr   r   r   r   Zrepositoriesr?   r3   r>   r/   r6   r:   rD   ZPathBaserE   r€   rƒ   r   r‡   r,   r‰   rO   r‹   rŠ   r&  r@  rŒ   r“   r”   r›   rP   rœ   rò   r¦   rç   ré   r  r`  r  r  r  r   r   r   r   Ú<module>   sT   (		(

	 5


	
   q~l-