@ -171,7 +171,7 @@ class CommandRunner(object):
self . retries - = 1
self . retries - = 1
else :
else :
failed_conditions = [ item . raw for item in self . conditionals ]
failed_conditions = [ item . raw for item in self . conditionals ]
errmsg = ' One or more conditional statements have not be satisfied'
errmsg = ' One or more conditional statements have not be en satisfied'
raise FailedConditionsError ( errmsg , failed_conditions )
raise FailedConditionsError ( errmsg , failed_conditions )
class Conditional ( object ) :
class Conditional ( object ) :
@ -189,9 +189,9 @@ class Conditional(object):
' matches ' : [ ' matches ' ]
' matches ' : [ ' matches ' ]
}
}
def __init__ ( self , conditional , encoding = ' json ' ) :
def __init__ ( self , conditional , encoding = None ) :
self . raw = conditional
self . raw = conditional
self . encoding = encoding
self . encoding = encoding or ' json '
try :
try :
key , op , val = shlex . split ( conditional )
key , op , val = shlex . split ( conditional )
@ -230,7 +230,7 @@ class Conditional(object):
return self . get_json ( result )
return self . get_json ( result )
except ( IndexError , TypeError ) :
except ( IndexError , TypeError ) :
msg = ' unable to apply conditional to result '
msg = ' unable to apply conditional to result '
raise FailedConditionalError ( msg , self . key )
raise FailedConditionalError ( msg , self . raw )
elif self . encoding == ' xml ' :
elif self . encoding == ' xml ' :
return self . get_xml ( result . get ( ' result ' ) )
return self . get_xml ( result . get ( ' result ' ) )
@ -250,14 +250,16 @@ class Conditional(object):
path + = ' /text() '
path + = ' /text() '
index = int ( re . match ( r ' result \ [( \ d+) \ ] ' , parts [ 0 ] ) . group ( 1 ) )
index = int ( re . match ( r ' result \ [( \ d+) \ ] ' , parts [ 0 ] ) . group ( 1 ) )
values = result [ index ] . xpath ( path )
values = result [ index ] . findall ( path )
if value_index is not None :
if value_index is not None :
return values [ value_index ] . strip ( )
return values [ value_index ] . strip ( )
return [ v . strip ( ) for v in values ]
return [ v . strip ( ) for v in values ]
def get_json ( self , result ) :
def get_json ( self , result ) :
parts = re . split ( r ' \ .(?=[^ \ ]]*(?: \ [|$)) ' , self . key )
string = re . sub ( r " \ [[ \ ' | \" ] " , " . " , self . key )
string = re . sub ( r " [ \ ' | \" ] \ ] " , " . " , string )
parts = re . split ( r ' \ .(?=[^ \ ]]*(?: \ [|$)) ' , string )
for part in parts :
for part in parts :
match = re . findall ( r ' \ [( \ S+?) \ ] ' , part )
match = re . findall ( r ' \ [( \ S+?) \ ] ' , part )
if match :
if match :