o
     JAf 2                     @   s   	 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mZ d dl	m
Z
 G dd dZdd Ze jfd	d
Zdd ZdddZdS )    Nconvert_path)DistutilsTemplateErrorDistutilsInternalError)logc                   @   s|   e Zd Z	 dddZdd ZejfddZdd	 Zd
d Z	dd Z
dd Zdd Zdd Zdd ZdddZ	dddZdS )FileListNc                 C   s   d | _ g | _d S N)allfilesfiles)selfwarndebug_print r   )/usr/lib/python3.10/distutils/filelist.py__init__   s   
zFileList.__init__c                 C   s
   || _ d S r   )r	   )r   r	   r   r   r   set_allfiles#   s   
zFileList.set_allfilesc                 C   s   t || _d S r   )findallr	   )r   dirr   r   r   r   &   s   zFileList.findallc                 C   s"   	 ddl m} |rt| d S d S )Nr   )DEBUG)Zdistutils.debugr   print)r   msgr   r   r   r   r   )   s
   zFileList.debug_printc                 C      | j | d S r   )r
   append)r   itemr   r   r   r   3      zFileList.appendc                 C   r   r   )r
   extend)r   itemsr   r   r   r   6   r   zFileList.extendc                 C   s<   t ttjj| j}g | _|D ]}| jtjj|  qd S r   )sortedmapospathsplitr
   r   join)r   Zsortable_filesZ
sort_tupler   r   r   sort9   s
   zFileList.sortc                 C   s@   t t| jd ddD ]}| j| | j|d  kr| j|= qd S )N   r   )rangelenr
   )r   ir   r   r   remove_duplicatesC   s
   zFileList.remove_duplicatesc                 C   s   |  }|d }d  } }}|dv r*t|dk rtd| dd |dd  D }n?|dv rLt|d	k r:td
| t|d }dd |dd  D }n|dv rct|dkr\td| t|d }ntd| ||||fS )Nr   )includeexcludeglobal-includeglobal-exclude   z&'%s' expects <pattern1> <pattern2> ...c                 S      g | ]}t |qS r   r   .0wr   r   r   
<listcomp>W       z1FileList._parse_template_line.<locals>.<listcomp>r$   )recursive-includerecursive-exclude   z,'%s' expects <dir> <pattern1> <pattern2> ...c                 S   r/   r   r   r0   r   r   r   r3   ]   r4   )graftprunez#'%s' expects a single <dir_pattern>zunknown action '%s')r!   r'   r   r   )r   linewordsactionpatternsr   dir_patternr   r   r   _parse_template_lineL   s0   zFileList._parse_template_linec                 C   s6  |  |\}}}}|dkr+| dd|  |D ]}| j|dds(td| qd S |dkrM| dd|  |D ]}| j|ddsJtd	| q;d S |d
kro| dd|  |D ]}| j|ddsltd| q]d S |dkr| dd|  |D ]}| j|ddstd| qd S |dkr| d|d|f  |D ]}| j||dstd|| qd S |dkr| d|d|f  |D ]}| j||dstd|| qd S |dkr| d|  | jd |dstd| d S d S |dkr| d|  | jd |dstd| d S d S td| )Nr*   zinclude  r$   )anchorz%warning: no files found matching '%s'r+   zexclude z9warning: no previously-included files found matching '%s'r,   zglobal-include r   z>warning: no files found matching '%s' anywhere in distributionr-   zglobal-exclude zRwarning: no previously-included files matching '%s' found anywhere in distributionr5   zrecursive-include %s %s)prefixz:warning: no files found matching '%s' under directory '%s'r6   zrecursive-exclude %s %szNwarning: no previously-included files matching '%s' found under directory '%s'r8   zgraft z+warning: no directories found matching '%s'r9   zprune z6no previously-included directories found matching '%s'z'this cannot happen: invalid action '%s')r?   r   r"   include_patternr   r   exclude_patternr   )r   r:   r<   r=   r   r>   patternr   r   r   process_template_lineh   s   
zFileList.process_template_liner$   r   c                 C   sn   	 d}t ||||}| d|j  | jd u r|   | jD ]}||r4| d|  | j| d}q|S )NFz%include_pattern: applying regex r'%s'z adding T)translate_patternr   rE   r	   r   searchr
   r   )r   rE   rA   rB   is_regexfiles_found
pattern_renamer   r   r   rC      s   


zFileList.include_patternc                 C   st   	 d}t ||||}| d|j  tt| jd ddD ]}|| j| r7| d| j|   | j|= d}q|S )NFz%exclude_pattern: applying regex r'%s'r$   r%   z
 removing T)rG   r   rE   r&   r'   r
   rH   )r   rE   rA   rB   rI   rJ   rK   r(   r   r   r   rD      s   zFileList.exclude_pattern)NNr$   Nr   )__name__
__module____qualname__r   r   r   curdirr   r   r   r   r#   r)   r?   rF   rC   rD   r   r   r   r   r      s    


	
L,r   c                 C   s(   	 dd t j| ddD }tt jj|S )Nc                 s   s.    | ]\}}}|D ]
}t j||V  q	qd S r   )r   r    r"   )r1   basedirsr
   filer   r   r   	<genexpr>   s    z#_find_all_simple.<locals>.<genexpr>T)followlinks)r   walkfilterr    isfile)r    resultsr   r   r   _find_all_simple   s
   r[   c                 C   s8   	 t | }| tjkrtjtjj| d}t||}t|S )N)start)	r[   r   rQ   	functoolspartialr    relpathr   list)r   r
   Zmake_relr   r   r   r     s   

r   c                 C   s:   	 t | }tj}tjdkrd}d| }td||}|S )N\z\\\\z\1[^%s]z((?<!\\)(\\\\)*)\.)fnmatch	translater   sepresub)rE   rK   rd   escapedr   r   r   
glob_to_re  s   

rh   r$   c           
      C   s   	 |rt | trt| S | S tdd\}}}| r t| }nd}|d urZt|}|t|t|t|  }tj}	tjdkrBd}	|t|t|t|  }d|||	||f }n|rhd||t|d  f }t|S )N_ ra   z\\z%s\A%s%s.*%s%sz%s\A%s)	
isinstancestrre   compilerh   	partitionr'   r   rd   )
rE   rA   rB   rI   r\   ri   endrK   Z	prefix_rerd   r   r   r   rG   %  s(   




rG   rM   )r   re   rb   r]   Zdistutils.utilr   Zdistutils.errorsr   r   Z	distutilsr   r   r[   rQ   r   rh   rG   r   r   r   r   <module>   s     i