
    z#g                     2    S SK r SSKJr  SS jrSS jrS rg)	    N   )
exceptionsc                 d   U c  g [         R                  " U[         R                  [         R                  -  5      n/ nUc  [        [        [        U 5      5      5      nU H.  nUR                  X   5      (       d  M  UR                  U5        M0     U$ ! [         a    [
        R                  ef = f)a%  
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 &jjbddRTTk2 Jc'l+,::gj!!a     &%%%&s   6B B/c                     / n[        [        U 5      5       HM  nU(       a!  X%   (       a  [        X   U   XU   5      nO/ nO[        X   U   U5      nUR                  U5        MO     U$ )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   sg    4 J3t9z'k1:N

#DGCL+>J*%      c                     / n[        X5      n[        [        U5      5       HB  nX4   (       d  M  X4    Vs/ s H  oPU   S   U   PM     nnUR                  X   S   U45        MD     U$ s  snf )av  
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
r   r   )r   r   r   r   )r   r   mhierresultr   yitems          r   matched_hierarchyr%   \   sp    " ET/F3v;99+1959aGAJqM9D5LL$'!*d+,   L 6s   A*)N)Nr   )r    r   r   r   r%    r   r   <module>r(      s    
 &R&Rr   