@@ -566,23 +566,39 @@ class a:
566566 # Data collector with pattern.
567567 # Match with the following pattern.
568568 # var_name{pattern1}{pattern2}{...}
569+ # Optional post-indexing: var_name{pattern}[0] to get single value
569570
570571 name = name [: name .find ("{" )]
571572 val = Get_Shared_Variables (name , log = False )
572573
573574 if val == "zeuz_failed" :
574575 return "zeuz_failed"
575576
577+ # Separate {} collector patterns from trailing [] post-indices
578+ rest = copy_of_name [copy_of_name .find ("{" ):]
579+ last_brace = rest .rfind ("}" )
580+ trailing = rest [last_brace + 1 :] if last_brace >= 0 else ""
581+ collector_patterns = re .findall (r"\{(.*?)\}" , rest )
582+ post_indices = re .findall (r"\[(.*?)\]" , trailing )
583+
576584 result = []
577585
578- for idx in indices :
586+ for idx in collector_patterns :
579587 result .append (data_collector .collect (idx , val , "pattern" ))
580588
581- if len (indices ) > 1 :
589+ if len (collector_patterns ) > 1 :
582590 result = list (zip (* result ))
583- elif len (indices ) == 1 :
591+ elif len (collector_patterns ) == 1 :
584592 result = result [0 ]
585593
594+ # Apply post-indexing if specified (e.g., var{pattern}[0] to get single value)
595+ for idx in post_indices :
596+ try :
597+ result = result [int (idx )]
598+ except (ValueError , IndexError , TypeError ) as e :
599+ CommonUtil .ExecLog (sModuleInfo , "Post-index [%s] could not be applied to data collector result: %s" % (idx , str (e )), 3 )
600+ return "zeuz_failed"
601+
586602 # send variable value in report logs and terminal
587603 if str (shared_variables ['zeuz_enable_variable_logging' ]).lower () in {"on" , "yes" , "true" , "1" }:
588604 CommonUtil .AddVariableToLog (sModuleInfo , copy_of_name , result )
@@ -595,21 +611,44 @@ class a:
595611 # Data collector with keys.
596612 # Match with the following pattern.
597613 # var_name(pattern1)(pattern2)(...)
614+ # Optional post-indexing: var_name(key)[0] to get single value
598615
599616 name = name [: name .find ("(" )]
600617 val = Get_Shared_Variables (name , log = False )
601618
602619 if val == "zeuz_failed" :
603620 return "zeuz_failed"
604621
622+ # Separate () collector patterns from trailing [] post-indices
623+ rest = copy_of_name [copy_of_name .find ("(" ):]
624+ last_paren = rest .rfind (")" )
625+ trailing = rest [last_paren + 1 :] if last_paren >= 0 else ""
626+ collector_patterns = re .findall (r"\((.*?)\)" , rest )
627+ post_indices = re .findall (r"\[(.*?)\]" , trailing )
628+
605629 result = []
606630
607- for idx in indices :
631+ for idx in collector_patterns :
608632 result .append (data_collector .collect (idx , val , "key" ))
609633
610- if len (indices ) == 1 :
634+ if len (collector_patterns ) == 1 :
611635 result = result [0 ]
612636
637+ # Apply post-indexing if specified (e.g., var(key)['line'][0] to get single value)
638+ for idx in post_indices :
639+ try :
640+ result = result [int (idx )]
641+ except ValueError :
642+ # Try string key access (e.g., var(key)['line'])
643+ try :
644+ result = result [idx .strip ("'\" " )]
645+ except (KeyError , TypeError , IndexError ) as e :
646+ CommonUtil .ExecLog (sModuleInfo , "Post-index [%s] could not be applied to key collector result: %s" % (idx , str (e )), 3 )
647+ return "zeuz_failed"
648+ except (IndexError , TypeError ) as e :
649+ CommonUtil .ExecLog (sModuleInfo , "Post-index [%s] could not be applied to key collector result: %s" % (idx , str (e )), 3 )
650+ return "zeuz_failed"
651+
613652 if str (shared_variables ['zeuz_enable_variable_logging' ]).lower () in {"on" , "yes" , "true" , "1" }:
614653 CommonUtil .AddVariableToLog (sModuleInfo , copy_of_name , result )
615654
0 commit comments