<commit_before># Copyright (c) 2012 <NAME>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#

"""Implements an |Edge| that receives messages with the HTTP protocol. WSGI_ is
a Python specification for defining communication between web servers and the
application.

The resulting edge can be used by any HTTP client, like curl::

    $ curl -v -X POST -H 'Content-Type: message/rfc822' \\
           --data-binary @test.eml \\
           -H 'X-Envelope-Sender: c2VuZGVyQGV4YW1wbGUuY29t' \\
           -H 'X-Envelope-Recipient: cmVjaXBpZW50QGV4YW1wbGUuY29t' \\
           http://localhost:8080/
    * About to connect() to localhost port 8080 (#0)
    *   Trying 127.0.0.1...
    * Connected to localhost (127.0.0.1) port 8080 (#0)
    > POST / HTTP/1.1
    > User-Agent: curl/7.29.0
    > Host: localhost:8080
    > Accept: */*
    > Content-Type: message/rfc822
    > X-Envelope-Sender: c2VuZGVyQGV4YW1wbGUuY29t
    > X-Envelope-Recipient: cmVjaXBpZW50QGV4YW1wbGUuY29t
    > Content-Length: 99
    >
    * upload completely sent off: 99 out of 99 bytes
    < HTTP/1.1 200 OK
    < X-Smtp-Reply: 250; message="2.6.0 Message accepted for delivery"
    < Date: Mon, 29 Jul 2013 20:11:55 GMT
    < Content-Length: 0
    <
    * Connection #0 to host localhost left intact

.. _WSGI: http://wsgi.readthedocs.org/en/latest/
.. _variables: http://www.python.org/dev/peps/pep-0333/#environ-variables

"""

from __future__ import absolute_import, unicode_literals

import sys
import re
from base64 import b64decode
from wsgiref.headers import Headers

import gevent
from gevent.pywsgi import WSGIServer
from dns import reversename
from dns.exception import DNSException
import six

from slimta.logging import log_exception
from slimta.http.wsgi import WsgiServer
from slimta.envelope import Envelope
from slimta.smtp.reply import Reply
from slimta.queue import QueueError
from slimta.relay import RelayError
from slimta.util import dns_resolver
from . import Edge

__all__ = ['WsgiResponse', 'WsgiEdge', 'WsgiValidators']


class WsgiResponse(Exception):
    """This exception can be explicitly raised to end the WSGI request and
    return the given response.

    :param status: The HTTP status string to return, e.g. ``200 OK``.
    :param headers: List of ``(name, value)`` header tuples to return.
    :param data: Optional raw data string to return.

    """

    def __init__(self, status, headers=[], data=[]):
        super(WsgiResponse, self).__init__(status)
        self.status = status
        self.headers = [(_unicode_to_bytes(k), _unicode_to_bytes(v))
                        for k, v in headers]
        self.data = data or []
<commit_msg>Remove default arguments as lists<commit_after># Copyright (c) 2012 <NAME>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#

"""Implements an |Edge| that receives messages with the HTTP protocol. WSGI_ is
a Python specification for defining communication between web servers and the
application.

The resulting edge can be used by any HTTP client, like curl::

    $ curl -v -X POST -H 'Content-Type: message/rfc822' \\
           --data-binary @test.eml \\
           -H 'X-Envelope-Sender: c2VuZGVyQGV4YW1wbGUuY29t' \\
           -H 'X-Envelope-Recipient: cmVjaXBpZW50QGV4YW1wbGUuY29t' \\
           http://localhost:8080/
    * About to connect() to localhost port 8080 (#0)
    *   Trying 127.0.0.1...
    * Connected to localhost (127.0.0.1) port 8080 (#0)
    > POST / HTTP/1.1
    > User-Agent: curl/7.29.0
    > Host: localhost:8080
    > Accept: */*
    > Content-Type: message/rfc822
    > X-Envelope-Sender: c2VuZGVyQGV4YW1wbGUuY29t
    > X-Envelope-Recipient: cmVjaXBpZW50QGV4YW1wbGUuY29t
    > Content-Length: 99
    >
    * upload completely sent off: 99 out of 99 bytes
    < HTTP/1.1 200 OK
    < X-Smtp-Reply: 250; message="2.6.0 Message accepted for delivery"
    < Date: Mon, 29 Jul 2013 20:11:55 GMT
    < Content-Length: 0
    <
    * Connection #0 to host localhost left intact

.. _WSGI: http://wsgi.readthedocs.org/en/latest/
.. _variables: http://www.python.org/dev/peps/pep-0333/#environ-variables

"""

from __future__ import absolute_import, unicode_literals

import sys
import re
from base64 import b64decode
from wsgiref.headers import Headers

import gevent
from gevent.pywsgi import WSGIServer
from dns import reversename
from dns.exception import DNSException
import six

from slimta.logging import log_exception
from slimta.http.wsgi import WsgiServer
from slimta.envelope import Envelope
from slimta.smtp.reply import Reply
from slimta.queue import QueueError
from slimta.relay import RelayError
from slimta.util import dns_resolver
from . import Edge

__all__ = ['WsgiResponse', 'WsgiEdge', 'WsgiValidators']


class WsgiResponse(Exception):
    """This exception can be explicitly raised to end the WSGI request and
    return the given response.

    :param status: The HTTP status string to return, e.g. ``200 OK``.
    :param headers: List of ``(name, value)`` header tuples to return.
    :param data: Optional raw data string to return.

    """

    def __init__(self, status, headers=None, data=None):
        if headers is None:
            headers = []
        if data is None:
            data = []

        super(WsgiResponse, self).__init__(status)
        self.status = status
        self.headers = [(_unicode_to_bytes(k), _unicode_to_bytes(v))
                        for k, v in headers]
        self.data = data or []

{'fraction_non_alphanumeric': 0.08495765559887082, 'fraction_numerical': 0.029573867455303132, 'mean_word_length': 3.4180522565320666, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 4, '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': '309550', 'n_tokens_mistral': 2451, 'n_tokens_neox': 2217, 'n_words': 864}