o
    ﯪg&]                  	   @   s  d Z g dZddlmZmZ ddlZddlmZ ddlmZm	Z	m
Z
 ddlZddlmZ ddlZddlZddlmZmZmZ dd	lmZmZmZmZmZmZmZmZmZmZmZm Z m!Z! dd
l"m#Z#m$Z$ erddl%m&Z&m'Z' ddl(m)Z) ddl"m*Z*m+Z+ ddl,m-Z- ddl.m/Z/ ddl0m1Z1 ddl2m3Z3 ddl4m5Z5m6Z6 neZ*dd Z+G dd deZ7edddZ8eeed df df Z9e	dZ:dee;e<f de=fd d!Z>d"e;deed# ed$ ed% ed& f fd'd(Z?d)e<de=fd*d+Z@d,eAde<fd-d.ZBd/e<de<fd0d1ZCG d2d3 d3e
ZDeDdd4ZEd5eAd6eAdefd7d8ZFd9ee<ef dee=e=f fd:d;ZGeHd<ZIeHd=ZJd>e<deee=e=f fd?d@ZKG dAdB dBZLe+G dCd de*ZMe+G dDdE dEe*ZNG dFd deeMZOdS )Gz/Utility functions for working with git objects.)get_object_type_by_name
parse_dateparse_actor_and_dateProcessStreamAdapterTraversablealtz_to_utctz_strutctz_to_altzverify_utctzActortzoffsetutc    )ABCabstractmethodN)deque)datetime	timedeltatzinfo)digits)r	   IterableListIterableObj)AnyCallableDequeIterator
NamedTupleSequenceTYPE_CHECKINGTupleTypeTypeVarUnioncastoverload)Has_id_attributeLiteral)BytesIOStringIO)Popen)Protocolruntime_checkable   )Blob)Commit)	Submodule)	TagObject)TraversedTreeTupTreec                 C   s   | S N )fr2   r2   L/var/www/html/chatdoc2/venv/lib/python3.10/site-packages/git/objects/util.pyr)   C      r)   c                   @   s.   e Zd ZU eed< ed ed< ed ed< dS )
TraverseNTdepthr   r+   itemr   NsrcN)__name__
__module____qualname__int__annotations__r    r2   r2   r2   r4   r6   G   s   
 r6   T_TIobjTraversableIterableObj)boundr:   r   r/   modestrreturnc                 C   sL   d}t t| dd D ]\}}ttttf |}|t||d > 7 }q|S )a  Convert mode bits from an octal mode string to an integer mode for git.

    :param modestr:
        String like ``755`` or ``644`` or ``100644`` - only the last 6 chars will be
        used.

    :return:
        String identifying a mode compatible to the mode methods ids of the :mod:`stat`
        module regarding the rwx permissions for user, group and other, special flags
        and file system flags, such as whether it is a symlink.
    r   N   )	enumeratereversedr!   r    strr?   )rD   mode	iterationcharr2   r2   r4   mode_str_to_int[   s
   rN   object_type_namer,   r.   r0   r+   c                 C   sx   | dkrddl m} |jS | dkrddl m} |jS | dkr'ddl m} |jS | dkr4dd	l m} |jS t	d
| 
  )a  Retrieve the Python class GitPython uses to represent a kind of Git object.

    :return:
        A type suitable to handle the given as `object_type_name`.
        This type can be called create new instances.

    :param object_type_name:
        Member of :attr:`Object.TYPES <git.objects.base.Object.TYPES>`.

    :raise ValueError:
        If `object_type_name` is unknown.
    s   commitr*   )commits   tag)tags   blob)blobs   tree)treez%Cannot handle unknown object type: %s) rP   r,   rQ   r.   rR   r+   rS   r0   
ValueErrordecode)rO   rP   rQ   rR   rS   r2   r2   r4   r   o   s   r   utctzc                 C   s:   t | }t|d d t|d d  }|dk r|S | S )zConvert a git timezone offset into a timezone offset west of UTC in seconds
    (compatible with :attr:`time.altzone`).

    :param utctz:
        git utc timezone string, e.g. +0200
    d     <   r   )r?   abs)rW   	int_utctzsecondsr2   r2   r4   r      s    r   altzc                 C   s:   t | d }t | d d }| dkrdnd}d|||S )zConvert a timezone offset west of UTC in seconds into a Git timezone offset
    string.

    :param altz:
        Timezone offset in seconds west of UTC.
    rY   rZ   -+z{}{:02}{:02})r[   format)r^   hoursminutessignr2   r2   r4   r      s   r   offsetc                 C   sd   t d|  }t| dkr|| d dvr|| d tvs.| d tvs.| d tvs.| d tvr0|| S )	z]
    :raise ValueError:
        If `offset` is incorrect.

    :return:
        `offset`
    z"Invalid timezone offset format: %s   r   z+-r*      rG      )rU   lenr   )re   fmt_excr2   r2   r4   r      s   0r   c                   @   s   e Zd Zddededef ddfddZdeed  eeef f fddZ	d	ee
