<s> from robot . errors import DataError <EOL> from robot . utils import plural_or_not <EOL> from robot . variables import is_list_var <EOL> class ArgumentValidator ( object ) : <EOL> def __init__ ( self , argspec ) : <EOL> self . _argspec = argspec <EOL> def validate ( self , positional , named , dryrun = False ) : <EOL> if dryrun and any ( is_list_var ( arg ) for arg in positional ) : <EOL> return <EOL> named = set ( name for name , value in named ) <EOL> self . _validate_no_multiple_values ( positional , named , self . _argspec ) <EOL> self . _validate_limits ( positional , named , self . _argspec ) <EOL> self . _validate_no_mandatory_missing ( positional , named , self . _argspec ) <EOL> def _validate_limits ( self , positional , named , spec ) : <EOL> count = len ( positional ) + self . _named_positionals ( named , spec ) <EOL> if not spec . minargs <= count <= spec . maxargs : <EOL> self . _raise_wrong_count ( count , spec ) <EOL> def _named_positionals ( self , named , spec ) : <EOL> if not spec . supports_named : <EOL> return <NUM_LIT:0> <EOL> return sum ( <NUM_LIT:1> for n in named if n in spec . positional ) <EOL> def _raise_wrong_count ( self , count , spec ) : <EOL> minend = plural_or_not ( spec . minargs ) <EOL> if spec . minargs == spec . maxargs : <EOL> expected = '<STR_LIT>' % ( spec . minargs , minend ) <EOL> elif not spec . varargs : <EOL> expected = '<STR_LIT>' % ( spec . minargs , spec . maxargs ) <EOL> else : <EOL> expected = '<STR_LIT>' % ( spec . minargs , minend ) <EOL> if spec . kwargs : <EOL> expected = expected . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> raise DataError ( "<STR_LIT>" <EOL> % ( spec . type , spec . name , expected , count ) ) <EOL> def _validate_no_multiple_values ( self , positional , named , spec ) : <EOL> if named and spec . supports_named : <EOL> for name in spec . positional [ : len ( positional ) ] : <EOL> if name in named : <EOL> raise DataError ( "<STR_LIT>" <EOL> "<STR_LIT>" % ( spec . type , spec . name , name ) ) <EOL> def _validate_no_mandatory_missing ( self , positional , named , spec ) : <EOL> for name in spec . positional [ len ( positional ) : spec . minargs ] : <EOL> if name not in named : <EOL> raise DataError ( "<STR_LIT>" <EOL> % ( spec . type , spec . name , name ) ) </s>
