<s> from robot . errors import DataError <EOL> from robot . utils import ( get_error_message , is_java_method , is_bytes , <EOL> is_unicode , py2to3 ) <EOL> from . arguments import JavaArgumentParser , PythonArgumentParser <EOL> def no_dynamic_method ( * args ) : <EOL> pass <EOL> @ py2to3 <EOL> class _DynamicMethod ( object ) : <EOL> _underscore_name = NotImplemented <EOL> def __init__ ( self , lib ) : <EOL> self . method = self . _get_method ( lib ) <EOL> def _get_method ( self , lib ) : <EOL> for name in self . _underscore_name , self . _camelCaseName : <EOL> method = getattr ( lib , name , None ) <EOL> if callable ( method ) : <EOL> return method <EOL> return no_dynamic_method <EOL> @ property <EOL> def _camelCaseName ( self ) : <EOL> tokens = self . _underscore_name . split ( '<STR_LIT:_>' ) <EOL> return '<STR_LIT>' . join ( [ tokens [ <NUM_LIT:0> ] ] + [ t . capitalize ( ) for t in tokens [ <NUM_LIT:1> : ] ] ) <EOL> @ property <EOL> def name ( self ) : <EOL> return self . method . __name__ <EOL> def __call__ ( self , * args ) : <EOL> try : <EOL> return self . _handle_return_value ( self . method ( * args ) ) <EOL> except : <EOL> raise DataError ( "<STR_LIT>" <EOL> % ( self . method . __name__ , get_error_message ( ) ) ) <EOL> def _handle_return_value ( self , value ) : <EOL> raise NotImplementedError <EOL> def _to_string ( self , value ) : <EOL> if is_unicode ( value ) : <EOL> return value <EOL> if is_bytes ( value ) : <EOL> return value . decode ( '<STR_LIT>' ) <EOL> raise DataError ( '<STR_LIT>' ) <EOL> def _to_list_of_strings ( self , value ) : <EOL> try : <EOL> return [ self . _to_string ( v ) for v in value ] <EOL> except ( TypeError , DataError ) : <EOL> raise DataError ( '<STR_LIT>' ) <EOL> def __nonzero__ ( self ) : <EOL> return self . method is not no_dynamic_method <EOL> class GetKeywordNames ( _DynamicMethod ) : <EOL> _underscore_name = '<STR_LIT>' <EOL> def _handle_return_value ( self , value ) : <EOL> names = self . _to_list_of_strings ( value or [ ] ) <EOL> return list ( self . _remove_duplicates ( names ) ) <EOL> def _remove_duplicates ( self , names ) : <EOL> seen = set ( ) <EOL> for name in names : <EOL> if name not in seen : <EOL> seen . add ( name ) <EOL> yield name <EOL> class RunKeyword ( _DynamicMethod ) : <EOL> _underscore_name = '<STR_LIT>' <EOL> @ property <EOL> def supports_kwargs ( self ) : <EOL> if is_java_method ( self . method ) : <EOL> return self . _supports_java_kwargs ( self . method ) <EOL> return self . _supports_python_kwargs ( self . method ) <EOL> def _supports_python_kwargs ( self , method ) : <EOL> spec = PythonArgumentParser ( ) . parse ( method ) <EOL> return len ( spec . positional ) == <NUM_LIT:3> <EOL> def _supports_java_kwargs ( self , method ) : <EOL> func = self . method . im_func if hasattr ( method , '<STR_LIT>' ) else method <EOL> signatures = func . argslist [ : func . nargs ] <EOL> spec = JavaArgumentParser ( ) . parse ( signatures ) <EOL> return ( self . _java_single_signature_kwargs ( spec ) or <EOL> self . _java_multi_signature_kwargs ( spec ) ) <EOL> def _java_single_signature_kwargs ( self , spec ) : <EOL> return len ( spec . positional ) == <NUM_LIT:1> and spec . varargs and spec . kwargs <EOL> def _java_multi_signature_kwargs ( self , spec ) : <EOL> return len ( spec . positional ) == <NUM_LIT:3> and not ( spec . varargs or spec . kwargs ) <EOL> class GetKeywordDocumentation ( _DynamicMethod ) : <EOL> _underscore_name = '<STR_LIT>' <EOL> def _handle_return_value ( self , value ) : <EOL> return self . _to_string ( value or '<STR_LIT>' ) <EOL> class GetKeywordArguments ( _DynamicMethod ) : <EOL> _underscore_name = '<STR_LIT>' <EOL> def __init__ ( self , lib ) : <EOL> _DynamicMethod . __init__ ( self , lib ) <EOL> self . _supports_kwargs = RunKeyword ( lib ) . supports_kwargs <EOL> def _handle_return_value ( self , value ) : <EOL> if value is None : <EOL> if self . _supports_kwargs : <EOL> return [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> return [ '<STR_LIT>' ] <EOL> return self . _to_list_of_strings ( value ) </s>
