o
    Uh                     @   s   d Z ddlZddlmZ ddlmZ ddlmZmZ ddl	m
Z
mZ ded	ed
efddZdeded
efddZde
dee d
ee fddZdS )zbSupport for git credential helpers.

https://git-scm.com/book/en/v2/Git-Tools-Credential-Storage

    N)Iterator)Optional)ParseResulturlparse   )
ConfigDictSectionLikeurl
url_prefixreturnc                 C   s^   | j |j ko| j|jko| j|jk}|jr| j|jknd}| jd|j }|o.|o.|S )NT/)schemehostnameportusernamepathrstrip
startswith)r	   r
   
base_match
user_match
path_match r   g/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/dulwich/credentials.py
match_urls%   s   

r   	valid_urlpartial_urlc                 C   s   d|vrt d| }nt |}| j|jkrdS t|jo | j|jk|jo(| j|jk|jo0| j|jk|jo>|jd| jdkfrCdS dS )z;Matches a parsed url with a partial url (no scheme/netloc).z://z	scheme://Fr   T)r   r   anyr   r   r   r   r   )r   r   parsedr   r   r   match_partial_url0   s   r   configc                 c   s    | j pt }t|pd}|  D ]4}|d dkrqt|dk r%|V  q|d |}t|}|jr<|jr<t	||}nt
||}|rF|V  qdS )zFReturns credential sections from the config which match the given URL. r   s
   credential   r   N)encodingsysgetdefaultencodingr   sectionslendecoder   netlocr   r   )r   r	   r"   
parsed_urlconfig_section
config_urlparsed_config_urlis_matchr   r   r   urlmatch_credential_sectionsF   s$   
r.   )__doc__r#   collections.abcr   typingr   urllib.parser   r   r   r   r   boolr   strr   r.   r   r   r   r   <module>   s   