403Webshell
Server IP : 80.87.202.40  /  Your IP : 216.73.216.169
Web Server : Apache
System : Linux rospirotorg.ru 5.14.0-539.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Dec 5 22:26:13 UTC 2024 x86_64
User : bitrix ( 600)
PHP Version : 8.2.27
Disable Function : NONE
MySQL : OFF |  cURL : ON |  WGET : ON |  Perl : ON |  Python : OFF |  Sudo : ON |  Pkexec : ON
Directory :  /lib64/python3.9/site-packages/mercurial/__pycache__/

Upload File :
current_dir [ Writeable] document_root [ Writeable]

 

Command :


[ Back ]     

Current File : /lib64/python3.9/site-packages/mercurial/__pycache__/crecord.cpython-39.pyc
a

�+�b��	@s�ddlmZddlZddlZddlZddlmZddlmZm	Z	ddl
mZmZm
Z
mZmZmZmZddlmZejZed�Zed	�Zed
�ZzddlZddlZej
Wneefy�dZYn0Gdd�de
j�Zd
d�ZGdd�de�Z Gdd�de e!�ZGdd�de �Z"Gdd�de �Z#Gdd�de �Z$d(dd�Z%d)dd�Z&dd�Z'd*dd �Z(ed!�ed"�ed#�ed$�d%�Z)Gd&d'�d'e�Z*dS)+�)�absolute_importN�)�_)�getattr�open)�
diffhelper�encoding�error�patch�pycompat�scmutil�util)�
stringutils�# To remove '-' lines, make them ' ' lines (context).
# To remove '+' lines, delete them.
# Lines starting with # will be removed from the patch.
s,#
# If the patch applies cleanly, the edited hunk will immediately be
# added to the record list. If it does not apply cleanly, a rejects file
# will be generated. You can use that when you try again. If all lines
# of the hunk are removed, then the edit is aborted and the hunk is left
# unchanged.
s�#
# If the patch applies cleanly, the edited patch will immediately
# be finalised. If it does not apply cleanly, rejects files will be
# generated. You can use those when you try again.
c@seZdZdZdS)�
fallbackerrorzDError that indicates the client should try to fallback to text mode.N)�__name__�
__module__�__qualname__�__doc__�rr�7/usr/lib64/python3.9/site-packages/mercurial/crecord.pyrFsrcCsto|�d�dkS)z�Return True if the user wants to use curses

    This method returns True if curses is found (and that python is built with
    it) and that the user has the correct flag for the ui.
    s
chunkselectorscurses)�cursesZ	interface)�uirrr�checkcursesMsrc@sReZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	ddd�Z
dd�ZdS)�	patchnodezVabstract class for patch graph nodes
    (i.e. patchroot, header, hunk, hunkline)
    cCstd��dS�N�&method must be implemented by subclass��NotImplementedError��selfrrr�
firstchild[szpatchnode.firstchildcCstd��dSrrrrrr�	lastchild^szpatchnode.lastchildcCstd��dS)z8Return a list of all of the direct children of this noderNrrrrr�allchildrenaszpatchnode.allchildrencCstd��dS)z�
        Return the closest next item of the same type where there are no items
        of different types between the current item and this closest item.
        If no such item exists, return None.
        rNrrrrr�nextsiblingeszpatchnode.nextsiblingcCstd��dS)z�
        Return the closest previous item of the same type where there are no
        items of different types between the current item and this closest item.
        If no such item exists, return None.
        rNrrrrr�prevsiblingmszpatchnode.prevsiblingcCstd��dSrrrrrr�
parentitemuszpatchnode.parentitemTcCs�z
|j}Wnty d}Yn0|rf|rf|��}|durbz|����}Wnty`d}Yn0|S|��}|durz|S|��}|dur�|Sz,|����}|dur�|WS|������WSty�YdS0dS)ax
        Try to return the next item closest to this item, regardless of item's
        type (header, hunk, or hunkline).

        If skipfolded == True, and the current item is folded, then the child
        items that are hidden due to folding will be skipped when determining
        the next item.

        If it is not possible to get the next item, return None.
        FN)�folded�AttributeErrorr#r%r )rZ
skipfoldedZ
itemfolded�nextitem�itemrrrr(xs2


zpatchnode.nextitemcCsR|��}|durJ|��}|durF|jsF|��}|dur@|js@|S|Sn|S|��S)z�
        Try to return the previous item closest to this item, regardless of
        item's type (header, hunk, or hunkline).

        If it is not possible to get the previous item, return None.
        N)r$r!r&r%)rr$ZprevsiblinglastchildZprevsiblinglclcrrr�previtem�s	��zpatchnode.previtemN)T)rrrrr r!r"r#r$r%r(r*rrrrrVs
.rc@seZdZdZdd�ZdS)r
z8
    list of header objects representing the patch.
    cCs|�|�|D]
}||_qdS�N)�extendr
)r�
headerlist�headerrrr�__init__�s
zpatch.__init__N)rrrrr/rrrrr
�sr
c@sXeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�ZdS)�uiheaderzIpatch header

    xxx shouldn't we move this to mercurial/patch.py ?
    cs>|�_d�_d�_d�_d�_d�_�fdd��jD��_dS)NTFcsg|]}t|���qSr��uihunk��.0�hrrr�
<listcomp>��z%uiheader.__init__.<locals>.<listcomp>)�nonuiheader�applied�partialr&r
�
neverunfolded�hunks)rr.rrrr/�szuiheader.__init__cCst�}|�|�|��Sr+��stringio�pretty�getvalue�r�xrrr�	prettystr�s
zuiheader.prettystrcCs<t|j�}|j�|�}||dkr4|j|d}|SdSdS�Nr)�lenr
�index)rZnumheadersinpatch�indexofthisheaderZ
nextheaderrrrr#�s
zuiheader.nextsiblingcCs.|j�|�}|dkr&|j|d}|SdSdS�Nrr)r
rF)rrGZpreviousheaderrrrr$�s
zuiheader.prevsiblingcCsdS)zj
        there is no 'real' parent item of a header that can be selected,
        so return None.
        Nrrrrrr%�szuiheader.parentitemcCs t|j�dkr|jdSdSdS��Lreturn the first child of this item, if one exists.  otherwise
        None.rN�rEr<rrrrr s
zuiheader.firstchildcCs t|j�dkr|jdSdSdS��Kreturn the last child of this item, if one exists.  otherwise
        None.r���NrKrrrrr!s
zuiheader.lastchildcCs|jS�z8return a list of all of the direct children of this node)r<rrrrr"szuiheader.allchildrencCst|j|�Sr+)rr8�r�namerrr�__getattr__szuiheader.__getattr__N)
rrrrr/rCr#r$r%r r!r"rRrrrrr0�s
r0c@sHeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dS)�
uihunklinez#represents a changed line in a hunkcCs||_d|_||_d|_dS�NTF)�linetextr9�hunkr&)rrUrVrrrr/szuihunkline.__init__cCs|jSr+)rUrrrrrC'szuihunkline.prettystrcCsBt|jj�}|jj�|�}||dkr:|jj|d}|SdSdSrD)rErV�changedlinesrF)rZnumlinesinhunk�indexofthislineZnextlinerrrr#*szuihunkline.nextsiblingcCs2|jj�|�}|dkr*|jj|d}|SdSdSrH)rVrWrF)rrXZpreviouslinerrrr$4s
zuihunkline.prevsiblingcCs|jS�z%return the parent to the current item)rVrrrrr%<szuihunkline.parentitemcCsdS)rJNrrrrrr @szuihunkline.firstchildcCsdS)rMNrrrrrr!Fszuihunkline.lastchildN)rrrrr/rCr#r$r%r r!rrrrrSs	
rSc@s�eZdZdZdZdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
dd�ZeZdd�Zdd�Zdd�Zdd�ZdS) r2z9ui patch hunk, wraps a hunk and keep track of ui behavior�cs@|�_�fdd�|jD��_|�_�j�_d�_d�_d�_dS)Ncsg|]}t|���qSr)rS�r4�linerrrr6Tr7z#uihunk.__init__.<locals>.<listcomp>TF)	�_hunkrVrWr.�removed�originalremovedr&r9r:)rrVr.rrrr/Rszuihunk.__init__cCsBt|jj�}|jj�|�}||dkr:|jj|d}|SdSdSrD)rEr.r<rF)rZnumhunksinheader�indexofthishunkZnexthunkrrrr#aszuihunk.nextsiblingcCs2|jj�|�}|dkr*|jj|d}|SdSdSrH)r.r<rF)rr`Zprevioushunkrrrr$ks
zuihunk.prevsiblingcCs|jSrY�r.rrrrr%sszuihunk.parentitemcCs t|j�dkr|jdSdSdSrI�rErWrrrrr ws
zuihunk.firstchildcCs t|j�dkr|jdSdSdSrLrbrrrrr!s
zuihunk.lastchildcCs|jSrO)rWrrrrr"�szuihunk.allchildrencCs0tdd�|jD��}tdd�|jD��}||fS)zchangedlines -> (n+,n-)cSs$g|]}|jr|���d�r|�qS)�+�r9rC�
startswith�r4�lrrrr6�s�z'uihunk.countchanges.<locals>.<listcomp>cSs$g|]}|jr|���d�r|�qS)�-rdrfrrrr6�s�rb)r�addZremrrr�countchanges�s����zuihunk.countchangescCs�|j|j}t|j�t|j�|}|jrB|jdtjkrB|d8}||j}||j}|j|j	}}|dkr�|dkr||d8}|dkr�|dkr�|d8}d|||||j
o�d|j
f}|S)NrNrrs@@ -%d,%d +%d,%d @@%s
� )r_r^rE�before�afterr�MISSING_NEWLINE_MARKER�added�fromline�toline�proc)rZremovedconvertedtocontextZ
contextlenZfromlenZtolenrprqZ
fromtolinerrr�
getfromtoline�s*�

�zuihunk.getfromtolinecCs�|��\|_|_|�|���g}|jD]>}|��}|jrF|�|�q(|�	d�r(|�d|dd��q(|�d�
|j||j��dS)Nrhrkrr7)
rjror^�writersrWrCr9�appendre�joinrlrm)r�fpZhunklinelistZchangedlineZchangedlinestrrrrrt�s

zuihunk.writecCst�}|�|�|��Sr+r=rArrrrC�s
zuihunk.prettystrc	Csg}g}d}|jD]�}|j}|jtjkr0d}q�|jrr|�d�rT|�|dd��q�|�d�r�|�|dd��q|�d�r|�|dd��|�|dd��qdd�|D�d	d�|D�}|r�|r�|d
dd
�|d
<|j}t�	|j
|j|j|j
|j||j�S)aSreturn a recordhunk which is the reverse of the hunk

        Assuming the displayed patch is diff(A, B) result. The returned hunk is
        intended to be applied to B, instead of A.

        For example, when A is "0
