HEX
Server: Apache
System: Linux infong-uk86 4.4.400-icpu-106 #2 SMP Mon Sep 15 08:23:40 UTC 2025 x86_64
User: u44115835 (4976590)
PHP: 8.4.17
Disabled: NONE
Upload Files
File: //kunden/lib/python3/dist-packages/dulwich/__pycache__/objects.cpython-39.pyc
a

�~�_з�@s�dZddlZddlmZddlmZddlZddlZddlZddl	m
Z
mZmZm
Z
ddlZddlZddlmZddlmZmZmZmZmZmZmZddlmZd	Zd
ZdZdZd
Z dZ!dZ"dZ#dZ$dZ%dZ&dZ'dZ(dZ)dZ*Gdd�de�Z+dd�Z,dd�Z-dd�Z.d d!�Z/d"d#�Z0d$d%�Z1d&d'�Z2e3e3e4d(�d)d*�Z5d`e6e
e6d+�d,d-�Z7d.d/�Z8d0d1�Z9d2d3�Z:d4d5�Z;d6d7�Z<Gd8d9�d9e=�Z>Gd:d;�d;e=�Z?Gd<d=�d=e?�Z@d>d?�ZAGd@dA�dAe?�ZBGdBdC�dCedCgdD���ZCdadFdG�ZDdHdI�ZEdJdK�ZFdLdM�ZGdNdO�ZHdbdQdR�ZIGdSdT�dTe?�ZJdUdV�ZKdcdWdX�ZLdYdZ�ZMd[d\�ZNGd]d^�d^e?�ZOeOeJe@eBfZPiZQePD]ZReReQeRjS<eReQeRjT<�q`eDZUeFZVzdd_lWmDZDmFZFWneX�y�Yn0dS)dzAccess to base git objects.�N)�BytesIO)�
namedtuple)�Optional�Dict�Union�Type)�sha1)�ChecksumMismatch�NotBlobError�NotCommitError�NotTagError�NotTreeError�ObjectFormatException�FileFormatException)�GitFiles(0000000000000000000000000000000000000000�treesparentsauthors	committersencodingsmergetagsgpgsigsobjectstype�tagstaggeri�l����s-----BEGIN PGP SIGNATURE-----c@seZdZdZdS)�EmptyFileExceptionz+An unexpectedly empty file was encountered.N)�__name__�
__module__�__qualname__�__doc__�rr�1/usr/lib/python3/dist-packages/dulwich/objects.pyrNsrcCst�|�tkS)zhCheck if a mode indicates a submodule.

    Args:
      m: Mode to check
    Returns: a ``boolean``
    )�stat�S_IFMT�S_IFGITLINK)�mrrr�S_ISGITLINKRsrcCs"t��}|�|�}||��7}|S�N)�zlib�
decompressobj�
decompress�flush)�stringZdcompZdcompedrrr�_decompress\s
r%cCs&t�|�}t|�dks"Jd|��|S)z4Takes a string and returns the hex of the sha within�(z#Incorrect length of sha1 string: %d)�binasciiZhexlify�len)�sha�hexsharrr�
sha_to_hexcs
r+c
Csht|�dksJd|��zt�|�WStyb}z&t|t�s@�t|jd��WYd}~n
d}~00dS)z(Takes a hex sha and returns a binary shar&zIncorrect length of hexsha: %srN)r(r'�	unhexlify�	TypeError�
isinstance�bytes�
ValueError�args)�hex�excrrr�
hex_to_shajs
r4c	CsBt|�dkrdSzt�|�Wnttjfy8YdS0dSdS)Nr&FT)r(r'r,r-�Error)r2rrr�valid_hexshausr6cCsBt|dd�dur|�d�}|dd�}|dd�}tj�|||�S)zDTakes a hex sha and returns its filename relative to the given path.�encodeN�ascii�)�getattr�decode�os�path�join)r=r2�dir�filerrr�hex_to_filename�s

rAcCsv|�tjjd�dd�}d|}t|�dks4J|��|\}}t|�dkrTt|�dks\J|��||�d�}t|�|S)z?Takes an object filename and returns its corresponding hex sha.r9���NzInvalid object filename: %s�&r8)�rsplitr<r=�sepr(r7r4)�filename�names�errmsg�base�restr2rrr�filename_to_hex�s rK)�num_type�length�returncCs t|�jdt|��d�dS)zCReturn an object header for the given numeric type and text length.� r8�)�object_class�	type_name�strr7)rLrMrrr�
object_header�s���rT)�name�	docstringcs&�fdd�}�fdd�}t|||d�S)zGA property that helps tracking whether serialization is necessary.
    cst|d�|�d|_dS)N�_T)�setattr�_needs_serialization)�obj�value�rUrr�set�sz"serializable_property.<locals>.setcst|d��S)NrW)r:)rZr\rr�get�sz"serializable_property.<locals>.get��doc)�property)rUrVr]r^rr\r�serializable_property�srbcCst�|d�S)z�Get the object class corresponding to the given type.

    Args:
      type: Either a type name string or a numeric type.
    Returns: The ShaFile subclass corresponding to the given type, or None if
        type is not a valid type name/number.
    N)�	_TYPE_MAPr^)�typerrrrQ�srQcCst|�std||f��dS)z�Check if a string is a valid hex sha string.

    Args:
      hex: Hex string to check
      error_msg: Error message to use in exception
    Raises:
      ObjectFormatException: Raised when the string is not valid
    z%s %sN)r6r)r2�	error_msgrrr�check_hexsha�s	rfcCsj|�d�}|�d�}|dks^|dks^||ks^|�d|d�dks^|�d|d�dks^|�d�sft|��dS)z�Check if the specified identity is valid.

    This will raise an exception if the identity is not valid.

    Args:
      identity: Identity string
      error_msg: Error message to use in exception
    �<�>r�N)�find�endswithr)ZidentityreZemail_startZ	email_endrrr�check_identity�s	

���rlcCs|tkrtdt��dS)z�Check if the specified time is not prone to overflow error.

    This will raise an exception if the time is not valid.

    Args:
      time_info: author/committer/tagger info

    zDate field should not exceed %sN)�MAX_TIMEr)Ztime_secondsrrr�
check_time�s
�rncGsd�|�dS)z*Formats items into a space separated line.rO�
)r>)�itemsrrr�git_line�srqc@s,eZdZdZdZdd�Zdd�Zdd�Zd	S)
�FixedShazBSHA object that behaves like hashlib's but is given a fixed value.)�_hexsha�_shacCsDt|dd�dur|�d�}t|t�s0td|��||_t|�|_dS)Nr7r8z!Expected bytes for hexsha, got %r)r:r7r.r/r-rsr4rt)�selfr*rrr�__init__�s

zFixedSha.__init__cCs|jS)zReturn the raw SHA digest.)rt�rurrr�digest�szFixedSha.digestcCs|j�d�S)zReturn the hex SHA digest.r8)rsr;rwrrr�	hexdigest�szFixedSha.hexdigestN)rrrr�	__slots__rvrxryrrrrrr�s
rrc@s�eZdZdZdZdZdZedd��Zdd�Z	dQd	d
�Z
dRdd�Zd
d�Zdd�Z
dd�Zdd�Zdd�ZdSdd�ZdTdd�Zedd��Zdd�Zedd ��Zed!d"��Zd#d$�Zd%d&�Zd'd(�Zed)d*��Zed+d,��ZedUd-d.��ZedVd/d0��Zed1d2��Zd3d4�Z d5d6�Z!d7d8�Z"d9d:�Z#d;d<�Z$d=d>�Z%e&d?d@��Z'dAdB�Z(dCdD�Z)e&e(e)�Z*dEdF�Z+dGdH�Z,dIdJ�Z-dKdL�Z.dMdN�Z/dOdP�Z0dS)W�ShaFilezA git SHA file.)�
_chunked_textrtrYNc
Cs�d}t��}|�|�}d}d}|dkr\|�|�}||�|�7}||7}|�d|�}t|�}q|d|�}|�dd�\}}	zt|	�Wn0ty�}
zt	d|
��WYd}
~
n
d}
~
00t
|�}|s�t	d	|��|�S)
z<Parse a legacy object, creating it but not reading the file.ir���rPNrOrizObject size not an integer: %s�Not a known type: %s)r r!r"�readrjr(�split�intr0rrQ)�magic�f�bufsizeZdecomp�header�start�end�extrarR�size�e�	obj_classrrr�_parse_legacy_object_headers*


"z#ShaFile._parse_legacy_object_headercCs<t|�}|�d�}|dkr"td��|�||dd��dS)z.Parse a legacy object, setting the raw string.rPrzInvalid object header, no \0riN)r%rjr�set_raw_string)ru�map�textZ
header_endrrr�_parse_legacy_object!s

zShaFile._parse_legacy_objectr}ccsBt�|�}|�|���V|��D]}|�|�Vq"|��VdS)zlReturn chunks representing the object in the experimental format.

        Returns: List of strings
        N)r Zcompressobj�compress�_header�
as_raw_chunksr#)ru�compression_levelZcompobj�chunkrrr�as_legacy_object_chunks)s

zShaFile.as_legacy_object_chunkscCsd�|j|d��S)zJReturn string representing the object in the experimental format.
        �)r�)r>r�)rur�rrr�as_legacy_object4s�zShaFile.as_legacy_objectcCs"|jrd|_|��|_d|_|jS)zxReturn chunks with serialization of the object.

        Returns: List of strings, not necessarily one per line
        NF)rYrt�
_serializer|rwrrrr�:s

zShaFile.as_raw_chunkscCsd�|���S)z\Return raw string with serialization of the object.

        Returns: String object
        r�)r>r�rwrrr�
as_raw_stringEszShaFile.as_raw_stringcCs|��S)z/Return raw string serialization of this object.�r�rwrrr�	__bytes__LszShaFile.__bytes__cCs
t|j�S)z#Return unique hash for this object.)�hash�idrwrrr�__hash__PszShaFile.__hash__cCs|��S)z:Return a string representing this object, fit for display.r�rwrrr�as_pretty_stringTszShaFile.as_pretty_stringcCs(t|t�std|��|�|g|�dS)z9Set the contents of this object from a serialized string.zExpected bytes for text, got %rN)r.r/r-�set_raw_chunks)rur�r)rrrr�Xs
zShaFile.set_raw_stringcCs4||_|�|�|dur d|_n
t|�|_d|_dS)z6Set the contents of this object from a list of chunks.NF)r|�_deserializertrrrY)ru�chunksr)rrrr�^s

zShaFile.set_raw_chunkscCs6t|dd��d?d@}t|�}|s0td|��|�S)z?Parse a new style object, creating it but not reading the file.rri��zNot a known type %d)�ordrQr)r�r�rLr�rrr�_parse_object_headerhs
zShaFile._parse_object_headercCs\t|dd��}d}|d@dkr>t|||d��}|d7}q||d�}|�t|��dS)z-Parse a new style object, setting self._text.rri�N)r�r�r%)rur�ZbyteZused�rawrrr�
_parse_objectqs
zShaFile._parse_objectcCsDt|dd��}t|dd��}|d>|}|d@dkoB|ddkS)Nrrir9���)r�)�clsr�Zb0Zb1Zwordrrr�_is_legacy_object}szShaFile._is_legacy_objectcCsP|��}|std��|�|�r6|�||�}|�|�n|�||�}|�|�|S)NzCorrupted empty file detected)rrr�r�r�r�r�)r�r�r�rZrrr�_parse_file�s

zShaFile._parse_filecCsd|_g|_d|_dS)zDon't call this directlyNT)rtr|rYrwrrrrv�szShaFile.__init__cCst|j��dSr)�NotImplementedErrorr��rur�rrrr��szShaFile._deserializecCst|j��dSr)r�r�rwrrrr��szShaFile._serializecCs8t|d��}|�|�Wd�S1s*0YdS)zOpen a SHA file from disk.�rbN)r�	from_file)r�r=r�rrr�	from_path�szShaFile.from_pathc	Cs:z|�|�}d|_|WSttfy4td��Yn0dS)z'Get the contents of a SHA file on disk.Nzinvalid object header)r�rt�
IndexErrorr0r)r�r�rZrrrr��s
zShaFile.from_filecCst|��}|�||�|S)z�Creates an object of the indicated type from the raw string given.

        Args:
          type_num: The numeric type of the object.
          string: The raw uncompressed contents.
          sha: Optional known sha for the object
        )rQr�)�type_numr$r)rZrrr�from_raw_string�s	
zShaFile.from_raw_stringcCst|��}|�||�|S)z�Creates an object of the indicated type from the raw chunks given.

        Args:
          type_num: The numeric type of the object.
          chunks: An iterable of the raw uncompressed contents.
          sha: Optional known sha for the object
        )rQr�)r�r�r)rZrrr�from_raw_chunks�s	
zShaFile.from_raw_chunkscCs|�}|�|�|S)zCreate a ShaFile from a string.�r�)r�r$rZrrr�from_string�s
zShaFile.from_stringcCst||d�durt|��dS)a:Check that the object has a given member variable.

        Args:
          member: the member variable to check for
          error_msg: the message for an error if the member is missing
        Raises:
          ObjectFormatException: with the given error_msg if member is
            missing or is None
        N)r:r)ru�memberrerrr�_check_has_member�s
zShaFile._check_has_memberc
Csh|j}z|�|���d|_|j}Wn,tyP}zt|��WYd}~n
d}~00||krdt||��dS)z�Check this object for internal consistency.

        Raises:
          ObjectFormatException: if the object is malformed in some way
          ChecksumMismatch: if the object was created with a SHA that does
            not match its contents
        N)r�r�r�rt�	Exceptionrr	)ruZold_sha�new_shar�rrr�check�s
z
ShaFile.checkcCst|j|���Sr)rTrd�
raw_lengthrwrrrr��szShaFile._headercCs"d}|��D]}|t|�7}q|S)z4Returns the length of the raw string of this object.r)r�r()ru�retr�rrrr��szShaFile.raw_lengthcCsH|jdus|jrBt�}|�|���|��D]}|�|�q,||_|jS)z0The SHA1 object that is the name of this object.N)rtrYr�updater�r�)rur�r�rrrr)�szShaFile.shacCs$t|���}|�|��|��|j�S)z9Create a new copy of this SHA1 object from its raw string)rQ�get_typer�r�r�)rur�rrr�copys�zShaFile.copycCs|�����d�S)zThe hex SHA of this object.r8)r)ryr7rwrrrr�sz
ShaFile.idcCs|jS)z-Return the type number for this object class.�r�rwrrrr�szShaFile.get_typecCs
||_dS)z*Set the type number for this object class.Nr�)rurdrrr�set_typeszShaFile.set_typecCsd|jj|jfS)Nz<%s %s>)�	__class__rr�rwrrr�__repr__szShaFile.__repr__cCst|t�p|j|jkS)z3Check whether this object does not match the other.�r.r{r��ru�otherrrr�__ne__"szShaFile.__ne__cCst|t�o|j|jkS)z:Return True if the SHAs of the two objects match.
        r�r�rrr�__eq__&szShaFile.__eq__cCst|t�st�|j|jkS)zBReturn whether SHA of this object is less than the other.
        �r.r{r-r�r�rrr�__lt__+s
zShaFile.__lt__cCst|t�st�|j|jkS)zMCheck whether SHA of this object is less than or equal to the other.
        r�r�rrr�__le__2s
zShaFile.__le__cCst|t�st�t|j|j�S)zFCompare the SHA of this object with that of the other object.
        )r.r{r-Zcmpr�r�rrr�__cmp__9s
zShaFile.__cmp__)r})r})N)N)N)N)1rrrrrzrRr��staticmethodr�r�r�r�r�r�r�r�r�r�r�r�r��classmethodr�r�rvr�r�r�r�r�r�r�r�r�r�r�r)r�rar�r�r�rdr�r�r�r�r�r�rrrrr{sj











	



r{cs�eZdZdZdZdZdZ�fdd�Zdd�Zd	d
�Z	e
ee	dd�Zd
d�Zdd�Z
dd�Zdd�Ze
ee
dd�Zedd��Z�fdd�Zdd�Z�ZS)�BlobzA Git Blob object.rsblob�cstt|���g|_d|_dS�NF)�superr�rvr|rYrw�r�rrrvIsz
Blob.__init__cCs|��Srr�rwrrr�	_get_dataNszBlob._get_datacCs|�|�dSrr�)ru�datarrr�	_set_dataQszBlob._set_dataz*The text contained within the blob object.r_cCs|jSr�r|rwrrr�_get_chunkedWszBlob._get_chunkedcCs
||_dSrr�r�rrr�_set_chunkedZszBlob._set_chunkedcCs|jSrr�rwrrrr�]szBlob._serializecCs
||_dSrr�r�rrrr�`szBlob._deserializez>The text in the blob object, as chunks (not necessarily lines)cCs t�|�}t||�st|��|Sr)r{r�r.r
)r�r=�blobrrrr�gs

