
    .Ph-              	       8   d Z ddlZddlZddlmZ ddlmZ ddlm	Z	m
Z
mZmZ e	rddlmZ ddlmZmZ d	ed
efdZded
efdZde
d
ee         fdZddededed
efdZ G d d          Z G d d          Z G d d          Zded
efdZ G d d          ZdS ) zhParsing of gitignore files.

For details for the matching rules, see https://git-scm.com/docs/gitignore
    N)Iterable)suppress)TYPE_CHECKINGBinaryIOOptionalUnion   )Repo)Configget_xdg_config_home_pathsegmentreturnc                    | dk    rdS d}dt          |           }}||k     rd| ||dz            }|dz   }|dk    r|dz  }n>|dk    r|dz  }n1|d	k    r)|t          j        | ||dz                      z  }|dz  }n|d
k    r|}||k     r| ||dz            dk    r|dz   }||k     r| ||dz            dk    r|dz   }||k     r-| ||dz            dk    r|dz   }||k     r| ||dz            dk    ||k    r|dz  }n| ||                             d	d          }|dz   }|                    d          rd|dd          z   }n|                    d          rd	|z   }|d
|z   dz   z  }n|t          j        |          z  }||k     d|S )N   *s   [^/]+    r   r	   s   [^/]*   ?s   [^/]   \   [   !   ]s   \[s   \\   ^)lenreescapereplace
startswith)r   resincjstuffs          N/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/dulwich/ignore.py_translate_segmentr$   &   s   $x
Cc'llqA
a%%AAIE998OCC$YY7NCC%ZZ29WQQY/000CFAA$YYA1uuQU+t33E1uuQU+t33Ea%%GAAI.$66E a%%GAAI.$66Avvv!,,UG<<E##D)) * 59,EE%%d++ *!EMEte|d**29Q<<C; a%%< Jr   patc                    d}d| dd         vr|dz  }|                      d          r| dd         } |dz  }|                      d          r
| dd         } t          |                     d                    D ]@\  }}|d	k    r|d
z  }||dk    rt          j        d          ndt          |          z   z  }A|                     d          s|dz  }|dz   S )zTranslate a shell PATTERN to a regular expression.

    There is no way to quote meta-characters.

    Originally copied from fnmatch in Python 2.7, but modified for Dulwich
    to cope with features in Git ignore patterns.
    s   (?ms)   /Ns   (.*/)?s   **/   r	   s   **s   (/.*)?r   r   s   /?s   \Z)r   	enumeratesplitr   r   r$   endswith)r%   r   r   r   s       r#   	translater-   L   s    C3ss8y
~~f !""gy
~~d !""g		$00 U U
7e9Cq1uuBIdOOO#9KG9T9TTTCC<< u<r   fc              #     K   | D ]}|                     d          }|                                s,|                    d          rB|                    d          rI|                    d          s4|dd         }|                    d          r|                    d          4|                    dd          }|V  dS )zlRead a git ignore file.

    Args:
      f: File-like object to read from
    Returns: List of patterns
    s   
   #    s   \ Nr(   )rstripstripr   r,   r   )r.   lines     r#   read_ignore_patternsr5   o   s         {{7## zz|| 	??4   	 mmD!! 	$--*?*? 	9D mmD!! 	$--*?*? 	||FD))



! r   Fpathpattern
ignorecasec                 H    t          ||                              |           S )zMatch a gitignore-style pattern against a path.

    Args:
      path: Path to match
      pattern: Pattern to match
      ignorecase: Whether to do case-sensitive matching
    Returns:
      bool indicating whether the pattern matched
    )Patternmatch)r6   r7   r8   s      r#   match_patternr<      s"     7J''--d333r   c                   l    e Zd ZdZddededdfdZdefdZdefd	Z	d
e
defdZdefdZdedefdZdS )r:   zA single ignore pattern.Fr7   r8   r   Nc                    || _         || _        |dd         dk    rd| _        |dd          }n|dd         dk    r
|dd          }d| _        d}| j        rt          j        }t          j        t          |          |          | _        d S )Nr   r	   r   Fr   T)r7   r8   
is_excluder   
IGNORECASEcompiler-   _re)selfr7   r8   flagss       r#   __init__zPattern.__init__   s    $1Q3<4#DOabbkGGqs|u$$!!""+"DO? 	"ME:i00%88r   c                     | j         S N)r7   rC   s    r#   	__bytes__zPattern.__bytes__   s
    |r   c                 4    t          j        | j                  S rG   )osfsdecoder7   rH   s    r#   __str__zPattern.__str__   s    {4<(((r   otherc                 |    t          |t          |                     o| j        |j        k    o| j        |j        k    S rG   )