1
2
6
" and B is "0
3
4
5
6
", and
        the user made the following selection:

                 0
            [x] -1           [x]: selected
            [ ] -2           [ ]: not selected
            [x] +3
            [ ] +4
            [x] +5
                 6

        This function returns a hunk like:

                 0
                -3
                -4
                -5
                +1
                +4
                 6

        Note "4" was first deleted then added. That's because "4" exists in B
        side and "-4" must exist between "-3" and "-5" to make the patch
        applicable to B.
        FTrcrNrhcSsg|]}d|�qS)s-%srrfrrrr6r7z&uihunk.reversehunk.<locals>.<listcomp>cSsg|]}d|�qS)s+%srrfrrrr6r7rN)rWrUrrnr9rerur]�patchmodZ
recordhunkr.rqrprrrlrm)rZdelsZaddsZnoeolr\�textrVr5rrr�reversehunk�s.



�zuihunk.reversehunkcCst|j|�Sr+)rr]rPrrrrRszuihunk.__getattr__cCsd|��|jfS)Nz<hunk %r@%d>)�filenamerprrrr�__repr__szuihunk.__repr__N)rrrrZ
maxcontextr/r#r$r%r r!r"rjrsrtr?rCrzrRr|rrrrr2Ms"
"8r2cCs�t|�}dd�|D�}t|�dkr*gifSdd�|D�}||||d�}g}|D]x}|jrN|��sxtdd�|jD��dkrN|�|�d}	|jD]8}
|
jr�|�|
�|	r�|
j|	7_q�|	|
j|
j7}	q�qN||fS)z:interactively filter patch chunks into applied-only chunkscSsg|]}t|tj�r|�qSr)�
isinstancerxr.)r4�crrrr6r7zfilterpatch.<locals>.<listcomp>rcSsg|]}t|��qSr)r0r3rrrr6 r7)�	operationcSsg|]}|jr|�qSr�r9r3rrrr6'r7)	�listrEr9�specialr<rurqr^ro)r�chunks�
chunkselectorrZheadersZ	uiheaders�retZappliedhunklist�hdrZ	fixoffset�hnkrrr�filterpatchs,��


r�c
Cs�|�td��t|||�}t�}}t�td�r<t�tj�}z^t�	��t
�|j�Wd�n1sh0Y|j
dur�|j
�W||ur�t�tj|�n||ur�t�tj|�0|jS)zk
    curses interface to get selection of chunks, and mark the applied flags
    of the chosen chunks.
    sstarting interactive selection
sSIGTSTPN)rtr�curseschunkselector�objectr
�safehasattr�signal�	getsignal�SIGTSTPZ
with_lc_ctyper�wrapper�main�initexc�opts)rr-rr�Zorigsigtstp�sentinelrrrr�9s