zBlob.from_pathcstt|���dS)��Check this object for internal consistency.

        Raises:
          ObjectFormatException: if the object is malformed in some way
        N)r�r�r�rwr�rrr�nsz
Blob.checkcCs�|j}|sgSt|�dkr(|d�d�Sd}g}|D]v}|�d�}t|�dkr�|�|pXd|d�|�|dd��|d}q4t|�dkr4|dur�|��}q4||��7}q4|dur�|�|�|S)z^Return list of lines in this blob.

        This preserves the original line endings.
        rirTNr�r})�chunkedr(�
splitlines�append�extend�pop)rur�Z	remainingr�r��linesrrrr�vs(



zBlob.splitlines)rrrrrzrRr�rvr�r�rar�r�r�r�r�r�r�r�r�r��
__classcell__rrr�rr�As,��
r�ccs�td�|��}d}d}d}dd�}|D]R}|�d�rF||dd�7}q&|dur\|||�fV|d	krhq�|�dd�\}}q&d
}|dur�|||�fVdV|s�d|��fV|��dS)aQParse a message with a list of fields and a body.

    Args:
      chunks: the raw chunks of the tag or commit object.
    Returns: iterator of tuples of (field, value), one per header line, in the
        order read from the text, possibly including duplicates. Includes a
        field named None for the freeform tag/commit text.
    r�N�FcSs|r|�d�r|dd�S|S)z!Strip the last newline from valueroNr})rk)r[rrr�_strip_last_newline�sz+_parse_message.<locals>._strip_last_newlinerOriroT�NN)rr>�
startswithr�r�close)r�r��k�v�eofr��linerrr�_parse_message�s(	

r�cs�eZdZdZdZdZdZ�fdd�Zedd��Z	�fd	d
�Z
dd�Zd
d�Zdd�Z
dd�Zee
e�Zedd�Zedd�Zedd�Zedd�Zedd�Zedd�Z�ZS)�TagzA Git Tag object.rr�)	�_tag_timezone_neg_utc�_name�_object_sha�
_object_class�	_tag_time�
_tag_timezone�_tagger�_message�
_signaturecs0tt|���d|_d|_d|_d|_d|_dSr�)r�r�rvr�r�r�r�r�rwr�rrrv�szTag.__init__cCs t�|�}t||�st|��|Sr)r{r�r.r)r�rF�tagrrrr��s

z
Tag.from_pathcstt|���|�dd�|�dd�|�dd�|js@td��t|jd�t|d	d
�rdt	|j
d�|�dd
�t|j�d
}t
|j�D]r\}}|tkr�|d
ur�td��nL|tkr�|tkr�td��n2|tkr�|tkr�td��n|tkr�|tkr�td��|}q�d
S)r�r�zmissing object shar�zmissing object typer�zmissing tag namezempty tag namezinvalid object shar�Nzinvalid taggerr�zmissing tag timezunexpected objectzunexpected typezunexpected tag namezunexpected tagger)r�r�r�r�r�rrfr�r:rlr�rnr�r�r|�_OBJECT_HEADER�_TYPE_HEADER�_TAG_HEADER�_TAGGER_HEADER)ru�last�fieldrWr�rrr��s,



