
    &=d                     0    d dl Z ddlmZ ddZddZd ZdS )	    N   )
exceptionsc                 b   | dS 	 t          j        |t           j        t           j        z            }n# t          $ r t
          j        w xY wg }|)t          t          t          |                               }|D ]2}|
                    | |                   r|                    |           3|S )am  
    Use the pattern_str to find any match in a list of strings

    This is a helper function for :func:`egrep_hierarchy`.

    Note that this function is never called with the `subindex`
    parameter set.

    Parameters
    ----------
    strlist : [str, ...]
        list of strings in which to look for the pattern
    pattern_str : str
        regular expression pattern
    subindex : [int, ...]
        list of indexes of strings in strlist, specifying the elements
        in which to look for the pattern

    Returns
    -------
    [int, ...]
        a list of indexes for the matches in the origin list
    N)recompileIM	Exceptionr   InvalidRegexlistrangelensearchappend)strlistpattern_strsubindexpat
resultlistis         5/usr/lib/python3/dist-packages/reportbug/hiermatch.py
egrep_listr   
   s    0 t&jbdRTk22 & & &%%& Jc'll++,, ! !::gaj!! 	!a   s	   ,3 A
c                    g }t          t          |                     D ]d}|r/||         r$t          | |         |         |||                   }ng }nt          | |         |         |          }|                    |           e|S )a  
    Grep the nth item of a hierarchy [(x, [a, b]),...]

    This is a helper function for :func:`matched_hierarchy`.

    Note that this function is never called with the `subhier` and `nth`
    parameters set.

    Parameters
    ----------
    hier : [(str, [str, ...]), (str, [str, ...]), ...]
        list of tuples with severity and bug list
    pattern_str : str
        regular expression pattern
    subhier : [[int, ...], ...], optional
        subhierarchy indices
    nth : int, optional
        should always be 1 (one)

    Returns
    -------
    [[int, ...], [int, ...], ...]
        a subhierarchy (for each severity in the input hierarchy, the
        list of indexes of the bugs matching the pattern_str)
    )r   r   r   r   )hierr   subhiernth
resulthierr   r   s          r   egrep_hierarchyr   3   s    4 J3t99 	& 	& 	?qz  'Qk71:NN



#DGCL+>>J*%%%%    c                      g }t           |          }t          t          |                    D ]B|         r8 fd|         D             }|                              d         |f           C|S )a  
    Create a new hierarchy from a pattern matching

    Parameters
    ----------
    hier : [(str, [str, ...]), (str, [str, ...]), ...]
        list of tuples with severity and bug list
    pattern_str : str
        regular expression pattern

    Returns
    -------
    [(str, [str, ...]), (str, [str, ...]), ...]
        list of tuples with severity and bug list, only including bugs
        matching the pattern_str
    c                 8    g | ]}         d          |         S )r    ).0yr   r   s     r   
<listcomp>z%matched_hierarchy.<locals>.<listcomp>q   s%    555aDGAJqM555r   r   )r   r   r   r   )r   r   mhierresultitemr   s   `    @r   matched_hierarchyr)   \   s    " ET;//F3v;; - -!9 	-555556!9555DLL$q'!*d+,,,Lr   )N)Nr   )r    r   r   r   r)   r"   r   r   <module>r+      se    
			      & & & &R& & & &R    r   