
    .PhL                     \   d Z ddlmZ ddlmZ ddlmZ ddlZddlm	Z	m
Z
 dZg d	Zd
ZdZdZdZdZd
ZdZd
ZdZdZdZdZdZdZdZdZdZdZdZdZ dZ!dZ"dZ#dZ$dZ%dZ&dZ'dZ(d Z)d!Z*d"Z+d#Z,d$Z-e e$e%e'egZ. e/g e.e&eeeee(e#eee)e*e+          Z0 e/g e.e"ee!e          Z1d%Z2d&Z3d' Z4d( Z5d) Z6d* Z7d+ Z8d, Z9d-Z:dZ;d.Z<d/Z=d0Z>d1Z?d2 Z@d3 ZAd4 ZBd5 ZCd6 ZD G d7 d8          ZEd9ZF G d: d;eE          ZGd< ZHd= ZId> ZJ G d? d@          ZK G dA dB          ZLdC ZMdIdDZNdE ZOdF ZPdJdHZQdS )Kz<Generic functions for talking the git smart server protocol.    )BytesIO)SEEK_END)OptionalN   )GitProtocolErrorHangupExceptioni$  )r   r      r	   s(   0000000000000000000000000000000000000000   s   atomics   deepen-sinces
   deepen-nots   deepen-relatives   delete-refss   include-tag	   multi_ack   multi_ack_detaileds   no-dones   no-progresss	   ofs-deltas   quiets   report-statuss   shallows	   side-bands   side-band-64ks	   thin-packs   agents   symrefs   allow-tip-sha1-in-wants   allow-reachable-sha1-in-wants   fetchs   filters   capabilities^{}is   NAK
c                      dd                     t          t          t          j                            z                       d          S )Nzdulwich/.ascii)joinmapstrdulwich__version__encode     P/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/dulwich/protocol.pyagent_stringr      s4    #c7+>"?"?@@@HHQQQr   c                  4    t           dz   t                      z   S )N   =)CAPABILITY_AGENTr   r   r   r   capability_agentr      s    d"\^^33r   c                 (    t           dz   | z   dz   |z   S )Nr      :)CAPABILITY_SYMREF)from_refto_refs     r   capability_symrefr#      s    t#h.5>>r   c                     d | D             S )Nc                 8    h | ]}t          |          d          S )r   )parse_capability.0cs     r   	<setcomp>z+extract_capability_names.<locals>.<setcomp>   s&    999qQ"999r   r   capabilitiess    r   extract_capability_namesr-      s    99L9999r   c                     |                      dd          }t          |          dk    r
|d         d fS t          |          S )Nr   r   r   )splitlentuple)
capabilitypartss     r   r&   r&      sA    T1%%E
5zzQa$<<r   c                     d | D             S )Nc                      g | ]}t          | S r   )r#   )r(   ks     r   
<listcomp>z'symref_capabilities.<locals>.<listcomp>   s    333aq!333r   r   )symrefss    r   symref_capabilitiesr9      s    3373333r   s   deepens	   unshallows   dones   wants   havec                 L    | dz   d                     d |D                       z   S )N    r   c                     g | ]}|d z   S )    r   )r(   as     r   r7   z"format_cmd_pkt.<locals>.<listcomp>   s    !<!<!<!1u9!<!<!<r   r   )cmdargss     r   format_cmd_pktrB      s,    :!<!<t!<!<!<====r   c                     |                      d          }| d |         | |dz   d          }}|dd          dk    sJ ||d d                             d          fS )Nr;   r   r=   )findr/   )line	splice_atr@   rA   s       r   parse_cmd_pktrH      sh    		$IZiZ $y1}"7C9SbS	&&&&r   c                 `    | dS dt          |           dz   z                      d          | z   S )zWrap data in a pkt-line.

    Args:
      data: The data to wrap, as a str or None.
    Returns: The data prefixed with its length in pkt-line format; if data was
        None, returns the flush-pkt ('0000').
    Ns   0000z%04x   r   )r0   r   )datas    r   pkt_linerL      s6     |wc$ii!m$,,W55<<r   c                  `    d                     d | D                       t          d          z   S )z`Wrap a sequence of data in pkt-lines.

    Args:
      seq: An iterable of strings to wrap.
    r   c                 ,    g | ]}t          |          S r   )rL   )r(   ss     r   r7   zpkt_seq.<locals>.<listcomp>   s    ...QXa[[...r   N)r   rL   )seqs    r   pkt_seqrQ      s0     88..#...//(4..@@r   c                 D    fd|                                  D             S )zFilter refs to only include those with a given prefix.

    Args:
      refs: A list of refs.
      prefix: The prefix to filter by.
    c                 T    i | ]#\  }t          fd D                        |$S )c              3   B   K   | ]}                     |          V  d S N)
