@@ -609,7 +609,7 @@ def get_value_from_context(param, context):
609
609
elif isinstance (value , list ):
610
610
msg , value = get_value_in_list (value , list_index , part )
611
611
elif hasattr (value , part ):
612
- value = getattr (value , part )
612
+ value = get_attribute (value , part )
613
613
else :
614
614
msg = get_value_context_errors (value , part )
615
615
if msg :
@@ -627,7 +627,10 @@ def get_list_index_value(value, is_list_with_index):
627
627
:param is_list_with_index: key that matchs the regex (.*){(.*)}, key{index}
628
628
:return: value and index updated
629
629
"""
630
- val = value [is_list_with_index .group (1 )]
630
+ try :
631
+ val = get_attribute (value , is_list_with_index .group (1 ))
632
+ except AttributeError :
633
+ val = value [is_list_with_index .group (1 )]
631
634
try :
632
635
idx = int (is_list_with_index .group (2 ))
633
636
except ValueError :
@@ -649,10 +652,24 @@ def get_value_in_list(value, list_index, part):
649
652
if list_index >= len (value ):
650
653
msg = f"Invalid index '{ list_index } ', list size is '{ len (value )} '. { list_index } >= { len (value )} ."
651
654
else :
652
- value = value [list_index ][ part ]
655
+ value = get_attribute ( value [list_index ], part )
653
656
return msg , value
654
657
655
658
659
+ def get_attribute (value , key ):
660
+ """
661
+ get the key attribute, accepts dictionary and classes
662
+
663
+ :param value: updated value of the dict
664
+ :param key: part to take in the value
665
+ :return: error msg and updated value
666
+ """
667
+ try :
668
+ return getattr (value , key )
669
+ except AttributeError :
670
+ return value [key ]
671
+
672
+
656
673
def get_value_context_errors (value , part ):
657
674
"""
658
675
Returns the errors
@@ -683,7 +700,7 @@ def _get_initial_value_from_context(initial_key, context):
683
700
if initial_key in context_storage :
684
701
value = context_storage [initial_key ]
685
702
elif hasattr (context , initial_key ):
686
- value = getattr (context , initial_key )
703
+ value = get_attribute (context , initial_key )
687
704
else :
688
705
msg = f"'{ initial_key } ' key not found in context"
689
706
logger .error (msg )
@@ -774,7 +791,7 @@ def get_file(file_path):
774
791
Return the content of a file given its path. If a base path was previously set by using
775
792
the set_file_path() function, the file path specified must be relative to that path.
776
793
777
- :param file path : file path using slash as separator (e.g. "resources/files/doc.txt")
794
+ :param file_path : file path using slash as separator (e.g. "resources/files/doc.txt")
778
795
:return: string with the file content
779
796
"""
780
797
file_path_parts = (base_file_path + file_path ).split ("/" )
@@ -791,7 +808,7 @@ def convert_file_to_base64(file_path):
791
808
Return the content of a file given its path encoded in Base64. If a base path was previously set by using
792
809
the set_file_path() function, the file path specified must be relative to that path.
793
810
794
- :param file path : file path using slash as separator (e.g. "resources/files/doc.txt")
811
+ :param file_path : file path using slash as separator (e.g. "resources/files/doc.txt")
795
812
:return: string with the file content encoded in Base64
796
813
"""
797
814
file_path_parts = (base_base64_path + file_path ).split ("/" )
0 commit comments