z	Tag.checkc	Cs�g}|�tt|j��|�tt|jj��|�tt|j��|j	r�|j
dur`|�tt|j	��n,|�tt|j	t|j
��
d�t|j|j���|jdur�|�d�|�|j�|jdur�|�|j�|S)Nr8ro)r�rqr�r�r�r�rRrr�r�r�rrSr7�format_timezoner�r�r�r�r�rrrr�s(
��


zTag._serializec	Csd|_d|_d|_d|_t|�D]�\}}|tkr8||_q |tkr`t|�}|sXt	d|��||_
q |tkrp||_q |t
kr�t|�\|_|_\|_|_q |dur�|dur�d|_d|_nJz|�t�}Wnty�||_d|_Yn0|d|�|_||d�|_q t	d|��q dS)z%Grab the metadata attached to the tagNFr~zUnknown field %s)r�r�r�r�r�r�r�r�rQrr�rr�r�parse_time_entryr�r��index�BEGIN_PGP_SIGNATUREr0)rur�rr[r�Zsig_idxrrrr�sB��zTag._deserializecCs|j|jfS)z_Get the object pointed to by this tag.

        Returns: tuple of (object class, sha).
        )r�r�rwrrr�_get_object=szTag._get_objectcCs|\|_|_d|_dS�NT)r�r�rY�rur[rrr�_set_objectDszTag._set_objectrUzThe name of this tag�taggerz3Returns the name of the person who created this tag�tag_timezLThe creation timestamp of the tag.  As the number of seconds since the epoch�tag_timezonez!The timezone that tag_time is in.�messagez the message attached to this tag�	signaturezOptional detached GPG signature)rrrrrRr�rzrvr�r�r�r�r�rrra�objectrbrUrr
