<commit_before># Copyright (c) 2007-2008 The PyAMF Project.
# See LICENSE for details.

"""
WSGI server implementation.

@see: U{WSGI homepage (external)<http://wsgi.org>}

@author: U{<NAME><mailto:<EMAIL>>}
@since: 0.1.0
"""

import pyamf
from pyamf import remoting
from pyamf.remoting import gateway

__all__ = ['WSGIGateway']

class WSGIGateway(gateway.BaseGateway):
    """
    WSGI Remoting Gateway.
    """

    def __init__(self, services={}, expose_environ=False):
        gateway.BaseGateway.__init__(self, services)

        self.expose_environ = expose_environ

    def getResponse(self, request, environ):
        """
        Processes the AMF request, returning an AMF response.

        @param request: The AMF Request.
        @type request: L{Envelope<pyamf.remoting.Envelope>}
        @rtype: L{Envelope<pyamf.remoting.Envelope>}
        @return: The AMF Response.
        """
        response = remoting.Envelope(request.amfVersion, request.clientType)
        
        kwargs = {}

        if self.expose_environ:
            def wrapper(service_request, *body):
                return service_request(environ, *body)

            kwargs.update({'service_wrapper': wrapper})

        for name, message in request:
            processor = self.getProcessor(message)
            response[name] = processor(message, **kwargs)

        return response

    def badRequestMethod(self, environ, start_response):
        """
        Return HTTP 400 Bad Request
        """
        response = "400 Bad Request\n\nTo access this PyAMF gateway you " \
            "must use POST requests (%s received)" % environ['REQUEST_METHOD']

        start_response('400 Bad Request', [
            ('Content-Type', 'text/plain'),
            ('Content-Length', str(len(response))),
        ])

        return [response]

    def __call__(self, environ, start_response):
        """<commit_msg>Whitespace removal<commit_after># Copyright (c) 2007-2008 The PyAMF Project.
# See LICENSE for details.

"""
WSGI server implementation.

@see: U{WSGI homepage (external)<http://wsgi.org>}

@author: U{<NAME><mailto:<EMAIL>>}
@since: 0.1.0
"""

import pyamf
from pyamf import remoting
from pyamf.remoting import gateway

__all__ = ['WSGIGateway']

class WSGIGateway(gateway.BaseGateway):
    """
    WSGI Remoting Gateway.
    """

    def __init__(self, services={}, expose_environ=False):
        gateway.BaseGateway.__init__(self, services)

        self.expose_environ = expose_environ

    def getResponse(self, request, environ):
        """
        Processes the AMF request, returning an AMF response.

        @param request: The AMF Request.
        @type request: L{Envelope<pyamf.remoting.Envelope>}
        @rtype: L{Envelope<pyamf.remoting.Envelope>}
        @return: The AMF Response.
        """
        response = remoting.Envelope(request.amfVersion, request.clientType)

        kwargs = {}

        if self.expose_environ:
            def wrapper(service_request, *body):
                return service_request(environ, *body)

            kwargs.update({'service_wrapper': wrapper})

        for name, message in request:
            processor = self.getProcessor(message)
            response[name] = processor(message, **kwargs)

        return response

    def badRequestMethod(self, environ, start_response):
        """
        Return HTTP 400 Bad Request
        """
        response = "400 Bad Request\n\nTo access this PyAMF gateway you " \
            "must use POST requests (%s received)" % environ['REQUEST_METHOD']

        start_response('400 Bad Request', [
            ('Content-Type', 'text/plain'),
            ('Content-Length', str(len(response))),
        ])

        return [response]

    def __call__(self, environ, start_response):
        """
{'fraction_non_alphanumeric': 0.11637133033588998, 'fraction_numerical': 0.01057921184871727, 'mean_word_length': 2.629558541266795, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '4600076', 'n_tokens_mistral': 1153, 'n_tokens_neox': 1101, 'n_words': 275}