#NEWLINE# def __init__( self , origin , name = None , return_type = str , args = None , needs_context = False ) : #NEWLINE# #INDENT# "\n        ``origin`` is a native Python function to be wrapped.\n        ``name`` is the name of the function, if it is not specified,\n        ``origin.__name__`` is used. ``return_type`` and ``needs_context``\n        correspond to ``pyws.functions.Function`` arguments. ``args`` is a\n        tuple, each of its elements may be:\n\n        * a type,\n        * a tuple, first element is a type, second is a value representing an\n          empty one.\n\n        If ``args`` is not specified all arguments will be treated as strings,\n        the same thing with ``return_type``. Argument names are infered from\n        ``origin.func_code.co_varnames``.\n\n        >>> from pyws.functions import NativeFunctionAdapter\n        >>> from pyws.functions.args import String\n        >>> from pyws.functions.args import Dict, Field\n\n        >>> def nothing():\n        ...     pass\n\n        >>> a = NativeFunctionAdapter(nothing)\n        >>> a.origin == nothing\n        True\n        >>> a.name\n        'nothing'\n        >>> a.return_type\n        <class 'pyws.functions.args.types.simple.String'>\n        >>> issubclass(a.args, Dict)\n        True\n        >>> a.args.fields\n        []\n        >>> a(context=None)\n\n        >>> def add(a, b):\n        ...     c = a + b\n        ...     return c\n\n        >>> a = NativeFunctionAdapter(add, name='concat')\n        >>> a.name\n        'concat'\n        >>> len(a.args.fields)\n        2\n        >>> f = a.args.fields[0]\n        >>> type(f)\n        <class 'pyws.functions.args.field.Field'>\n        >>> f.name\n        'a'\n        >>> f.type\n        <class 'pyws.functions.args.types.simple.String'>\n        >>> a.return_type\n        <class 'pyws.functions.args.types.simple.String'>\n\n        >>> a = NativeFunctionAdapter(\n        ...     add,\n        ...     name='sum',\n        ...     return_type=int,\n        ...     args=(int,),\n        ... )\n        >>> a.name\n        'sum'\n        >>> f = a.args.fields[0]\n        >>> f.type\n        <class 'pyws.functions.args.types.simple.Integer'>\n        >>> a.return_type\n        <class 'pyws.functions.args.types.simple.Integer'>\n\n        >>> def empty_value(a):\n        ...     return 'hello ' + a\n\n        >>> a = NativeFunctionAdapter(empty_value, args=((str, 'world'), ))\n        >>> a(context=None, a=None) # note that 'world' is used instead of None\n        'hello world'\n        " #NEWLINE# self . origin = origin #NEWLINE# self . name = ( name or origin . __name__ ) #NEWLINE# self . documentation = origin . __doc__ #NEWLINE# self . return_type = TypeFactory ( ( return_type or str ) ) #NEWLINE# self . needs_context = needs_context #NEWLINE# arg_names = [ ( x , ) for x in getargspec ( origin ) [ 0 ] if ( ( not needs_context ) or ( x != CONTEXT_ARG_NAME ) ) ] #NEWLINE# if ( not args ) : #NEWLINE# #INDENT# args = ( ( str , ) * len ( arg_names ) ) #NEWLINE# #UNINDENT# args_ = map ( ( lambda x : ( x [ 0 ] + x [ 1 ] ) ) , zip ( arg_names , map ( ( lambda arg : ( ( isinstance ( arg , tuple ) and arg ) or ( arg , ) ) ) , args ) ) ) #NEWLINE# self . args = DictOf ( self . type_name , * args_ )