df defd
dZd	ee
df defddZd	ee
df defddZdS )r
   Nsecs_west_of_utcnamerE   c                 C   s   t | d| _|p
d| _d S )N)r]   fixed)r   _offset_name)selfrk   rl   r2   r2   r4   __init__   s   ztzoffset.__init__c                 C   s   t | j  | jffS r1   )r
   rn   total_secondsro   rp   r2   r2   r4   
__reduce__   s   ztzoffset.__reduce__dtc                 C      | j S r1   )rn   rp   ru   r2   r2   r4   	utcoffset      ztzoffset.utcoffsetc                 C   rv   r1   )ro   rw   r2   r2   r4   tzname   ry   ztzoffset.tznamec                 C   s   t S r1   )ZEROrw   r2   r2   r4   dst   r5   ztzoffset.dstr1   )r<   r=   r>   floatr    rJ   rq   r   r   rt   r   r   rx   rz   r|   r2   r2   r2   r4   r
      s     "r
   UTC	timestamp	tz_offsetc                 C   s8   t | t}z
|t|}|W S  ty   | Y S w )z[Convert a `timestamp` + `tz_offset` into an aware :class:`~datetime.datetime`
    instance.)r   fromtimestampr   
astimezoner
   rU   )r   r   utc_dtlocal_dtr2   r2   r4   from_timestamp   s   r   string_datec                 C   s"  t | tr(| jr!tt|  }t|  }t| t	
 |fS td|  z| ddkrU| ddkrU|  \}}|drH|dd }t|}|tt|fW S d}| d	 d
v rkt| d	d }| dd } t|}g }d}d| v r|d | d}n"|d |d |d |d | d}|dkr| d}|dksJ | |d d }| d| }	t|d}
|D ]2}z't|	|}t|j|j|j|
j|
j|
j|j|j|
jf	}t||fW   W S  ty   Y qw td t y } ztd|  dt!|  |d}~ww )a	  Parse the given date as one of the following:

        * Aware datetime instance
        * Git internal format: timestamp offset
        * :rfc:`2822`: ``Thu, 07 Apr 2005 22:13:13 +0200``
        * ISO 8601: ``2005-04-07T22:13:13`` - The ``T`` can be a space as well.

    :return:
        Tuple(int(timestamp_UTC), int(offset)), both in seconds since epoch

    :raise ValueError:
        If the format could not be understood.

    :note:
        Date can also be ``YYYY.MM.DD``, ``MM/DD/YYYY`` and ``DD.MM.YYYY``.
    z,string_date datetime object without tzinfo,  r*   :@Nz+0000z-+rF   ,z%a, %d %b %Yz%Y-%m-%dz%Y.%m.%dz%m/%d/%Yz%d.%m.%YTz%H:%M:%Szno format matchedz!Unsupported date format or type: z, type=)"
isinstancer   r   r!   r   rx   r?   rr   r   r   r   rU   countrfindsplit
startswithr   r   appendtimestrptimecalendartimegmtm_yeartm_montm_mdaytm_hourtm_mintm_sectm_wdaytm_ydaytm_isdst	Exceptiontype)r   rx   re   r   
offset_strtimestamp_intdate_formatssplitter	time_part	date_parttstructfmtdtstructutctimeer2   r2   r4   r      st   








