On the way to alternative inputs. Still needs unit and integration testing

This commit is contained in:
Vincent Jacques
2012-03-16 08:11:07 +01:00
parent a85de99ea5
commit a475d685d8
5 changed files with 24 additions and 6 deletions
@@ -37,3 +37,21 @@ class Parameters:
def NoParameters():
return Parameters( [], [] )
class Alternative:
def __init__( self, *checkers ):
self.__checkers = checkers
def check( self, args, kwds ):
# Try the n - 1 first checkers
for checker in self.__checkers[ : -1 ]:
try:
return checker.check( args, kwds )
except TypeError:
pass
# Use the last checker
# This way, the call stack will point to an actual validation failure
return self.__checkers[ -1 ].check( args, kwds )
def documentParameters( self ):
return " <" + "> or <".join( checker.documentParameters() for checker in self.__checkers ) + "> "