@@ -536,9 +536,11 @@ def _callable_name(fn):
536536 return fn_name
537537
538538
539- def _extractiter_tag (patt , filename , tag , conv , encoding ):
539+ def _extractiter_singletag (patt , filename , tag , conv , encoding ):
540540 if isinstance (conv , collections .Iterable ):
541- conv = conv [0 ]
541+ raise SanityError (
542+ f'multiple conversion functions given for single group: { tag } '
543+ )
542544
543545 for m in finditer (patt , filename , encoding ):
544546 try :
@@ -551,7 +553,8 @@ def _extractiter_tag(patt, filename, tag, conv, encoding):
551553 except ValueError :
552554 fn_name = _callable_name (conv )
553555 raise SanityError (
554- f'could not convert value { val !r} using { fn_name } ()' )
556+ f'could not convert value { val !r} using { fn_name } ()'
557+ )
555558
556559
557560def _extractiter_multitag (patt , filename , tags , conv , encoding ):
@@ -569,16 +572,16 @@ def _extractiter_multitag(patt, filename, tags, conv, encoding):
569572 elif builtins .len (conv ) > builtins .len (val ):
570573 conv = conv [:builtins .len (val )]
571574
572- # Here we use the last conversion function for the remaining
573- # tags which don't have a corresponding one, if length of the
574- # conversion function iterable is less that the one of tags
575+ # Use the last function in case we have less conversion functions than
576+ # tags
575577 for v , c in itertools .zip_longest (val , conv , fillvalue = conv [- 1 ]):
576578 try :
577579 converted_vals .append (c (v ) if callable (c ) else v )
578580 except ValueError :
579581 fn_name = _callable_name (conv )
580582 raise SanityError (
581- f'could not convert value { v !r} using { fn_name } ()' )
583+ f'could not convert value { v !r} using { fn_name } ()'
584+ )
582585
583586 yield tuple (converted_vals )
584587
@@ -595,7 +598,7 @@ def extractiter(patt, filename, tag=0, conv=None, encoding='utf-8'):
595598 if isinstance (tag , collections .Iterable ) and not isinstance (tag , str ):
596599 yield from _extractiter_multitag (patt , filename , tag , conv , encoding )
597600 else :
598- yield from _extractiter_tag (patt , filename , tag , conv , encoding )
601+ yield from _extractiter_singletag (patt , filename , tag , conv , encoding )
599602
600603
601604@deferrable
@@ -618,24 +621,22 @@ def extractall(patt, filename, tag=0, conv=None, encoding='utf-8'):
618621 returns the whole line that was matched.
619622 :arg conv: A callable or iterable of callables taking a single argument
620623 and returning a new value.
621- If provided, and is not an iterable it will be used to convert
622- the extracted values for all the capturing groups of ``tag``
623- returning the converted values.
624- If an iterable of callables is provided, each one will be used to
625- convert the corresponding extracted capturing group of `tag`.
626- If more callables functions than the corresponding capturing groups of
627- ``tag`` are provided, the last conversion function is used for the
628- remaining capturing groups.
629- :returns: A list of the extracted values from the matched regex if ``tag``
630- converted using the ``conv`` callable if ``tag`` is a single value.
631- In case of multiple capturing groups, a list of tuples where each one
632- contains the extracted capturing converted using the corresponding
633- callable of ``conv``.
624+ If not an iterable it will be used to convert the extracted values for
625+ all the capturing groups specified in ``tag``.
626+ Otherwise, each conversion function will be used to convert the value
627+ extracted from the corresponding capturing group in ``tag``.
628+ If more conversion functions are supplied than the corresponding
629+ capturing groups in ``tag``, the last conversion function will be used
630+ for the additional capturing groups.
631+ :returns: A list of tuples of converted values extracted from the
632+ capturing groups specified in ``tag``, if ``tag`` is an iterable.
633+ Otherwise, a list of the converted values extracted from the single
634+ capturing group specified in ``tag``.
634635 :raises reframe.core.exceptions.SanityError: In case of errors.
635636
636637 .. versionchanged:: 3.1
637638 Multiple regex capturing groups are now supporetd via ``tag`` and
638- multiple callables can be used in ``conv``.
639+ multiple conversion functions can be used in ``conv``.
639640 '''
640641 return list (evaluate (x )
641642 for x in extractiter (patt , filename , tag , conv , encoding ))
0 commit comments