rrrr�rrr�rr��s@
"%

�����r�c@seZdZdZdd�ZdS)�	TreeEntryz.Named tuple encapsulating a single tree entry.cCs2t|jt�std|��tt�||j�|j|j�S)z:Return a copy of this entry with the given path prepended.zExpected bytes for path, got %r)	r.r=r/r-r�	posixpathr>�moder))rur=rrr�in_path_szTreeEntry.in_pathN)rrrrrrrrrr\sr)r=rr)Fccs�d}t|�}||kr�|�d|�}|||�}|rF|�d�rFtd|��zt|d�}Wntyrtd|��Yn0|�d|�}||d|�}|d}||d|�}	t|	�d	kr�td
��t|	�}
|||
fVqdS)z�Parse a tree text.

    Args:
      text: Serialized text to parse
    Returns: iterator of tuples of (name, mode, sha)
    Raises:
      ObjectFormatException: if the object was malformed in some way
    rrO�0zInvalid mode '%s'r�rPri��zSha has invalid lengthN)r(rr�rr�r0r+)r��strict�countrMZmode_endZ	mode_textrZname_endrUr)r*rrr�
parse_treefs&	rccs8|D].\}}}d|�d�d|dt|�VqdS)z�Serialize the items in a tree to a text.

    Args:
      items: Sorted iterable over (name, mode, sha) tuples
    Returns: Serialized tree text as chunks
    z%04or8rOrPN)r7r4)rprUrr*rrr�serialize_tree�s��rccs^|rtp