startswith)r(   pr6   s     r   	<genexpr>z/filter_ref_prefix.<locals>.<dictcomp>.<genexpr>   s-      0S0SQa0S0S0S0S0S0Sr   )any)r(   vr6   prefixess     @r   
<dictcomp>z%filter_ref_prefix.<locals>.<dictcomp>   sB    TTTTQS0S0S0S0S(0S0S0S-S-STAqTTTr   )items)refsr[   s    `r   filter_ref_prefixr_      s(     UTTTTZZ\\TTTTr   c                   n    e Zd ZdZdddZddZd Zd Zd Zde	fd	Z
dd
Zd ZddZddZddZd ZdS )Protocola  Class for interacting with a remote git process over the wire.

    Parts of the git wire protocol use 'pkt-lines' to communicate. A pkt-line
    consists of the length of the line as a 4-byte hex string, followed by the
    payload data. The length includes the 4-byte header. The special line
    '0000' indicates the end of a section of input and is called a 'flush-pkt'.

    For details on the pkt-line format, see the cgit distribution:
        Documentation/technical/protocol-common.txt
    Nreturnc                 L    || _         || _        || _        || _        d | _        d S rU   )readwrite_closereport_activity
_readahead)selfrd   re   closerg   s        r   __init__zProtocol.__init__   s*    	
.-1r   c                 @    | j         r|                                   d S d S rU   )rf   ri   s    r   rj   zProtocol.close   s'    ; 	KKMMMMM	 	r   c                     | S rU   r   rm   s    r   	__enter__zProtocol.__enter__   s    r   c                 .    |                                   d S rU   )rj   )ri   exc_typeexc_valexc_tbs       r   __exit__zProtocol.__exit__   s    

r   c                 B   | j         | j        }n| j         j        }d| _         	  |d          }|st          t          |d          }|dk    s|dk    r| j        r|                     dd           dS | j        r|                     |d            ||dz
            }t          |          dz   |k    r't          dt          |          dz   dd	|d          |S # t          $ r}t          |d}~wt          $ r"}t          t          |                    |d}~ww xY w)
a  Reads a pkt-line from the remote git process.

        This method may read from the readahead buffer; see unread_pkt_line.

        Returns: The next string from the stream, without the length prefix, or
            None for a flush-pkt ('0000') or delim-pkt ('0001').
        NrJ      r   r   rd   zLength of pkt read 04xz does not match length prefix )
rh   rd   r   intrg   r0   r   ConnectionResetErrorOSErrorr   )ri   rd   sizestrsizepkt_contentsexcs         r   read_pkt_linezProtocol.read_pkt_line   sn    ?"9DD?'D"DO	 d1ggG &%%w##DqyyDAII' 4((F333t# 3$$T62224q>>L <  1$,,&m#l*;*;a*?mmmcgmmm     $ 	+ 	+ 	+!s* 	6 	6 	6"3s88,,#5	6s*   AC 3+C 
D'C//D<DDc                 ~    	 |                                  }n# t          $ r Y dS w xY w|                     |           dS )zTest whether the protocol stream has reached EOF.

        Note that this refers to the actual stream EOF and not just a
        flush-pkt.

        Returns: True if the stream is at EOF, False otherwise.
        TF)r   r   unread_pkt_line)ri   	next_lines     r   eofzProtocol.eof  sU    	**,,II 	 	 	44	Y'''us    
%%c                 t    | j         t          d          t          t          |                    | _         dS )a>  Unread a single line of data into the readahead buffer.

        This method can be used to unread a single pkt-line into a fixed
        readahead buffer.

        Args:
          data: The data to unread, without the length prefix.

        Raises:
          ValueError: If more than one pkt-line is unread.
        Nz'Attempted to unread multiple pkt-lines.)rh   
ValueErrorr   rL   ri   rK   s     r   r   zProtocol.unread_pkt_line"  s4     ?&FGGG!(4..11r   c              #   n   K   |                                  }|r|V  |                                  }|dS dS )zRead a sequence of pkt-lines from the remote git process.

        Returns: Yields each line of data up to but not including the next
            flush-pkt.
        N)r   )ri   pkts     r   read_pkt_seqzProtocol.read_pkt_seq2  sY         "" 	'III$$&&C  	' 	' 	' 	' 	'r   c                    	 t          |          }|                     |           | j        r%|                     t          |          d           dS dS # t          $ r"}t          t          |                    |d}~ww xY w)zSends a pkt-line to the remote git process.

        Args:
          line: A string containing the data to send, without the length
            prefix.
        re   N)rL   re   rg   r0   rz   r   r   )ri   rF   r~   s      r   write_pkt_linezProtocol.write_pkt_line=  s    	6D>>DJJt# 9$$SYY888889 9 	6 	6 	6"3s88,,#5	6s   AA 
B A;;B c                     |rI|                      t          t          |g                    |dd         z              |dd         }|GdS dS )zWrite multiplexed data to the sideband.

        Args:
          channel: An int specifying the channel to write to.
          blob: A blob of data (as a string) to send on this channel.
        N  )r   bytes	bytearray)ri   channelblobs      r   write_sidebandzProtocol.write_sidebandL  sj      	 i	&:&: ; ;d6E6l JKKK<D  	  	  	  	  	 r   c                 F    |                      t          |g|R             dS )zSend a command and some arguments to a git server.

        Only used for the TCP git protocol (git://).

        Args:
          cmd: The remote service to access.
          args: List of arguments to send to remove service.
        N)r   rB   )ri   r@   rA   s      r   send_cmdzProtocol.send_cmdZ  s.     	N3666677777r   c                 H    |                                  }t          |          S )zRead a command and some arguments from the git client.

        Only used for the TCP git protocol (git://).

        Returns: A tuple of (command, [list of arguments]).
        )r   rH   )ri   rF   s     r   read_cmdzProtocol.read_cmde  s#     !!##T"""r   )NNrb   N)__name__
__module____qualname____doc__rk   rj   ro   rt   r   boolr   r   r   r   r   r   r   r   r   r   ra   ra      s       	 	2 2 2 2 2       #  #  # JT    2 2 2 2 	' 	' 	'6 6 6 6       	8 	8 	8 	8# # # # #r   ra   i    c                   :     e Zd ZdZddef	 d fdZd Zd Z xZS )ReceivableProtocola  Variant of Protocol that allows reading up to a size without blocking.

    This class has a recv() method that behaves like socket.recv() in addition
    to a read() method.

    If you want to read n bytes from the wire and block until exactly n bytes
    (or EOF) are read, use read(n). If you want to read at most n bytes from
    the wire but don't care if you get less, use recv(n). Note that recv(n)
    will still block until at least one byte is read.
    Nrb   c                     t                                          | j        |||           || _        t	                      | _        || _        d S )N)rj   rg   )superrk   rd   _recvr   _rbuf	_rbufsize)ri   recvre   rj   rg   rbufsize	__class__s         r   rk   zReceivableProtocol.__init__  sE     	EXXX
YY
!r   c                 H   |dk    sJ | j         }|                                }|                    dt                     |                                |z
  }||k    r|                    |           |                    |          }t                      | _         | j                             |                                           | j                             d           |S t                      | _         	 ||z
  }|                     |          }|snit          |          }||k    r|s|S ||k    r|                    |           ~n3||k    sJ d| d| d            |                    |           ||z  }~|                    |           |                                S )Nr   Tz_recv(z) returned z bytes)	r   tellseekr   rd   r   re   r   r0   )	ri   r|   bufstartbuf_lenrvleftrK   ns	            r   rd   zReceivableProtocol.read  s    axxxx
 j

H((**u$d??HHUOOO$B DJJSXXZZ(((JOOAIYY
	'>D ::d##D D		ADyyy Dyy		$999AtAAAAA999IIdOOOqLG3	6 	xxzzr   c                    |dk    sJ | j         }|                                }|                    dt                     |                                }|                    |           ||z
  }|so|                     | j                  }t          |          |k    r|S t                      }|                    |           |                    d           ~|| _         |	                    |          S )Nr   )
r   r   r   r   r   r   r0   r   re   rd   )ri   r|   r   r   r   r   rK   s          r   r   zReceivableProtocol.recv  s    axxxxj

H((** 
	::dn--D4yyD  ))CIIdOOOHHQKKKDJxx~~r   r   )	r   r   r   r   	_RBUFSIZErk   rd   r   __classcell__)r   s   @r   r   r   s  sw        	 	 "&ti"	" " " " " "; ; ;z      r   r   c                     d| vr| g fS |                                                      d          \  } }| |                                                    d          fS )zExtract a capabilities list from a string, if present.

    Args:
      text: String to extract from
    Returns: Tuple with text with capabilities removed and list of capabilities
    r=   r;   )rstripr/   strip)textr,   s     r   extract_capabilitiesr     s]     DRx,,U33D,,$$&&,,T2233r   c                     |                                                      d          }t          |          dk     r| g fS d                    |dd                   |dd         fS )ax  Extract a capabilities list from a want line, if present.

    Note that want lines have capabilities separated from the rest of the line
    by a space instead of a null byte. Thus want lines have the form:

        want obj-id cap1 cap2 ...

    Args:
      text: Want line to extract from
    Returns: Tuple with text with capabilities removed and list of capabilities
    r;   r
   Nr	   )r   r/   r0   r   )r   
split_texts     r   extract_want_line_capabilitiesr     s`     $$T**J
:RxIIj!n%%z!""~66r   c                 <    d| v rt           S d| v rt          S t          S )z.Extract the ack type from a capabilities list.r   r   )MULTI_ACK_DETAILED	MULTI_ACK
SINGLE_ACKr+   s    r   ack_typer     s*    ,,!!		%	%r   c                   ,    e Zd ZdZdd	dZd	dZd	dZdS )
BufferedPktLineWritera  Writer that wraps its data in pkt-lines and has an independent buffer.

    Consecutive calls to write() wrap the data in a pkt-line and then buffers
    it until enough lines have been written such that their total length
    (including length prefix) reach the buffer size.
    r   rb   Nc                 V    || _         || _        t                      | _        d| _        dS )zInitialize the BufferedPktLineWriter.

        Args:
          write: A write callback for the underlying writer.
          bufsize: The internal buffer size, including length prefixes.
        r   N)_write_bufsizer   _wbuf_buflen)ri   re   bufsizes      r   rk   zBufferedPktLineWriter.__init__  s(     YY
r   c                 p   t          |          }t          |          }| j        |z   | j        z
  }|dk    r<||z
  }| j                            |d|                    |                                  nd}||d         }| j                            |           | xj        t          |          z  c_        dS )z&Write data, wrapping it in a pkt-line.r   N)rL   r0   r   r   r   re   flush)ri   rK   rF   line_lenoverr   saveds          r   re   zBufferedPktLineWriter.write  s    ~~t99|h&6199tOEJT&5&\***JJLLLLEUVV