isinstancetyper7   r8   )rC   rN   s     r#   __eq__zPattern.__eq__   s=    ud4jj)) 4-45#33	
r   c                 P    t          |           j         d| j        d| j        dS N(z, ))rQ   __name__r7   r8   rH   s    r#   __repr__zPattern.__repr__   s.    t**%NNNN$/NNNNr   r6   c                 P    t          | j                            |                    S )zTry to match a path against this ignore pattern.

        Args:
          path: Path to match (relative to ignore location)
        Returns: boolean
        )boolrB   r;   rC   r6   s     r#   r;   zPattern.match   s      DHNN4(()))r   F)rW   
__module____qualname____doc__bytesrZ   rE   rI   strrM   objectrR   rX   r;    r   r#   r:   r:      s        ""9 9 94 9D 9 9 9 95    ) ) ) ) )
F 
t 
 
 
 
O# O O O O*% *D * * * * * *r   r:   c                       e Zd Z	 ddee         deddfdZdeddfdZd	eee	f         dee
         fd
Zd	edee         fdZeddedd fd            Zde	fdZdS )IgnoreFilterFNpatternsr8   r   c                 d    g | _         || _        || _        |D ]}|                     |           d S rG   )	_patterns_ignorecase_pathappend_pattern)rC   rf   r8   r6   r7   s        r#   rE   zIgnoreFilter.__init__   sJ     )+%
 	) 	)G((((	) 	)r   r7   c                 `    | j                             t          || j                             dS )zAdd a pattern to the set.N)rh   appendr:   ri   )rC   r7   s     r#   rk   zIgnoreFilter.append_pattern   s+    ggt/?@@AAAAAr   r6   c              #      K   t          |t                    st          j        |          }| j        D ]}|                    |          r|V  dS )zYield all matching patterns for path.

        Args:
          path: Path to match
        Returns:
          Iterator over iterators
        N)rP   r`   rK   fsencoderh   r;   )rC   r6   r7   s      r#   find_matchingzIgnoreFilter.find_matching   sb       $&& 	%;t$$D~ 	 	G}}T"" 	 	r   c                 H    d}|                      |          D ]	}|j        }
|S )zCheck whether a path is ignored.

        For directories, include a trailing slash.

        Returns: status is None if file is not mentioned, True if it is
            included, False if it is explicitly excluded.
        N)rp   r?   )rC   r6   statusr7   s       r#   