t}t|��|d�D]<\}}|\}}t|�}t|t�sJtd|��t|||�VqdS)aXIterate over a tree entries dictionary.

    Args:
      name_order: If True, iterate entries in order of their name. If
        False, iterate entries in tree order, that is, treat subtree entries as
        having '/' appended.
      entries: Dictionary mapping names to (mode, sha) tuples
    Returns: Iterator over (name, mode, hexsha)
    )�keyzExpected bytes for SHA, got %rN)	�key_entry_name_order�	key_entry�sortedrpr�r.r/r-r)�entries�
name_orderZkey_funcrU�entryrr*rrr�sorted_tree_items�s

r$cCs"|\}}t�|d�r|d7}|S)zJSort key for tree entry.

    Args:
      entry: (name, value) tuplee
    r�/)r�S_ISDIR)r#rUr[rrrr�srcCs|dS)z&Sort key for tree entry in name order.rr)r#rrrr�sr�utf-8cCs2|tj@rd}nd}d|||�d�|�|d�fS)z�Pretty format tree entry.

    Args:
      name: Name of the directory entry
      mode: Mode of entry
      hexsha: Hexsha of the referenced object
    Returns: string describing the tree entry
    �treer�z%04o %s %s	%s
r8�replace)r�S_IFDIRr;)rUrr*�encoding�kindrrr�pretty_format_tree_entry�s	

�r-cs�eZdZdZdZdZdZ�fdd�Zedd��Z	d	d
�Z
dd�Zd
d�Zdd�Z
dd�Zdd�Zdd�Zd&dd�Zdd�Zdd�Z�fdd�Zd d!�Zd"d#�Zd$d%�Z�ZS)'�TreezA Git tree objectrr9�_entriescstt|���i|_dSr)r�r.rvr/rwr�rrrv�sz
Tree.__init__cCs t�|�}t||�st|��|Sr)r{r�r.r
)r�rFr(rrrr��s

zTree.from_pathcCs
||jvSr�r/�rurUrrr�__contains__�szTree.__contains__cCs
|j|Srr0r1rrr�__getitem__�szTree.__getitem__cCs |\}}||f|j|<d|_dS)aSet a tree entry by name.

        Args:
          name: The name of the entry, as a string.
          value: A tuple of (mode, hexsha), where mode is the mode of the
            entry as an integral type and hexsha is the hex SHA of the entry as
            a string.
        TN�r/rY)rurUr[rr*rrr�__setitem__�s	zTree.__setitem__cCs|j|=d|_dSr	r4r1rrr�__delitem__�szTree.__delitem__cCs
t|j�Sr)r(r/rwrrr�__len__�szTree.__len__cCs
t|j�Sr)�iterr/rwrrr�__iter__�sz
Tree.__iter__cCsFt|t�r.t|t�r.||}}tjdtdd�||f|j|<d|_dS)a*Add an entry to the tree.

        Args:
          mode: The mode of the entry as an integral type. Not all
            possible modes are supported by git; see check() for details.
          name: The name of the entry, as a string.
          hexsha: The hex SHA of the entry as a string.
        z'Please use Tree.add(name, mode, hexsha)r9)�category�
stacklevelTN)r.r�r/�warnings�warn�DeprecationWarningr/rY)rurUrr*rrr�add�s	
�zTree.addFcCst|j|�S)z�Iterate over entries.

        Args:
          name_order: If True, iterate in name order instead of tree
            order.
        Returns: Iterator over (name, mode, sha) tuples
        )r$r/)rur"rrr�	iteritemsszTree.iteritemscCst|���S)zeReturn the sorted entries in this tree.

        Returns: List with (name, mode, sha) tuples
        )�listr@rwrrrrpsz