E

"r   c                     | j                                         }|r|                     |           d| _        t	                      | _         dS )zFlush all data from the buffer.r   N)r   getvaluer   _lenr   r   s     r   r   zBufferedPktLineWriter.flush'  sE    z""$$ 	KK	YY


r   )r   r   )r   r   r   r   rk   re   r   r   r   r   r   r     s_         
 
 
 
 
# # # #     r   r   c                   (    e Zd ZdZddZddZd ZdS )PktLineParserzBPacket line parser that hands completed packets off to a callback.rb   Nc                 :    || _         t                      | _        d S rU   )
handle_pktr   rh   )ri   r   s     r   rk   zPktLineParser.__init__3  s    $!))r   c                 0   | j                             |           | j                                         }t          |          dk     rdS t          |          dk    rt	          |dd         d          }|dk    r |                     d           |dd         }n<|t          |          k    r(|                     |d|                    ||d         }nnt          |          dk    t                      | _         | j                             |           dS )zAParse a fragment of data and call back for any completed packets.rJ   Nrv   r   )rh   re   r   r0   rx   r   r   )ri   rK   r   r|   s       r   parsezPktLineParser.parse7  s   d###o&&((s88a<<F#hh!mms2A2w##Dqyy%%%!""gS!!AdF,,,$%%j #hh!mm "))c"""""r   c                 4    | j                                         S )zRead back any unused data.)rh   r   rm   s    r   get_tailzPktLineParser.get_tailJ  s    '')))r   r   )r   r   r   r   rk   r   r   r   r   r   r   r   0  sQ        LL$ $ $ $# # # #&* * * * *r   r   c                 @    d                     d | D                       S )Nr   c                     g | ]}d |z   S )r;   r   r'   s     r   r7   z*format_capability_line.<locals>.<listcomp>P  s    444!TAX444r   r?   r+   s    r   format_capability_liner   O  s#    8844|444555r   c                 X    ||dz   | z   dz   S |dz   | z   dz   t          |          z   dz   S )Nr;      
r=   )r   )refshar,   s      r   format_ref_liner   S  sD    TzC%''TzC%'*@*N*NNQVVVr   c                     t           dz   | z   S Nr;   )COMMAND_SHALLOWr   s    r   format_shallow_liner   Z  s    T!C''r   c                     t           dz   | z   S r   )COMMAND_UNSHALLOWr   s    r   format_unshallow_liner   ^  s    t#c))r   r   c                 &    |rd|z   }d| z   |z   dz   S )Nr;   s   ACK r   r   )r   r   s     r   format_ack_liner   b  s'     #(?S=8#e++r   rU   )r   )Rr   ior   osr   typingr   r   errorsr   r   TCP_GIT_PORTGIT_PROTOCOL_VERSIONS"DEFAULT_GIT_PROTOCOL_VERSION_FETCH!DEFAULT_GIT_PROTOCOL_VERSION_SENDZERO_SHAr   r   r   SIDE_BAND_CHANNEL_DATASIDE_BAND_CHANNEL_PROGRESSSIDE_BAND_CHANNEL_FATALCAPABILITY_ATOMICCAPABILITY_DEEPEN_SINCECAPABILITY_DEEPEN_NOTCAPABILITY_DEEPEN_RELATIVECAPABILITY_DELETE_REFSCAPABILITY_INCLUDE_TAGCAPABILITY_MULTI_ACKCAPABILITY_MULTI_ACK_DETAILEDCAPABILITY_NO_DONECAPABILITY_NO_PROGRESSCAPABILITY_OFS_DELTACAPABILITY_QUIETCAPABILITY_REPORT_STATUSCAPABILITY_SHALLOWCAPABILITY_SIDE_BANDCAPABILITY_SIDE_BAND_64KCAPABILITY_THIN_PACKr   r    !CAPABILITY_ALLOW_TIP_SHA1_IN_WANT'CAPABILITY_ALLOW_REACHABLE_SHA1_IN_WANTCAPABILITY_FETCHCAPABILITY_FILTERCAPABILITIES_REFCOMMON_CAPABILITIESsetKNOWN_UPLOAD_CAPABILITIESKNOWN_RECEIVE_CAPABILITIESDEPTH_INFINITENAK_LINEr   r   r#   r-   r&   r9   COMMAND_DEEPENr   r   COMMAND_DONECOMMAND_WANTCOMMAND_HAVErB   rH   rL   rQ   r_   ra   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>r     s[  . C B                    5 5 5 5 5 5 5 5 "		 %& "$% !
	      ) % / ' ' #  5  ' #  +  # + #   $= !*I '   &     C	 	 	&	
 	 	  	 	 	 	# 	* 	0 	  " !S	  	 		
 	   R R R4 4 4? ? ?: : :  4 4 4   > > >' ' '
= 
= 
=A A AU U U\# \# \# \# \# \# \# \#~ 	f f f f f f f fR
4 
4 
47 7 7$  ) ) ) ) ) ) ) )X* * * * * * * *>6 6 6W W W W( ( (* * *, , , , , ,r   