*
�r�cs��fdd�}|S)Ncs��g|�Ri|��Sr+r)�args�kwargs��f�testfnrr�uPsztestdecorator.<locals>.ur)r�r�r�rr�r�
testdecoratorOsr�cCsvt|||�}Gdd�dt�}|�|_|rptj�|�rpt|d�}dd�|��D�}|��|j	|�
d�dd�rXqpqX|jS)	zi
    test interface to get selection of chunks, and mark the applied flags
    of the chosen chunks.
    c@seZdZdd�Zdd�ZdS)z&testchunkselector.<locals>.dummystdscrcSsdSr+rrrrr�clear^sz,testchunkselector.<locals>.dummystdscr.clearcSsdSr+rrrrr�refreshasz.testchunkselector.<locals>.dummystdscr.refreshN)rrrr�r�rrrr�dummystdscr]sr��rcSsg|]}|�d��qS)�
)�rstrip)r4rBrrrr6hr7z%testchunkselector.<locals>.<listcomp>rT��test)r�r��stdscr�os�path�existsr�	readlines�close�handlekeypressed�popr�)r�rr-rr�r�ZtestfZtestcommandsrrr�testchunkselectorVs
r�sSelect hunks to applysSelect hunks to discardsSelect hunks to keepsSelect hunks to record)sapplysdiscardskeepNc@s�eZdZd`dd�Zdd�Zdd�Zdd	�Zd
d�Zdad
d�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dbdd�Zdd�Zdd�Zdd �Zdcd!d"�Zd#d$�Zddd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zded0d1�Zdfd2d3�Zdgd4d5�Zdhd6d7�Zdid8d9�Zd:d;�Zd<d=�Zdjd>d?�Z dkd@dA�Z!dBdC�Z"dldDdE�Z#dFdG�Z$dHdI�Z%dJdK�Z&dLdM�Z'dNdO�Z(dPdQ�Z)dRdS�Z*dTdU�Z+dmdVdW�Z,dXdY�Z-dndZd[�Z.d\d]�Z/d^d_�Z0dS)or�NcCs�t|�|_||_i|_d|_g|_|D]}|j�|�|j�|j�q&i|_	i|_
t�|j�
dd��}|du|_|jd|_d|_d|_d|_d|_d|_d|_d|_d|_d|_d|_d|_d	|_|tvr�t�d
|��||_dS)NsuiscolorFrrZ�rr7Tsunexpected operation: %s) r
r-rr��errorstr�	chunklistrur,r<�
colorpairs�colorpairnamesrZ	parseboolZconfig�usecolor�currentselecteditem�lastapplieditem�selecteditemstartline�selecteditemendlineZheaderindentnumchars�hunkindentnumchars�hunklineindentnumchars�firstlineofpadtoprint�numpadlines�numstatuslines�linesprintedtopadsofar�commenttext�waslasttoggleallapplied�_headermessagesr	ZProgrammingErrorr)rr-rrr5Zuicolorrrrr/ys<

�zcurseschunkselector.__init__cCs$|j}|��}|dur|}||_dS)aM
        try to select the previous item to the current item that has the
        most-indented level.  for example, if a hunk is selected, try to select
        the last hunkline of the hunk prior to the selected hunk.  or, if
        the first hunkline of a hunk is currently selected, then select the
        hunk itself.
        N)r�r*�r�currentitemr(rrr�uparrowevent�s
z curseschunkselector.uparroweventcCs<|j}|��}|dur|��}|dur*|}||_|��dS)z�
        select (if possible) the previous item on the same level as the
        currently selected item.  otherwise, select (if possible) the
        parent-item of the currently selected item.
        N)r�r$r%�recenterdisplayedarear�rrr�uparrowshiftevent�sz%curseschunkselector.uparrowshifteventcCs$|j}|��}|dur|}||_dS)ag
        try to select the next item to the current item that has the
        most-indented level.  for example, if a hunk is selected, select
        the first hunkline of the selected hunk.  or, if the last hunkline of
        a hunk is currently selected, then select the next hunk, if one exists,
        or if not, the next header if one exists.
        N)r�r(r�rrr�downarrowevent�s
	z"curseschunkselector.downarroweventcCs\|j}|��}|dur>z|����}Wnty<d}Yn0|durJ|}||_|��dS)z�
        select (if possible) the next item on the same level as the currently
        selected item.  otherwise, select (if possible) the next item on the
        same level as the parent item of the currently selected item.
        N)r�r#r%r'r�r�rrr�downarrowshiftevent�s
z'curseschunkselector.downarrowshifteventFcsx|j��fdd�}���}|dur4||�s4|��}q|durB�}n |��}|durb|jrb|�|�||_|st|��dS)Ncst|t���Sr+)r}�type�r)�r�rr�<lambda>r7z2curseschunkselector.nextsametype.<locals>.<lambda>)r�r(r%r&�togglefoldedr�)rr�Zsametyper(�parentrr�r�nextsametype	s

z curseschunkselector.nextsametypecCs4|j}|��}|jr|�|�|dur*|}||_dS)zL
        select (if possible) the first of this item's child-items.
        N)r�r r&r�r�rrr�rightarrowevents
z#curseschunkselector.rightarroweventcCsV|j}t|t�s&|js&|j|d�dS|��}|durL|}|jsL|j|d�||_dS)z�
        if the current item can be folded (i.e. it is an unfolded header or
        hunk), then fold it.  otherwise try select (if possible) the parent
        of this item.
        r�N)r�r}rSr&r�r%r�rrr�leftarrowevent-s
z"curseschunkselector.leftarroweventcCsJ|j}t|t�r&|js&|j|d�dS|��}|dur:q@q&|}q&||_dS)z
        select the header of the current item (or fold current item if the
        current item is already a header).
        r�N)r�r}r0r&r�r%r�rrr�leftarrowshifteventFs
z'curseschunkselector.leftarrowshifteventcCsh|j}|j}|j}||j|jd}|d}|d}||krN|�||�n||krd|�||�dS)z6scroll the screen to fully show the currently-selectedrrZN)r�r�r��yscreensizer��scrolllines)rZselstartZselendZpadstartZpadendZpadstartbufferedZpadendbufferedrrr�updatescroll\sz curseschunkselector.updatescrollcCs>|j|7_|jdkrd|_|j|jdkr:|jd|_dS)z>scroll the screen up (down) by numlines when numlines >0 (<0).rrN)r�r�)r�numlinesrrrr�ns

zcurseschunkselector.scrolllinescCs |dur|j}||_|j|_t|t�r�d|_|jrZ|jD]}d|_|jD]
}d|_qJq:n*|jD]"}d|_d|_|jD]
}d|_qvq`�n�t|t��r(d|_|jD]}|j|_q�dd�|j	jD�}d|v}d|v}dd�|j	jD�}d|v}|�r|j	�
��s&d|j	_d|j	_nd|j	_|�p ||j	_n�t|t��rdd�|jjD�}d|v}d|v}|�rnd|j_d|j_n(|�r�d|j_d|j_nd|j_d|j_dd�|jj	jD�}	d|	v}
d|	v}d	d�|jj	jD�}d|v}
|
�r|jj	�
��sd|jj	_d|jj	_nd|jj	_|
�p||jj	_dS)
z�
        toggle the applied flag of the specified item.  if no item is specified,
        toggle the flag of the currently selected item.
        NFTcSsg|]
}|j�qSrr��r4r�rrrr6�r7z3curseschunkselector.toggleapply.<locals>.<listcomp>cSsg|]
}|j�qSr�r:r�rrrr6�r7cSsg|]
}|j�qSrr�)r4Zlnrrrr6�r7cSsg|]
}|j�qSrr�r�rrrr6�scSsg|]
}|j�qSrr�r�rrrr6�s)
r�r�r9r}r0r:r<rWr2r.r�rSrV)rr)r��hunklineZsiblingappliedstatusZallsiblingsappliedZnosiblingsappliedZsiblingspartialstatusZsomesiblingspartialZparentsiblingsappliedZnoparentsiblingsappliedZallparentsiblingsappliedZparentsiblingspartialZsomeparentsiblingspartialrrr�toggleapplyvsx









�

��


�zcurseschunkselector.toggleapplycCsN|jr$|jD]}|jr|�|�qn|jD]}|js*|�|�q*|j|_dS)z%toggle the applied flag of all items.N)r�r-r9r�)rr)rrr�	toggleall�s

