�
�&=d� � �0 � d dl Z ddlmZ dd�Zdd�Zd� ZdS ) � N� )�
exceptionsc �b � | �dS t j |t j t j z � � }n# t $ r
t
j �w xY wg }|�)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��b�d�R�T�k�2�2����� &� &� &��%�%�&���� �J�����c�'�l�l�+�+�,�,��
� !� !���:�:�g�a�j�!�!� !����a� � � ���s �,3 �A
c � � g }t t | � � � � D ]d}|r/|| r$t | | | ||| � � }ng }nt | | | |� � }|� |� � �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�
�3�t�9�9�
�
� &� &��� ?��q�z�
�'��Q����k�7�1�:�N�N�
�
��
�
�#�D��G�C�L�+�>�>�J����*�%�%�%�%��� c �� � �� g }t � |� � }t t |� � � � D ]B�|� r8� �fd�|� 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�5�a�D��G�A�J�q�M�5�5�5r r )r r
r r )r r �mhier�result�itemr s ` @r �matched_hierarchyr) \ s� ��� �" |