r   z^.+? (.*) (\d+) ([+-]\d+).*$z
^.+? (.*)$linec                 C   s`   d\}}}t | }|r| \}}}nt| }|r |dn| p#d}t|t|t|fS )zParse out the actor (author or committer) info from a line like::

        author Tom Preston-Werner <tom@mojombo.com> 1191999972 -0700

    :return:
        [Actor, int_seconds_since_epoch, int_timezone_offset]
    )rT   0r   r*   rT   )	_re_actor_epochsearchgroups_re_only_actorgroupr	   _from_stringr?   r   )r   actorepochre   mr2   r2   r4   r   F  s   


r   c                   @   s<   e Zd ZdZdZdddeddfdd	Zd
edefddZdS )r   a%  Class wiring all calls to the contained Process instance.

    Use this type to hide the underlying process to provide access only to a specified
    stream. The process is usually wrapped into an :class:`~git.cmd.Git.AutoInterrupt`
    class to kill it if the instance goes out of scope.
    )_proc_streamprocessr'   stream_namerE   Nc                 C   s   || _ t||| _d S r1   )r   getattrr   )rp   r   r   r2   r2   r4   rq   h  s   zProcessStreamAdapter.__init__attrc                 C   s   t | j|S r1   )r   r   )rp   r   r2   r2   r4   __getattr__l  s   z ProcessStreamAdapter.__getattr__)	r<   r=   r>   __doc__	__slots__rJ   rq   r   r   r2   r2   r2   r4   r   ^  s
    r   c                   @   s  e Zd ZdZdZeededed  fddZ	edededefd	d
Z
	d#dedededeed  fddZedededefddZdd dd dddddfdeed def egef deed def egef dedededededeeed  ee f fd d!Zd"S )$r   au  Simple interface to perform depth-first or breadth-first traversals in one
    direction.

    Subclasses only need to implement one function.

    Instances of the subclass must be hashable.

    Defined subclasses:

    * :class:`Commit <git.objects.Commit>`
    * :class:`Tree <git.objects.tree.Tree>`
    * :class:`Submodule <git.objects.submodule.base.Submodule>`
    r2   r9   rE   c                 C      t d)aA  
        :return:
            Tuple of items connected to the given item.
            Must be implemented in subclass.

        class Commit::     (cls, Commit) -> Tuple[Commit, ...]
        class Submodule::  (cls, Submodule) -> Iterablelist[Submodule]
        class Tree::       (cls, Tree) -> Tuple[Tree, ...]
        To be implemented in subclassNotImplementedError)clsr9   r2   r2   r4   _get_intermediate_items     z#Traversable._get_intermediate_itemsargskwargsc                 O       t jdtdd | j|i |S )zTraverse self and collect all items found.

        Calling this directly on the abstract base class, including via a ``super()``
        proxy, is deprecated. Only overridden implementations should be called.
        zlist_traverse() method should only be called from subclasses. Calling from Traversable abstract class will raise NotImplementedError in 4.0.0. The concrete subclasses in GitPython itself are 'Commit', 'RootModule', 'Submodule', and 'Tree'.rg   
stacklevel)warningswarnDeprecationWarning_list_traverserp   r   r   r2   r2   r4   list_traverse     zTraversable.list_traverseFas_edge)r,   r-   r0   r+   c                 O   sX   t | tr	| j}nd}|s t|}|| j|d|i| |S t| j|i |}|S )aj  Traverse self and collect all items found.

        :return:
            :class:`~git.util.IterableList` with the results of the traversal as
            produced by :meth:`traverse`::

                Commit -> IterableList[Commit]
                Submodule ->  IterableList[Submodule]
                Tree -> IterableList[Union[Submodule, Tree, Blob]]
        rT   r   )r   r#   _id_attribute_r   extendtraverse)rp   r   r   r   idoutout_listr2   r2   r4   r     s   
zTraversable._list_traversec                 O   r   )zIterator yielding items found when traversing self.

        Calling this directly on the abstract base class, including via a ``super()``
        proxy, is deprecated. Only overridden implementations should be called.
        ztraverse() method should only be called from subclasses. Calling from Traversable abstract class will raise NotImplementedError in 4.0.0. The concrete subclasses in GitPython itself are 'Commit', 'RootModule', 'Submodule', and 'Tree'.rg   r   )r   r   r   	_traverser   r2   r2   r4   r     r   zTraversable.traversec                 C      dS NTr2   idr2   r2   r4   <lambda>      zTraversable.<lambda>c                 C   r   NFr2   r   r2   r2   r4   r     r   r   Tr*   	predicater+   pruner7   branch_first
visit_onceignore_selfr8   c              
   #   s    t  }t }	|	tdd dtt dddtdtddf
 fd	d
}
|	rr|	 \} }|r4 |v r4q$|r;|  |rB| f}n }|||rJq$|oO u }|sZ|||rZ|V  |d }|dkrg||krgq$|
|	 || |	s&dS dS )a  Iterator yielding items found when traversing `self`.

        :param predicate:
            A function ``f(i,d)`` that returns ``False`` if item i at depth ``d`` should
            not be included in the result.

        :param prune:
            A function ``f(i,d)`` that returns ``True`` if the search should stop at
            item ``i`` at depth ``d``. Item ``i`` will not be returned.

        :param depth:
            Defines at which level the iteration should not go deeper if -1. There is no
            limit if 0, you would effectively only get `self`, the root of the
            iteration. If 1, you would only get the first level of
            predecessors/successors.

        :param branch_first:
            If ``True``, items will be returned branch first, otherwise depth first.

        :param visit_once:
            If ``True``, items will only be returned once, although they might be
            encountered several times. Loops are prevented that way.

        :param ignore_self:
            If ``True``, `self` will be ignored and automatically pruned from the
            result. Otherwise it will be the first item to be returned. If `as_edge` is
            ``True``, the source of the first edge is ``None``.

        :param as_edge:
            If ``True``, return a pair of items, first being the source, second the
            destination, i.e. tuple(src, dest) with the edge spanning from source to
            destination.

        :return:
            Iterator yielding items found when traversing `self`::

                Commit -> Iterator[Union[Commit, Tuple[Commit, Commit]] Submodule ->
                Iterator[Submodule, Tuple[Submodule, Submodule]] Tree ->
                Iterator[Union[Blob, Tree, Submodule,
                                        Tuple[Union[Submodule, Tree], Union[Blob, Tree,
                                        Submodule]]]

                ignore_self=True is_edge=True -> Iterator[item] ignore_self=True
                is_edge=False --> Iterator[item] ignore_self=False is_edge=True ->
                Iterator[item] | Iterator[Tuple[src, item]] ignore_self=False
                is_edge=False -> Iterator[Tuple[src, item]]
        r   Nstacksrc_itemr   r   r7   rE   c                    sh    s	d S |r|  fddD  d S  fddttd ddD }| | d S )Nc                 3   s    | ]	}t  |V  qd S r1   r6   .0r   )r7   r   r2   r4   	<genexpr>  s    z<Traversable._traverse.<locals>.addToStack.<locals>.<genexpr>c                 3   s     | ]}t  | V  qd S r1   r   r   r7   lstr   r2   r4   r     s    r*   r   )r   
extendleftrangeri   r   )r   r   r   r7   reviterr9   rp   r   r4   
addToStack  s   
&z)Traversable._traverse.<locals>.addToStackr*   r   )	setr   r   r6   r   boolr?   popadd)rp   r   r   r7   r   r   r   r   visitedr   r   r   r;   rvalskipStartItemnext_dr2   r   r4   r     sD   :


zTraversable._traverseN)F)r<   r=   r>   r   r   classmethodr   r   r   r   r   r   r   r    r   r   r   TraversedTupr?   r   r   r2   r2   r2   r4   r   p  sX    

#	c                   @   s(   e Zd ZdZdZdddZddd	Zd
S )SerializablezUDefines methods to serialize and deserialize objects from and into a data
    stream.r2   streamr%   rE   c                 C   r   )a  Serialize the data of this object into the given data stream.

        :note:
            A serialized object would :meth:`_deserialize` into the same object.

        :param stream:
            A file-like object.

        :return:
            self
        r   r   rp   r  r2   r2   r4   
_serializeK  r   zSerializable._serializec                 C   r   )zDeserialize all information regarding this object from the stream.

        :param stream:
            A file-like object.

        :return:
            self
        r   r   r  r2   r2   r4   _deserializeZ  s   	zSerializable._deserializeN)r  r%   rE   r  )r<   r=   r>   r   r   r  r  r2   r2   r2   r4   r  C  s
    
r  c                       s~  e Zd ZdZeeedf ef Zdededede	e f fddZ
ededee fd	d
Zededeeeeeedf ef f egef deeeeeedf ef f egef dedededed ded dee fdd
Zededeeeeeedf ef f egef deeeeeedf ef f egef dedededed ded deeeedf ef  fdd
Zededeeeef egef deeeef egef dedededed ded deeeef  fdd
Zdd dd dddddfdedeeeef egef deeeef egef dedededededeee eeeef  ee f f fdd
Z  ZS )rB   r2   Nrp   r   r   rE   c                    s   t  j|i |S r1   )superr   r   	__class__r2   r4   r   k  s   z$TraversableIterableObj.list_traversec                 C      d S r1   r2   rs   r2   r2   r4   r   n  r5   zTraversableIterableObj.traverser   r   r7   r   r   r   Tr   Fc                 C   r	  r1   r2   rp   r   r   r7   r   r   r   r   r2   r2   r4   r   q     
c                 C   r	  r1   r2   r
  r2   r2   r4   r   }  r  c                 C   r	  r1   r2   r
  r2   r2   r4   r     r  c                 C   r   r   r2   r   r2   r2   r4   r     r   zTraversableIterableObj.<lambda>c                 C   r   r   r2   r   r2   r2   r4   r     r   r   r*   c                    s>   t ttt tttdtf tf  f t |||||||S )z5For documentation, see :meth:`Traversable._traverse`.N)r!   r    r   rA   r   r  r   r
  r  r2   r4   r     s   ")r<   r=   r>   r   r   r    rA   TIobj_tupler   r   r   r"   r   r   r   r?   r   r$   __classcell__r2   r2   r  r4   rB   f  s    "&&	&&		 	)Pr   __all__abcr   r   r   collectionsr   r   r   r   restringr   r   r   git.utilr	   r   r   typingr   r   r   r   r   r   r   r   r   r   r    r!   r"   	git.typesr#   r$   ior%   r&   
subprocessr'   r(   r)   rR   r+   rP   r,   submodule.baser-   rQ   r.   rS   r/   r0   r6   rA   r   r{   bytesrJ   r?   rN   r   r   r}   r   r   r
   r   r   r   compiler   r   r   r   r   r  rB   r2   r2   r2   r4   <module>   sn   <
#
"
d
 S"