<commit_before>"""The core WSGIController"""
import inspect
import logging
import types
import warnings

from paste.httpexceptions import HTTPException
from paste.response import HeaderDict
from paste.wsgiwrappers import WSGIResponse

import pylons

__all__ = ['Controller', 'WSGIController']

log = logging.getLogger(__name__)

class WSGIController(object):
    """WSGI Controller that follows WSGI spec for calling and return values
    
    The Pylons WSGI Controller handles incoming web requests that are 
    dispatched from the PylonsBaseWSGIApp. These requests result in a new 
    instance of the WSGIController being created, which is then called with the
    dict options from the Routes match. The standard WSGI response is then
    returned with start_response called as per the WSGI spec.
    
    By default, the WSGIController will search and attempt to call a 
    ``__before__`` method before calling the action, and will try to call a
    ``__after__`` method after the action was called. These two methods can act
    as filters controlling access to the action, setup variables/objects for 
    use with a set of actions, etc.
    
    Each action to be called is inspected with ``_inspect_call`` so that it is
    only passed the arguments in the Routes match dict that it asks for. The
    arguments passed into the action can be customized by overriding the 
    ``_get_method_args`` function which is expected to return a dict.
    
    In the event that an action is not found to handle the request, the
    Controller will raise an "Action Not Found" error if in debug mode,
    otherwise a ``404 Not Found`` error will be returned.
    """
    
    __pudge_all__ = ['_inspect_call', '__call__', '_get_method_args', 
                     '_dispatch_call']
    
    def _inspect_call(self, func, **kargs):
        """Calls a function with as many arguments from args and kargs as
        possible
        
        Given a function, inspect_call will inspect the function args and call
        it with no further keyword args than it asked for.
        
        If the function has been decorated, it is assumed that the decorator
        preserved the function signature.
        """
        argspec = inspect.getargspec(func)
        kargs = self._get_method_args()
        
        # Hide the traceback for everything above this controller
        __traceback_hide__ = 'before_and_this'
        
        c = pylons.c._current_obj()
        args = None
        if argspec[2]:
            for k, val in kargs.iteritems():
                setattr(c, k, val)
            args = kargs
        else:<commit_msg>[svn] kargs are no longer passed to _inspect_call<commit_after>"""The core WSGIController"""
import inspect
import logging
import types
import warnings

from paste.httpexceptions import HTTPException
from paste.response import HeaderDict
from paste.wsgiwrappers import WSGIResponse

import pylons

__all__ = ['Controller', 'WSGIController']

log = logging.getLogger(__name__)

class WSGIController(object):
    """WSGI Controller that follows WSGI spec for calling and return values
    
    The Pylons WSGI Controller handles incoming web requests that are 
    dispatched from the PylonsBaseWSGIApp. These requests result in a new 
    instance of the WSGIController being created, which is then called with the
    dict options from the Routes match. The standard WSGI response is then
    returned with start_response called as per the WSGI spec.
    
    By default, the WSGIController will search and attempt to call a 
    ``__before__`` method before calling the action, and will try to call a
    ``__after__`` method after the action was called. These two methods can act
    as filters controlling access to the action, setup variables/objects for 
    use with a set of actions, etc.
    
    Each action to be called is inspected with ``_inspect_call`` so that it is
    only passed the arguments in the Routes match dict that it asks for. The
    arguments passed into the action can be customized by overriding the 
    ``_get_method_args`` function which is expected to return a dict.
    
    In the event that an action is not found to handle the request, the
    Controller will raise an "Action Not Found" error if in debug mode,
    otherwise a ``404 Not Found`` error will be returned.
    """
    
    __pudge_all__ = ['_inspect_call', '__call__', '_get_method_args', 
                     '_dispatch_call']
    
    def _inspect_call(self, func):
        """Calls a function with arguments from ``_get_method_args``
        
        Given a function, inspect_call will inspect the function args and call
        it with no further keyword args than it asked for.
        
        If the function has been decorated, it is assumed that the decorator
        preserved the function signature.
        """
        argspec = inspect.getargspec(func)
        kargs = self._get_method_args()
        
        # Hide the traceback for everything above this controller
        __traceback_hide__ = 'before_and_this'
        
        c = pylons.c._current_obj()
        args = None
        if argspec[2]:
            for k, val in kargs.iteritems():
                setattr(c, k, val)
            args = kargs
        else:
{'fraction_non_alphanumeric': 0.051413394042876114, 'fraction_numerical': 0.0015177385695313982, 'mean_word_length': 2.823060188542422, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6244044', 'n_tokens_mistral': 1388, 'n_tokens_neox': 1356, 'n_words': 639}