
    biJ                      (   d dl Z d dlZd dlZd dlZd dlZddlmZ ddlmZ er ej                  d      n ej                  d      Z	 ej                  d      Z
d	ed
efdZddZddZd Z	 	 ddZd Zd Zd ZddZ G d d      Z G d d      Zy)    N   )IS_WINDOWS_PLATFORM   )fnmatchz/|\\/zy^[a-z0-9]+((\.|_|__|-+)[a-z0-9]+)*(?::[0-9]+)?(/[a-z0-9]+((\.|_|__|-+)[a-z0-9]+)*)*(:[a-zA-Z0-9_][a-zA-Z0-9._-]{0,127})?$tagreturnc                 >    t        t        j                  |             S N)bool_TAGmatch)r   s    M/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/docker/utils/build.py	match_tagr      s    

3      c           
          t         j                  j                  |       }|xs g }|xs d}g }|d   #dj                  |xs dg|d   gz         }d|f|g}t	        t        t        |||d               ||||      S )N)NNr   
z.dockerignorer   )
dockerfile)filesrootfileobjgzipextra_files)ospathabspathjoincreate_archivesortedexclude_paths)r   excluder   r   r   r   r   dockerignore_contentss           r   tarr#      s    77??4 DmG+|JK!}  $		))jm_<!
 34
 ]4Z]KL7; r   c                 |    |d}|j                  d|        t        |      }t        |j                  |             S )a	  
    Given a root directory path and a list of .dockerignore patterns, return
    an iterator of all paths (both regular files and directories) in the root
    directory that do *not* match any of the patterns.

    All paths returned are relative to the root.
    
Dockerfile!)appendPatternMatchersetwalk)r   patternsr   pms       r   r    r    )   s?     !
OOa
|$%		!Brwwt}r   c           	          g }t        j                  |       D ]a  \  }}}||z   D ]S  }t         j                  j                  ||      }|j	                  |j                  | dd      j                  d             U c |S )N r   r   )r   r*   r   r   r'   replacelstrip)r   r   dirnamedirnamesfnamesfilenamelongpaths          r   build_file_listr6   :   s}    E%'WWT] !6) 	Hww||GX6HLL  r1-44S9	 Lr   c                    |xs g }|st        j                         }t        j                  |rdnd|      }|t	        |       }|D ch c]  }|d   	 }}|D ]  }||v rt
        j                  j                  | |      }	|j                  |	|      }
