# Path: web/core/util.py
# def safe_name(thing):
# 	"""Attempt to resolve the canonical name for an object, falling back on the `repr()` if unable to do so."""
# 	try:
# 		return name(thing)
# 	except:
# 		return repr(thing)


from inspect import isroutine, ismethod, getcallargs
from webob.exc import HTTPNotFound
from web.core.util import safe_name
	"""
	
	last = True
	
	provides = {'args.validation', 'kwargs.validation'}
	
	def __init__(self, enabled='development', correct=False):
		"""Configure when validation is performed and the action performed.
		
		If `enabled` is `True` validation will always be performed, if `False`, never. If set to `development` the
		callback will not be assigned and no code will be executed during runtime.
		
		When `correct` is falsy (the default), an `HTTPNotFound` will be raised if a conflict occurs. If truthy the
		conflicting arguments are removed, with positional taking precedence to keyword.
		"""
		
		if enabled is True or (enabled == 'development' and __debug__):
			self.mutate = self._mutate
	
	def _mutate(self, context, endpoint, args, kw):
		try:
			if callable(endpoint) and not isroutine(endpoint):
				endpoint = endpoint.__call__  # Handle instances that are callable.
			
			getcallargs(endpoint, *args, **kw)
		
		except TypeError as e:
			# If the argument specification doesn't match, the handler can't process this request.
			# This is one policy. Another possibility is more computationally expensive and would pass only
			# valid arguments, silently dropping invalid ones. This can be implemented as a mutate handler.

# Path: web/core/util.py
# def safe_name(thing):
# 	"""Attempt to resolve the canonical name for an object, falling back on the `repr()` if unable to do so."""
# 	try:
# 		return name(thing)
# 	except:
# 		return repr(thing)


# Path: web/ext/args.py
from inspect import isroutine, ismethod, getcallargs
from webob.exc import HTTPNotFound
from web.core.util import safe_name

	"""
	
	last = True
	
	provides = {'args.validation', 'kwargs.validation'}
	
	def __init__(self, enabled='development', correct=False):
		"""Configure when validation is performed and the action performed.
		
		If `enabled` is `True` validation will always be performed, if `False`, never. If set to `development` the
		callback will not be assigned and no code will be executed during runtime.
		
		When `correct` is falsy (the default), an `HTTPNotFound` will be raised if a conflict occurs. If truthy the
		conflicting arguments are removed, with positional taking precedence to keyword.
		"""
		
		if enabled is True or (enabled == 'development' and __debug__):
			self.mutate = self._mutate
	
	def _mutate(self, context, endpoint, args, kw):
		try:
			if callable(endpoint) and not isroutine(endpoint):
				endpoint = endpoint.__call__  # Handle instances that are callable.
			
			getcallargs(endpoint, *args, **kw)
		
		except TypeError as e:
			# If the argument specification doesn't match, the handler can't process this request.
			# This is one policy. Another possibility is more computationally expensive and would pass only
			# valid arguments, silently dropping invalid ones. This can be implemented as a mutate handler.

			log.error(str(e).replace(endpoint.__name__, safe_name(endpoint)), extra=dict(