Tree.itemsc
CsXztd�|��}Wn,ty>}zt|��WYd}~n
d}~00tdd�|D��|_dS)zGrab the entries in the treer�NcSsg|]\}}}|||ff�qSrr)�.0�nr�srrr�
<listcomp>"r�z%Tree._deserialize.<locals>.<listcomp>)rr>r0r�dictr/)rur�Zparsed_entriesr�rrrr�s
zTree._deserializecs�tt|���d}tjdBtjdBtjtjttjdBf}td�	|j
�d�D]�\}}}t|d|�d|vsr|d	vr�td
|�
dd���||vr�td
|��|||ff}|r�t|�t|�kr�td��||dkr�td|��|}qJdS)r�Ni�i�i�r�Tzinvalid sha %sr%)r��.s..s.gitzinvalid name %sr'r)zinvalid mode %06ozentries not sortedrzduplicate entry %s)r�r.r�r�S_IFREG�S_IFLNKr*rrr>r|rfrr;r)rurZ
allowed_modesrUrr)r#r�rrr�$s2
��
��z
Tree.checkcCstt|����Sr)rArr@rwrrrr�CszTree._serializecCs4g}|��D]\}}}|�t|||��qd�|�S)Nr�)r@r�r-r>)rur�rUrr*rrrr�FszTree.as_pretty_stringcCsR|�d�}|j}d}|D]0}|s"q||�}t|t�s<t|��||\}}q||fS)z�Look up an object in a Git tree.

        Args:
          lookup_obj: Callback for retrieving object by SHA1
          path: Path to lookup
        Returns: A tuple of (mode, SHA) of the resulting path.
        r%N)r�r�r.r.r
)ruZ
lookup_objr=�partsr)r�prZrrr�lookup_pathLs

zTree.lookup_path)F)rrrrrRr�rzrvr�r�r2r3r5r6r7r9r?r@rpr�r�r�r�rLr�rrr�rr.�s*



r.cCs�|ddvrtdt���|dd�}t|dd��}|dkrD|}|dkoR|dk}|dkr`dpbd}t|�}t|d�}|d}||d	|d
|fS)aParse a timezone text fragment (e.g. '+0100').

    Args:
      text: Text to parse.
    Returns: Tuple with timezone as seconds difference to UTC
        and a boolean indicating whether this was a UTC timezone
        prefixed with a negative sign (-0000).
    rs+-z*Timezone must start with + or - (%(text)s)Nri�-r}�d��<)r0�varsr��abs)r��sign�offset�unnecessary_negative_timezoneZsignumZhoursZminutesrrr�parse_timezoneas�rVcCsP|ddkrtd��|dks |r,d}|}nd}d||d|ddf�d�S)	aFormat a timezone for Git serialization.

    Args:
      offset: Timezone offset as seconds difference to UTC
      unnecessary_negative_timezone: Whether to use a minus sign for
        UTC or positive timezones (-0000 and --700 rather than +0000 / +0700).
    rPrz#Unable to handle non-minute offset.�-�+z
%c%02d%02drOr8)r0r7)rTrUrSrrrr|s��rc

Cs�z|�d�}Wnty*|ddfYS0zH|d|d�}||dd�}|�dd�\}}t|�}t|�\}}Wn,ty�}	zt|	��WYd}	~	n
d}	~	00||||ffS)aParse time entry behavior

    Args:
      value: Bytes representing a git commit/tag line
    Raises:
      ObjectFormatException in case of parsing error (malformed
      field date)
    Returns: Tuple of (author, time, (timezone, timezone_neg_utc))
    s> Nr�rrir9rO)�rindexr0rDr�rVr)
r[rEZpersonrJZtimetextZtimezonetext�time�timezoneZtimezone_neg_utcr�rrrr�s
rc	Cs�g}g}d}d}d}d}g}d}d}	t|�D]�\}
}|
tkrB|}q,|
tkrV|�|�q,|
tkrht|�}q,|
tkrzt|�}q,|
tkr�|}q,|
tkr�|�t	�
|d��q,|
tkr�|}	q,|
dur�|}q,|�|
|f�q,|||||||	||f	S)z�Parse a commit object from chunks.

    Args:
      chunks: Chunks to parse
    Returns: Tuple of (tree, parents, author_info, commit_info,
        encoding, mergetag, gpgsig, message, extra)
    N)NNr�ro)r��_TREE_HEADER�_PARENT_HEADERr��_AUTHOR_HEADERr�_COMMITTER_HEADER�_ENCODING_HEADER�_MERGETAG_HEADERr�r��_GPGSIG_HEADER)r��parentsr�r(�author_info�commit_infor+�mergetagr�gpgsigrr[rrr�parse_commit�s<

�rhcs�eZdZdZdZdZdZ�fdd�Zedd��Z	d	d
�Z
�fdd�Zd
d�Ze
dd�Zdd�Zdd�Zeeedd�Zdd�Zeedd�Ze
dd�Ze
dd�Ze
dd�Ze
d d!�Ze
d"d#�Ze
d$d%�Ze
d&d'�Ze
d(d)�Ze
d*d+�Ze
d,d-�Z�ZS).�CommitzA git commit objectscommitri)�_parents�	_encoding�_extra�_author_timezone_neg_utc�_commit_timezone_neg_utc�_commit_time�_author_time�_author_timezone�_commit_timezone�_author�
_committer�_treer��	_mergetag�_gpgsigcs<tt|���g|_d|_g|_d|_g|_d|_d|_	dSr�)
r�rirvrjrkrvrwrlrmrnrwr�rrrv�szCommit.__init__cCs t�|�}t||�st|��|Sr)r{r�r.r)r�r=Zcommitrrrr��s

zCommit.from_pathc
CsXt|�\	|_|_}}|_|_|_|_|_|\|_|_	\|_
|_|\|_|_
\|_|_dSr)rhrurjrkrvrwr�rlrsrprqrmrtrorrrn)rur�rdrerrrr��s��

�

�zCommit._deserializecsLtt|���|�dd�|�dd�|�dd�|�dd�|�d	d
�|jD]}t|d�qPt|jd�t|jd
�t|j	d�t
|j�t
|j�d}t
|j�D]�\}}|tkr�|dur�td��nz|tkr�|ttfvr�td��n\|tk�r|ttfv�rtd��n:|tk�r&|tk�r&td��n|tk�rB|tk�rBtd��|}q�dS)r�ruzmissing treerszmissing authorrtzmissing committerrpzmissing author timerozmissing commit timezinvalid parent shazinvalid tree shazinvalid authorzinvalid committerNzunexpected treezunexpected parentzunexpected authorzunexpected committerzunexpected encoding)r�rir�r�rjrfrurlrsrtrnrpror�r|r\rr]r^r_r`)ru�parentrrrWr�rrr��s<



