a
    K56añ  ã                   @   s4   d dl Z ddlmZ d
dd„Zddd„Zdd	„ ZdS )é    Né   )Ú
exceptionsc                 C   sz   | du rdS zt  |t jt jB ¡}W n   tj‚Y n0 g }|du rTttt| ƒƒƒ}|D ]}| 	| | ¡rX| 
|¡ qX|S )z;Use the pattern_str to find any match in a list of strings.N)ÚreÚcompileÚIÚMr   ZInvalidRegexÚlistÚrangeÚlenÚsearchÚappend)ZstrlistÚpattern_strZsubindexZpatÚ
resultlistÚi© r   ú5/usr/lib/python3/dist-packages/reportbug/hiermatch.pyÚ
egrep_list
   s    r   c                 C   sb   g }t t| ƒƒD ]L}|r@|| r:t| | | ||| ƒ}qRg }nt| | | |ƒ}| |¡ q|S )z3Grep the nth item of a hierarchy [(x, [a, b]),...].)r	   r
   r   r   )Úhierr   ZsubhierZnthZ
resulthierr   r   r   r   r   Úegrep_hierarchy   s    r   c                    sZ   g }t ˆ |ƒ}tt|ƒƒD ]:‰|ˆ r‡ ‡fdd„|ˆ D ƒ}| ˆ ˆ d |f¡ q|S )z8Actually create a new hierarchy from a pattern matching.c                    s   g | ]}ˆ ˆ d  | ‘qS )r   r   )Ú.0Úy©r   r   r   r   Ú
<listcomp>7   ó    z%matched_hierarchy.<locals>.<listcomp>r   )r   r	   r
   r   )r   r   ZmhierÚresultÚitemr   r   r   Úmatched_hierarchy1   s    
r   )N)Nr   )r   Ú r   r   r   r   r   r   r   r   Ú<module>   s   

