def __getargs__(func_name, signature, args, kwargs):
	"""Based on ``signature`` and ``args``, ``kwargs`` parameters retrieve
	the actual parameters.

	This will set default keyword arguments and retrieve positional arguments
	in kwargs if their called as such"""

	if args is None: args = []
	if kwargs is None: kwargs = {}
	out = {}

	# if the caller did not specify supplemental positional arguments e.g. *args in the signature
	# raise an error
	if args.length > signature.args.length:
		if signature.vararg:
			pass
		else:
			print 'Error in function->' + func_name
			print 'args:', args, 'kwargs:', kwargs, 'sig:', signature
			raise TypeError("Supplemental positional arguments provided but signature doesn't accept them")

	j = 0
	while j < signature.args.length:
		name = signature.args[j]
		if name in kwargs:
			# value is provided as a keyword argument
			out[name] = kwargs[name]
		elif j < args.length:
			# value is positional and within the signature length
			out[name] = args[j]
		elif name in signature.kwargs:
			# value is not found before and is in signature.length
			out[name] = signature.kwargs[name]
		j += 1

	args = args.slice(j)  ## note that if this fails because args is not an array, then a pythonjs function was called from javascript in a bad way.
	#args = Array.prototype.slice.call(args, j)  ## this fix should not be required

	if signature.vararg:
		out[signature.vararg] = args
	if signature.varkwarg:
		out[signature.varkwarg] = kwargs
	return out
dataset/ETHPy150Open PythonJS/PythonJS/pythonjs/runtime/pythonpythonjs.py/__getargs__/original