�
�

zCommit.checkc
	Cs�g}t|jt�r|jjn|j}|�tt|��|jD]}|�tt|��q4|�tt	|j
t|j��
d�t|j|j���|�tt|jt|j��
d�t|j|j���|jr�|�tt|j��|jD]l}|���d�}|�tt|d��|dd�D]}|�d|d�q�|d�d�r�|ddd�|d<q�|jD]>\}}d|v�sPd|v�r`td	||f��|�t||���q4|j�r�|j�d�}	|�tt |	d��|	dd�D]}|�td
|���q�|�d�|�|j!�|S)Nr8rorrirOr}s 
rBznewline in extra data: %r -> %rr�)"r.rur.r�r�rqr\rjr]r^rsrSrpr7rrqrmr_rtrorrrnr+r`rfr�r�rarkr��AssertionErrorrgrbr�)
rur�Z
tree_bytesrKrfZmergetag_chunksr�r�r�Z
sig_chunksrrrr�!sV�
����

�
zCommit._serializer(z%Tree that is the state of this commitcCs|jS)z(Return a list of parents of this commit.)rjrwrrr�_get_parentsPszCommit._get_parentscCsd|_||_dS)z%Set a list of parents of this commit.TN)rYrjr
rrr�_set_parentsTszCommit._set_parentsz&Parents of this commit, by their SHA1.r_cCs|jS)z%Return extra settings of this commit.)rlrwrrr�
_get_extra\szCommit._get_extraz�Extra header fields not understood (presumably added in a newer version of git). Kept verbatim so the object can be correctly reserialized. For private commit metadata, use pseudo-headers in Commit.message, rather than this field.�authorz$The name of the author of the commit�	committerz'The name of the committer of the commitrzThe commit message�commit_timezFThe timestamp of the commit. As the number of seconds since the epoch.�commit_timezonezThe zone the commit time is in�author_timezOThe timestamp the commit was written. As the number of seconds since the epoch.�author_timezonez'Returns the zone the author time is in.r+zEncoding of the commit message.rfzAssociated signed tag.rgzGPG Signature.) rrrrrRr�rzrvr�r�r�r�r�rbr(rzr{rarcr|r�r}r~rrr�r�r�r+rfrgr�rrr�rri�st

	),�������������ri)rr$)N)F)r')F)Yrr'�ior�collectionsrr<rr�typingrrrrr<r ZhashlibrZdulwich.errorsr	r
rrr
rrZdulwich.filerZZERO_SHAr\r]r^r_r`rarbr�r�rrrrmrrrr%r+r4r6rArKr�r/rTrSrbrQrfrlrnrqrrrr{r�r�r�rrrr$rrr-r.rVrrrhriZOBJECT_CLASSESrcr�rRr�Z_parse_tree_pyZ_sorted_tree_items_pyZdulwich._objects�ImportErrorrrrr�<module>s�$	



CQ6



*=