is_ignoredzIgnoreFilter.is_ignored   s5     ))$// 	( 	(G'FFr   c                     t          |d          5 } | t          |          ||          cd d d            S # 1 swxY w Y   d S )Nrb)r6   )openr5   )clsr6   r8   r.   s       r#   	from_pathzIgnoreFilter.from_path   s    $ 	G3+A..
FFF	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	G 	Gs   9= =c                     t          | dd           }|t          |           j         d|dS dt          |           j         dS )Nrj   z.from_path(rV   <>)getattrrQ   rW   r[   s     r#   rX   zIgnoreFilter.__repr__   sS    tWd++4jj)??d????-tDzz*----r   )FNr\   )rW   r]   r^   r   r`   rZ   rE   rk   r   ra   r:   rp   r   rs   classmethodrx   rX   rc   r   r#   re   re      s       HL) ) )59)	) ) ) )Be B B B B B%s
"3 8I    u $     G G G. G G G [G.# . . . . . .r   re   c                   6    e Zd ZdZddZdedee         fdZdS )IgnoreFilterStackz,Check for ignore status in multiple filters.r   Nc                     || _         d S rG   )_filters)rC   filterss     r#   rE   zIgnoreFilterStack.__init__   s    r   r6   c                 T    d}| j         D ]}|                    |          }||c S |S )Check whether a path is explicitly included or excluded in ignores.

        Args:
          path: Path to check
        Returns:
          None if the file is not mentioned, True if it is included,
          False if it is explicitly excluded.
        N)r   rs   )rC   r6   rr   filters       r#   rs   zIgnoreFilterStack.is_ignored   sF     m 	 	F&&t,,F! "r   )r   N)	rW   r]   r^   r_   rE   ra   r   rZ   rs   rc   r   r#   r   r      sT        66       s x~      r   r   configc                     	 |                      dd          }t          |t                    sJ |                    d          S # t          $ r Y nw xY wt          dd          S )zReturn default user ignore filter path.

    Args:
      config: A Config object
    Returns:
      Path to a global ignore file
    )   cores   excludesFilezutf-8)encodinggitignore)getrP   r`   decodeKeyErrorr   )r   values     r#   default_user_ignore_filter_pathr     sv    

:77%'''''||W|---    $E8444s   AA 
AAc                       e Zd ZdZdedee         deddfdZdefdZ	d	ede
e         fd
Zd	edee         fdZd	ede
e         fdZedd            ZdS )IgnoreFilterManagerzIgnore file manager.top_pathglobal_filtersr8   r   Nc                 >    i | _         || _        || _        || _        d S rG   )_path_filters	_top_path_global_filtersri   )rC   r   r   r8   s       r#   rE   zIgnoreFilterManager.__init__$  s+     AC!-%r   c                 `    t          |           j         d| j         d| j        d| j        dS rT   )rQ   rW   r   r   ri   rH   s    r#   rX   zIgnoreFilterManager.__repr__/  s;    t**%iiii$:NiiTXTdiiiir   r6   c                 ,   	 | j         |         S # t          $ r Y nw xY wt          j                            | j        |d          }	 t                              || j                  | j         |<   n# t          $ r d | j         |<   Y nw xY w| j         |         S )Nz
.gitignore)
r   r   rK   r6   joinr   re   rx   ri   OSError)rC   r6   ps      r#   
_load_pathzIgnoreFilterManager._load_path2  s    	%d++ 	 	 	D	 GLL|<<	,'3'='=aAQ'R'RDt$$ 	, 	, 	,'+Dt$$$	,!$''s    
(A/ /BBc                    t           j                            |          rt          | d          d | j        D             }t           j        j        dk    r%|                    t           j        j        d          }|                    d          }g }t          t          |          dz             D ]}d
                    |d|                   }|D ]_\  }}d
                    |||                   }	|t          |          k     r|	dz  }	|t          |                    |	                    z  }`|                     |          }
|
|                    d||
f           t          |          S )zFind matching patterns for path.

        Args:
          path: Path to check
        Returns:
          Iterator over Pattern instances
        z is an absolute pathc                     g | ]}d |fS )r   rc   ).0r.   s     r#   
<listcomp>z5IgnoreFilterManager.find_matching.<locals>.<listcomp>I  s    888aAq6888r   /r	   Nr   )rK   r6   isabs
ValueErrorr   sepr   r+   ranger   r   listrp   r   insertiter)rC   r6   r   partsmatchesr   dirnamesr.   relpathignore_filters              r#   rp   z!IgnoreFilterManager.find_matching?  s^    7== 	<:::;;;884#78887;#<<S11D

3s5zzA~&& 	6 	6AhhuRaRy))G : :1((51:..s5zz>> sNG4 8 8999 OOG44M(q1m"4555G}}r   c                 h    t          |                     |                    }|r|d         j        S dS )r   r(   N)r   rp   r?   )rC   r6   r   s      r#   rs   zIgnoreFilterManager.is_ignored\  s9     t))$//00 	*2;))tr   repor
   c           	         g }t           j                            |                                dd          t	          |                                          fD ]x}t          t                    5  |                    t          
                    t           j                            |                               ddd           n# 1 swxY w Y   y|                                }|                    ddd          } | |j        ||          S )zCreate a IgnoreFilterManager from a repository.

        Args:
          repo: Repository object
        Returns:
          A `IgnoreFilterManager` object
        infoexcludeNr   s
   ignorecaseF)rK   r6   r   
controldirr   get_config_stackr   r   rm   re   rx   
expanduserget_boolean)rw   r   r   r   r   r8   s         r#   	from_repozIgnoreFilterManager.from_repoj  s:    GLL**FI>>+D,A,A,C,CDD
 	U 	UA '"" U U%%l&<&<RW=O=OPQ=R=R&S&STTTU U U U U U U U U U U U U U U&&((''MEJJ
s49nj999s   -ACC	C	)r   r
   r   r   )rW   r]   r^   r_   ra   r   re   rZ   rE   rX   r   r   r   r:   rp   rs   r}   r   rc   r   r#   r   r   !  s       	&	& \*	& 		&
 
	& 	& 	& 	&j# j j j j(s (x'= ( ( ( (# (7*;    :s x~     : : : [: : :r   r   r\   )r_   os.pathrK   r   collections.abcr   
contextlibr   typingr   r   r   r   r   r
   r   r   r   r`   r$   r-   r5   rZ   r<   r:   re   r   ra   r   r   rc   r   r#   <module>r      s  * 
  				 $ $ $ $ $ $       ; ; ; ; ; ; ; ; ; ; ; ;  4 4 4 4 4 4 4 4# #% # # # #L 5  U        FH %    4
4 
4 
4 
44 
4D 
4 
4 
4 
4)* )* )* )* )* )* )* )*X3. 3. 3. 3. 3. 3. 3. 3.l       .5F 5s 5 5 5 5$[: [: [: [: [: [: [: [: [: [:r   