zcurseschunkselector.toggleallcCs6|jD]*}|��D]}|��D]}|�|�qqqdS)z`
        Flip all selections. Every selected line is unselected and vice
        versa.
        N)r-r"r�)rr.rVr\rrr�flipselections�s
z"curseschunkselector.flipselectionscCs�|jr|j|jkr|��dS|j}|j}dD]4}|��}|rP||krP|��}q:|rXqd||}}q.|sldS|}|jj}||��kr�|j|kr�|j|d�|��}qzdS)zOtoggle applied on or off for all items in range [lastapplied,
        current].N)sforwardsreverser�)r�r�r�r(r9)rZ	startitemZenditem�	directionr(Zdesiredstaterrr�toggleallbetween�s.�
�


z$curseschunkselector.toggleallbetweencCs�|dur|j}|s"t|t�rj|jrjt|t�s<|��|_}n|jrHd|_t|t�rj|��D]}|j|_qZt|ttf�r�|j|_dS)zMtoggle folded flag of specified item (defaults to currently
        selected)NF)r�r}r0r;r%r"r&r2)rr)�
foldparent�childrrrr�s

z curseschunkselector.togglefoldedcCsB|��\}}|j}|�d�}t�|�}||||}|d|S)z�
        add whitespace to the end of a string in order to make it fill
        the screen in the x direction.  the current cursor position is
        taken into account when making this calculation.  the string can span
        multiple lines.
        �rk)�getyx�xscreensize�
expandtabsr�colwidth)rZinstr�window�y�xstart�widthZstrwidthZ	numspacesrrr�alignstring(s

zcurseschunkselector.alignstringTcCs�|�d�}t�ddd�|�d��}|dur0|}nV|durD|j|}nB|durPd}|dur\d}||f|jvrz|j||f}n|�||�}|dur�g}|dkr�|D]}||O}q�n"tjtj	fD]}||vr�||O}q�|j
��\}
}d	}|
�r
t|�}|�
d
�}t|�}||}|�r"|�t�|�|�||7}|
�rj|tjB}|�r^t|�D]}|�tj|��qH|d|7}|	�r�|�r�|�d	|�}|�||�n|�||�}||7}|t|�|j}|j|7_|S)a
        print the string, text, with the specified colors and attributes, to
        the specified curses window object.

        the foreground and background colors are of the form
        curses.color_xxxx, where xxxx is one of: [black, blue, cyan, green,
        magenta, red, white, yellow].  if pairname is provided, a color
        pair will be looked up in the self.colorpairnames dictionary.

        attrlist is a list containing text attributes in the form of
        curses.a_xxxx, where xxxx can be: [bold, dim, normal, standout,
        underline].

        if align == True, whitespace is added to the printed string such that
        the string stretches to the right border of the window.

        if showwhtspc == True, trailing whitespace of a string is highlighted.
        r�s[\x00-\x08\x0a-\x1f]cSsdt�tt|���d��S)N�^�@)rZsysbytes�chr�ord�group��mrrrr�[r7z1curseschunkselector.printstring.<locals>.<lambda>�
NrN�r7s 
rk)r��re�sub�stripr�r��getcolorpairr�A_UNDERLINE�A_BOLD�chunkpadr�rEr�ZaddstrrZstrfromlocal�	A_REVERSE�rangeZaddchZACS_CKBOARDr�r�r�)rr�ry�fgcolor�bgcolor�pair�pairname�attrlist�towin�align�
showwhtspc�	colorpair�textattrr�r��tZoriglenZstrippedlenZnumtrailingspacesZwscolorpair�iZextrawhitespaceZlinesprintedrrr�printstring7sd 
�


zcurseschunkselector.printstringc	Csp|jj}td�}td�}tt|�t|��}d||r6|n|f}t|jdtd�td�td�td�|td	�g}|S)
z-> [str]. return segmentssspace/enter: selectsspace/enter: deselects%-*srhs[x]=selected **=collapseds
c: confirmsq: aborts arrow keys: move/expand/collapses?: help)r�r9r�maxrEr�r)r�selectedZspaceselectZ
spacedeselectZspacelenZ
selectedlabel�segmentsrrr�_getstatuslinesegments�s$
��
z*curseschunkselector._getstatuslinesegmentscs��jdur�jtd�g}n����}�j}g}|}|D]n}t�|�}dd|oT|ddv}||t|�|kr~|�|�|}q4|d||7<||t|�7}q4t|��jkr�t|��_�j	�
�j�j��fdd	�|D�S)
z<() -> [str]. return short help used in the top status windowNsPress any key to continuerkrrs-[rNcsg|]}t�|�jd��qS)r)rZellipsisr�rfrrrr6�r7z7curseschunkselector._getstatuslines.<locals>.<listcomp>)r�rr
r�rr�rErur��	statuswin�resize)r�linesr	r�Z	lastwidth�s�w�seprrr�_getstatuslines�s$



z#curseschunkselector._getstatuslinesc	Cs�|j��|j��|j}z,|��D]}||j|dd�q$|j��WntjyZYn0|jdurjdSz<|�	�|�
�|j�|jd|jd|j
|j|jd�Wntjy�Yn0dS)N�legend�r�rr)rZeraser�rrr�rr	r��	printitemr�r�r�r�r�)rrr\rrr�updatescreen�s0



�z curseschunkselector.updatescreencCs�|jr"t|t�s|jrd}q&d}nd}zJ|jrT|d7}t|t�rn|j}||d7}n|d7}t|t�rn|d7}Wnty�|d7}Yn0|S)zx
        create a string to prefix a line with which indicates whether 'item'
        is applied and/or folded.
        s[~]s[x]s[ ]s**rks  )r9r}rSr:r&r0Z
changetyper')rr)�checkboxZ
filestatusrrr�getstatusprefixstring�s"

z)curseschunkselector.getstatusprefixstringcCsd}|��}|j�|�}|dkrD|jsD||j|jd|j|dd�7}|j|rPdpRdtj	gd�}d}	|�
|�}
|jrv|r�|�d	�}|
|d}n|
|��}||j|j|||d
�7}|jr�|�r
t
|�dk�r
|dd�D]0}
d
|	t
|
�|
}||j|j|||d
�7}q�|S)z�
        print the header to the pad.  if countlines is True, don't print
        anything, but just count the number of lines which would be printed.
        r7r�_F�r�r�selected�normal�rQr�r��r�r�rNrk)rCr�rFr&rr�r�r�rr�r�splitr{rE)rr.rr��
ignorefolding�outstrryZ
chunkindexrZindentnumcharsrZtextlist�linestrr\rrr�printheaders6��



�
�
zcurseschunkselector.printheaderc
Cs�d}|jj�|�}|dkr8||j|jd|j|dd�7}|j|rDdpFdtjgd�}|�	|�}d|j
|}	d	|���d
�}
||j|j|	|dd�7}||j|j|
||d�7}|j
r�|s�|S|jD]0}d|jt|�|}||j|j||d�7}q�|S)
z!includes start/end line indicatorr7rrkFrrrrs   r�r�r�)r.r<rFrr�r�r�rr�rr�rsr�r&rlr�rE)
rrVrr�rr Z	hunkindexrr�
lineprefixZfrtoliner\r!rrr�printhunklinesbefore9s2��

�
�

�z(curseschunkselector.printhunklinesbeforecCsXd}|jr|s|S|�|�}|jD]0}d|jt|�|}||j|j||d�7}q"|S)Nr7rkr#)r&rrmr�rErr�)rrVr�rr rr\r!rrr�printhunklinesafteres


�z'curseschunkselector.printhunklinesafterc	Cs�d}|�|�}|���d�}|r.|jdd�}nF|�d�rF|jdd�}n.|�d�r^|jdd�}n|�d	�rt|jd
d�}d|j|}||j|j||dd
�7}||j|j|||dd�7}|S)Nr7r�r�rQrc�additionrh�deletion�\rrkFrT)r�r�r)rrCr�r�rer�rr�)	rr�rr�r rr!rr$rrr�printhunkchangedlinets&




��z(curseschunkselector.printhunkchangedlinecCs:|dur|j}|rd|_g}|j|||||d�d�|�S)z�
        use __printitem() to print the the specified item.applied.
        if item is not specified, then print the entire patch.
        (hiding folded elements, etc. -- see __printitem() docstring)
        Nrr#r7)r-r��_curseschunkselector__printitemrv)rr)r�recursechildrenr�r rrrr�s	
�zcurseschunkselector.printitemcCs@|j��\}}td|j|j�}|j|jd}||kp>||kS)Nr�)r�r��minr�r�)rr�rZminyZmaxyrrr�outofdisplayedarea�sz&curseschunkselector.outofdisplayedareacCs<||ju}|r8|r8|j|_|j|dd�}|j|d|_|S)NF�r-r)r�r�r��getnumlinesdisplayedr�)rr)r-rZselecteditemlinesrrr�handleselection�s
��z#curseschunkselector.handleselectionc
Cs*|r|��rdS|�||�}t|t�rF|rF|D]}|�|||||�q.t|t�r�|�|j||||d��|r�|jD]}|�|||||�qrn�t|t	�r�|j
jr�|r�|�|j||||d��|r�|j
D]}	|�|	||||�q�|�|j|||d��n2t|t��r&|jj�r|�r&|�|j|||d��|S)a{
        recursive method for printing out patch/header/hunk/hunk-line data to
        screen.  also returns a string with all of the content of the displayed
        patch (not including coloring, etc.).

        if ignorefolding is True, then folded items are printed out.

        if recursechildren is False, then only print the item without its
        child items.
        N)r�rr#)r0r3r}r
r,r0rur"r<r2r.r&r%rWr&rSrVr+)
rr)rr-r r�rr�r�rgrrrZ__printitem�sb

�
��

�
����

������zcurseschunkselector.__printitemcCs$|j|||dd�}t|�|j}|S)aY
        return the number of lines which would be displayed if the item were
        to be printed to the display.  the item will not be printed to the
        display (pad).
        if no item is given, assume the entire patch.
        if ignorefolding is True, folded items will be unfolded when counting
        the number of lines.
        Fr#)rrEr�)rr)rr-Zpatchdisplaystringr�rrrr2�s

�z(curseschunkselector.getnumlinesdisplayedcCspzVt��t�|j�\|_|_|j�|j	|j�|j
dd�d|_t�|j|j�|_
WntjyjYn0dS)zhandle window resizingT�rrN)r�endwinrZtermsizerr�r�rrr�r2r��newpadr�r	)r�n�framerrr�sigwinchhandlersz#curseschunkselector.sigwinchhandlerc
Cs2|dur||jvr|j|}n�|dur*d}|dur6d}||f|jvrT|j||f}n�t|j�d}|jr�t�|||�t�|�}|j||f<|dur�t�|�|j|<n6d}|dur�|dkr�tj}||j|<|}|j||f<|dur�g}|dk�r|D]}||O}q�n&tjtj	fD]}	|	|v�r||	O}�q|S)a�
        get a curses color pair, adding it to self.colorpairs if it is not
        already defined.  an optional string, name, can be passed as a shortcut
        for referring to the color-pair.  by default, if no arguments are
        specified, the white foreground / black background color-pair is
        returned.

        it is expected that this function will be used exclusively for
        initializing color pairs, and not curses.init_pair().

        attrlist is used to 'flavor' the returned color-pair.  this information
        is not stored in self.colorpairs.  it contains attribute values like
        curses.A_BOLD.
        NrNrrrr�)
r�r�rEr�rZ	init_pairZ
color_pairr�r�r�)
rr�r�rQr�rZ	pairindexZcvalrZ
textattribrrrr�s@��


z curseschunkselector.getcolorpaircOs|j|i|��dS)zsame as getcolorpair.N)r�)rr�r�rrr�
initcolorpairRsz!curseschunkselector.initcolorpaircCs�td�}t�|jddd�}|�d�}|dg|j|jt|�d}z|D]}|j||dd�qLWntjyxYn0|�	�z8|j
�d��|��Wd	�n1s�0YWntjy�Yn0d	S)
z<print a help window to the screen.  exit after any keypress.s            [press any key to return to the patch-display]

The curses hunk selector allows you to interactively choose among the
changes you have made, and confirm only those changes you select for
further processing by the command you are running (such as commit,
shelve, or revert). After confirming the selected changes, the
unselected changes are still present in your working copy, so you can
use the hunk selector multiple times to split large changes into
smaller changesets. the following are valid keystrokes:

              x [space] : (un-)select item ([~]/[x] = partly/fully applied)
                [enter] : (un-)select item and go to next item of same type
                      A : (un-)select all items
                      X : (un-)select all items between current and most-recent
    up/down-arrow [k/j] : go to previous/next unfolded item
        pgup/pgdn [K/J] : go to previous/next item of same type
 right/left-arrow [l/h] : go to child item / parent item
 shift-left-arrow   [H] : go to parent header / fold selected header
                      g : go to the top
                      G : go to the bottom
                      f : fold / unfold item, hiding/revealing its children
                      F : fold / unfold parent item and all of its ancestors
                 ctrl-l : scroll the selected line to the top of the screen
                      m : edit / resume editing the commit message
                      e : edit the currently selected hunk
                      a : toggle all selections
                      c : confirm selected changes
                      r : review/edit and confirm selected changes
                      q : quit without confirming (no changes will be made)
                      ? : help (what you're currently reading)rr�rkrrr�crecordN)
rr�newwinr�rr�rErr	r�r�timeblockedsection�getkey)rZhelptextZhelpwinZ	helplinesr\rrr�
helpwindowVs&�!
�*zcurseschunkselector.helpwindowcCsRt��t��t��|j�|j|j���|_t��|j	�
�|j	�d�dS)z?Create a temporary commit message editing window on the screen.rN)r�rawZ
def_prog_moder5r�editr��usernameZcbreakr�r��keypadrrrr�commitMessageWindow�s
z'curseschunkselector.commitMessageWindowcCs6|jd|_|j}|��}|dur&q,q|}q||_dS)zT
        Handle 'g' to navigate to the top most file in the ncurses window.
        rN)r-r�r%r�rrr�handlefirstlineevent�sz(curseschunkselector.handlefirstlineeventcCsB|j}|��}|dur0|��}|dur*q0q|}q||_|��dS)a�
        Handle 'G' to navigate to the bottom most file/hunk/line depending
        on the whether the fold is active or not.

        If the bottom most file is folded, it navigates to that file and
        stops there. If the bottom most file is unfolded, it navigates to
        the bottom most hunk in that file and stops there. If the bottom most
        hunk is unfolded, it navigates to the bottom most line in that hunk.
        N)r�r(r�r�rrr�handlelastlineevent�s
z'curseschunkselector.handlelastlineeventcCs�t�|jddd�}z(|�d�}|D]}|j||dd�q"WntjyNYn0|j��|��z>|j�	d��t
|j���}Wd�n1s�0YWnty�d}Yn0|S)zMdisplay an informational window, then wait for and return a
        keypress.rr�rrr;N)
rr<r�rrr	r�r�rr=r�Zgetch�
ValueError)rZ
windowtextZ
confirmwinr
r\�responserrr�confirmationwindow�s

0
z&curseschunkselector.confirmationwindowcCsdtd�}|j�d��|�|�}Wd�n1s40Y|durJd}|���d�r\dSdSdS)zPask for 'y' to be pressed to confirm selected. return True if
        confirmed.s�If you answer yes to the following, your currently chosen patch chunks
will be loaded into an editor. To modify the patch, make the changes in your
editor and save. To accept the current patch as-is, close the editor without
saving.

note: don't add/remove lines unless you also modify the range information.
      failing to follow this rule will result in the commit aborting.

are you sure you want to review/edit and confirm the selected changes [yn]?
r;Nr7r�TF)rrr=rI�lowerre)rZconfirmtextrHrrr�reviewcommit�s�(z curseschunkselector.reviewcommitcCs|jdd�|��dS)a
        once we scrolled with pg up pg down we can be pointing outside of the
        display zone. we print the patch with towin=False to compute the
        location of the selected item even though it is outside of the displayed
        zone and then update the scroll.
        Fr#N)rr�rrrrr��sz)curseschunkselector.recenterdisplayedareacs�dd�}dd�}|dur|j}t|t�r,dSt|t�r>|��}t|t�sLdS|��j�|�}|j|j	}}|||�}|dur�|s�||�dS|j
��j�|�}	�jd|	�}
�j|	dd�}|d}�fdd	�|jD�}
td
d	�|
D��}tdd	�|
D��}||||}|D]}|j|7_�q|
D]}d|_
�q,|
|
|�_|���rb|
|g|�_�|_t�j�|k�r��j||_|�s�||�dS)
z3
        edit the currently selected chunk
        cSsP|jdd�d|_t�|j|j�|_|��|j��|j	��|j�
d�dS)NTr4r)r2r�rr6r�r�r�r�r�rrCrrrr�updateui�s

z0curseschunkselector.toggleedit.<locals>.updateuic
Ss*|dur(|j�td��|j�d�dS|j��rR|j�td��|j�d�dSt�}|�tt�|j�|�|�|�zzz|jj|�	�ddd�}WnFt
jy�}z,|j|_
WYd}~W|j��|j��dSd}~00W|j��|j��n|j��|j��0dd�|��D�}t�|�S)	Ns cannot edit patch for whole filer�s!cannot edit patch for binary filer7sdiff)�actioncSsg|]}|�d�s|d�qS)�#r�)rer[rrrr6s
�zOcurseschunkselector.toggleedit.<locals>.editpatchwitheditor.<locals>.<listcomp>)rrtrr.Zbinaryr>�diffhelptext�hunkhelptextrAr@r	�Abort�messager�r�r�r��
splitlinesrxZ
parsepatch)r�chunkr
�excrrr�editpatchwitheditors8



�
�
�z;curseschunkselector.toggleedit.<locals>.editpatchwitheditorNrrcsg|]}t|���qSrr1r3rarrr69r7z2curseschunkselector.toggleedit.<locals>.<listcomp>cSsg|]
}|j�qSr)ror3rrrr6:r7cSsg|]
}|j�qSr)r^r3rrrr6;r7F)r�r}r0rSr%r2r<rFror^r.�sumrqr&�
emptypatchrE)rr)r�rLrVZ	itemindexZbeforeaddedZ
beforeremovedZ
newpatchesZeditedhunkindexZhunksbeforeZ
hunksafterZnewpatchheaderZnewhunksZnewaddedZ
newremoved�offsetr5rrar�
toggleedit�sL"





zcurseschunkselector.toggleeditcCs(|j}|sdS|D]}|jrdSqdSrT)r-r<)rr)r.rrrrXLszcurseschunkselector.emptypatchcCsF|dvr|���n.|dvr(|���n|dvr<|���n|dvrP|���n�|dvrd|���n�|dvrx|���n�|dvr�|���n�|dvr�t�t	d	����n�|d
vr�|�
��n�|dvr�dS|d
vr�|��r�d|jd<dS�nZ|�r|dv�rd|jd<dS|dv�r|�
��n&|dv�r>|�
�|j|d��n|dv�rR|��n�|dv�rf|��n�|dv�r~|j|d�n�|dv�r�|��n�|dv�r�|jdd�n�|dv�r�|��n�|dv�r�|��np|dv�r�|��n\|dv�r|��|j��|j��n4|tj�d�fv�rB|�|j�|j��|j��dS)zd
        Perform actions based on pressed keys.

        Return true to exit the main loop.
        )�kZKEY_UP)�KZ	KEY_PPAGE)�jZKEY_DOWN)�JZ	KEY_NPAGE)rgZ	KEY_RIGHT)r5ZKEY_LEFT)�HZ	KEY_SLEFT)�qs	user quit)�a)r~T)�rsreview)�R)� rB)r�Z	KEY_ENTERr�)�X)�A)�e)r�)�F)r�r�)�gZKEY_HOME)�GZKEY_END)�?�LN)r�r�r�r�r�r�r�r	Z
CanceledErrorrr�rKr�r�r�r�r�rZr�rDrErFr?r�r�r�r�asciiZctrlr�r�)r�
keypressedr�rrrr�Usp




















z$curseschunkselector.handlekeypressedc
Csht�}}t�td�r&t�tj|j�}z$|�|�W||urHt�tj|�Sn||urbt�tj|�0dS)zP
        method to be wrapped by curses.wrapper() for selecting chunks.
        sSIGWINCHN)r�r
r�r��SIGWINCHr9�_main)rr�Zorigsigwinchr�rrrr��s

��zcurseschunkselector.maincCs,||_d|_|j��\|_|_t��zt��WntjyLd|_	Yn0|j�
�zt�d�WntjyzYn0|jdddd�|jtj
tjdd�|jtjddd�|jtjddd�|jtj
tjdd�t�|jddd�|_|j�d	�t�d	|j�|_|jd
d�d	|_zt�|j|j�|_Wn&tj�yVttd��|_YdS0|j|jdd
�|_|��zT|j� d��|j�!�}Wd�n1�s�0Y|j"du�r�d|_"W�qjWntj�y�d}Yn0|�#|��rj�q��qj|j$dk�r(t%�&dd|j$�}|dk�r(|j$|j'd<dS)NFrrr'rr)r(rrTr4s&this diff is too large to be displayedr1r;sfoobarr7s(?m)^\s.*(\n|$)smessage)(r�r�Zgetmaxyxr�r�rZstart_colorZuse_default_colorsr	r�r�Zcurs_setr:ZCOLOR_WHITEZ
COLOR_MAGENTAZ	COLOR_REDZCOLOR_GREENZ
COLOR_BLUEr<r�rrCr6r�r2r�rrr�r�rrr=r>r�r�r�r�r�r�)rr�rnZwhitespaceremovedrrrrp�sj

�
���*

�
zcurseschunkselector._main)N)F)N)NF)NNNNNTTF)FTF)FTF)TF)FT)NFTT)T)NFT)NNNN)NF)F)1rrrr/r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rr
rrrr"r%r&r+rr0r3r,r2r9r�r:r?rDrErFrIrKr�rZrXr�r�rprrrrr�xsx
B

^
*
�
e"�
.�
,

�
	�
C�
�
;4

Y	
Ar�)N)N)N)+Z
__future__rr�r�r�Zi18nrrrr�rrr	r
rxrr
Zutilsrr>rOrPZ
patchhelptextrZcurses.ascii�ImportErrorr'rQrrr�rr�r0rSr2r�r�r�r�r�r�rrrr�<module>sR$	��
�

	kN2J
#

�

Youez - 2016 - github.com/yon3zu
LinuXploit