|
>|
j                  dk  s|
j                  dkD  rt        |
j                        |
_	        t        r|
j                  dz  dz  |
_        |
j                         r)	 t        |	d	      5 }|j                  |
|       d d d        |j                  |
d         |D ]`  \  }}t        j                   |      }|j#                  d      }t%        |      |_        |j                  |t)        j*                  |             b |j-                          |j/                  d       |S c c}w # 1 sw Y   xY w# t        $ r}t        d
|	       |d }~ww xY w)Nzw:gzwmoder   r   )arcnamel    i  I   rbzCan not read file in context: zutf-8)tempfileNamedTemporaryFiletarfileopenr6   r   r   r   
gettarinfomtimeintr   r:   isfileaddfileOSErrorTarInfoencodelensizeioBytesIOcloseseek)r   r   r   r   r   teextra_namesr   	full_pathifoenamecontentsinfocontents_encodeds                    r   r   r   F   s   #K--/D&c7CA}%!,-A1Q4-K- ;GGLLt,	LLDL19  77Q;!''I-!''lAG VVe^e+AF88:)T* $aIIaO$ IIa?B & 6ht$#??73()				$

#345	6 GGILLONU .0$ $ 4YK@s6   	G=G	GGG	G	G/G**G/c                    t        j                         }t        j                  d|      }t	        | t
        j                        r t        j                  d      }t        d      t	        | t
        j                        rEt        j                  d      }t        | j                               |_        | j                  d       n|j                  | d      }|j                  ||        |j!                          |j                  d       |S )Nr8   r9   r%   zCPlease use io.BytesIO to create in-memory Dockerfiles with Python 3r   )r   r;   )r>   r?   r@   rA   
isinstancerL   StringIOrH   	TypeErrorrM   rJ   getvaluerK   rO   rB   rF   rN   )r   rU   rP   dfinfos       r   mkbuildcontextra   {   s    ##%A#q)A*bkk*. 4 5 	5	J

	+.*--/0j,GIIfj!GGIFF1IHr   c                 n    t        j                  t        |       D cg c]  }|s|dk7  s| c}S c c}w )N.)resplit_SEP)ppts     r   
split_pathri      s)    $*?2bR3YB???s   222c                 F    t         rdj                  t        |             S | S )Nr   )r   r   ri   rg   s    r   normalize_slashesrl      s    xx
1&&Hr   c                 :    t        |      }|j                  |       S r   )r(   r*   )r   r+   defaultr,   s       r   r*   r*      s    		!B774=r   c                       e Zd Zd Zd Zd Zy)r(   c                     t        t        d |D cg c]  }t        |       c}            | _        | j                  j	                  t        d             y c c}w )Nc                     | j                   S r   )dirsrk   s    r   <lambda>z)PatternMatcher.__init__.<locals>.<lambda>   s
    aff r   z!.dockerignore)listfilterPatternr+   r'   )selfr+   rg   s      r   __init__zPatternMatcher.__init__   sH    V8<awqz<
  	W%567 =s   Ac           
         d}t         j                  j                  |      }t        |      }| j                  D ]  }|j
                  }|j                  |      }|st|dk7  rot        |j                        t        |      k  rN|j                  t         j                  j                  j                  |d t        |j                                     }|s| } |S )NFr.   )r   r   r1   ri   r+   	exclusionr   rJ   rr   sepr   )rw   filepathmatchedparent_pathparent_path_dirspatternnegativer   s           r   matcheszPatternMatcher.matches   s    ggooh/%k2}} 
	'G((HMM(+E[B.w||$,<(==#MM(()9:L3w||;L)MNE &,
	' r   c                 &      fd       S )Nc              3     K   t        j                  |       D ]F  }t         j                  j                  t         j                  j	                  |       |      }|j                  dt         j                  j                         r|dd  }	j                  |      }|s| t         j                  j                  |      }t         j                  j                  |      rt         j                  j                  |      r|rLd}	j                  D ]7  }|j                  s|j                  j                  t        |            s5d} n |r7 |      E d {    I y 7 w)Nrc   r   TF)r   listdirr   r   relpath
startswithr{   r   isdirislinkr+   rz   cleaned_patternrl   )
current_dirrU   fpathr   curskippatrec_walkr   rw   s
          r   r   z%PatternMatcher.walk.<locals>.rec_walk   s     ZZ, )GGOOK6 ##a}$56!!"IEU+Kggll4/ww}}S)RWW^^C-@
  D#}} ""}}$..99 1% 8:#(D!"  #C=((=)< )s   EE&E&E$	E& )rw   r   r   s   ``@r   r*   zPatternMatcher.walk   s    	)B ~r   N)__name__
__module____qualname__rx   r   r*   r   r   r   r(   r(      s    8&"r   r(   c                   (    e Zd Zd Zed        Zd Zy)rv   c                     d| _         |j                  d      rd| _         |dd  }| j                  |      | _        dj	                  | j                        | _        y )NFr&   Tr   r   )rz   r   	normalizerr   r   r   )rw   pattern_strs     r   rx   zPattern.__init__   sN    !!#&!DN%ab/KNN;/	"xx		2r   c                     |j                         }d}t        |      }|t        |      k  r0||   dk(  r||= |dkD  r||dz
  = |dz  }n|dz  }|t        |      k  r0|S )Nr   z..r   )stripri   rJ   )clsrg   rT   re   s       r   r   zPattern.normalize   su     GGI 1#e*nQx4!Hq5a!eFAQ #e*n r   c                 @    t        t        |      | j                        S r   )r   rl   r   )rw   r|   s     r   r   zPattern.match  s    (2D4H4HIIr   N)r   r   r   rx   classmethodr   r   r   r   r   rv   rv      s!    3  4Jr   rv   )NNNFr   )NNFN)T)rL   r   rd   r@   r>   	constantsr   r   compilerf   r   strr   r   r#   r    r6   r   ra   ri   rl   r*   r(   rv   r   r   r   <module>r      s    	 	 	   + 2zrzz(


3rzz.!3 !4 !&"	 9>#2j&@< <~&J &Jr   