<commit_before># Module:   wrappers
# Date:     13th September 2007
# Author:   <NAME>, prologic at shortcircuit dot net dot au

"""Request/Response Wrappers

This module implements the Request and Response objects.
"""


from io import BytesIO, IOBase
from time import strftime, time

try:
    from Cookie import SimpleCookie
except ImportError:
    from http.cookies import SimpleCookie  # NOQA

from .utils import url
from .headers import Headers
from ..six import binary_type
from .errors import HTTPError
from circuits.tools import deprecated
from circuits.net.sockets import BUFSIZE
from .constants import HTTP_STATUS_CODES, SERVER_PROTOCOL, SERVER_VERSION

try:
    unicode
except NameError:
    unicode = str


def file_generator(input, chunkSize=BUFSIZE):
    chunk = input.read(chunkSize)
    while chunk:
        yield chunk
        chunk = input.read(chunkSize)
    input.close()


class Host(object):
    """An internet address.

    name should be the client's host name. If not available (because no DNS
    lookup is performed), the IP address should be used instead.
    """

    ip = "0.0.0.0"
    port = 80
    name = "unknown.tld"

    def __init__(self, ip, port, name=None):
        self.ip = ip
        self.port = port
        if name is None:
            name = ip
            self.name = name

    def __repr__(self):
        return "Host(%r, %r, %r)" % (self.ip, self.port, self.name)


class HTTPStatus(object):

    __slots__ = ("_reason", "_status",)

    def __init__(self, status=200, reason=None):
        self._status = status
        self._reason = reason or HTTP_STATUS_CODES[status]

    def __int__(self):
        return self._status

    def __cmp__(self, other):
        if isinstance(other, int):
            return other == self._status
        return super(Status, self).__cmp__(other)

    def __str__(self):
        return "{0:d} {1:s}".format(self._status, self._reason)

    def __repr__(self):
        return "<Status (status={0:d} reason={1:s}>".format(
            self._status, self._reason
        )

    @property
    def status(self):
        return self._status

    @property
    def reason(self):
        return self._reason


class Request(object):
    """Creates a new Request object to hold information about a request.

    :param sock: The socket object of the request.
    :type  sock: socket.socket
<commit_msg>Fixed __cmp__ method on HTTPStatus class<commit_after># Module:   wrappers
# Date:     13th September 2007
# Author:   <NAME>, prologic at shortcircuit dot net dot au

"""Request/Response Wrappers

This module implements the Request and Response objects.
"""


from io import BytesIO, IOBase
from time import strftime, time

try:
    from Cookie import SimpleCookie
except ImportError:
    from http.cookies import SimpleCookie  # NOQA

from .utils import url
from .headers import Headers
from ..six import binary_type
from .errors import HTTPError
from circuits.tools import deprecated
from circuits.net.sockets import BUFSIZE
from .constants import HTTP_STATUS_CODES, SERVER_PROTOCOL, SERVER_VERSION

try:
    unicode
except NameError:
    unicode = str


def file_generator(input, chunkSize=BUFSIZE):
    chunk = input.read(chunkSize)
    while chunk:
        yield chunk
        chunk = input.read(chunkSize)
    input.close()


class Host(object):
    """An internet address.

    name should be the client's host name. If not available (because no DNS
    lookup is performed), the IP address should be used instead.
    """

    ip = "0.0.0.0"
    port = 80
    name = "unknown.tld"

    def __init__(self, ip, port, name=None):
        self.ip = ip
        self.port = port
        if name is None:
            name = ip
            self.name = name

    def __repr__(self):
        return "Host(%r, %r, %r)" % (self.ip, self.port, self.name)


class HTTPStatus(object):

    __slots__ = ("_reason", "_status",)

    def __init__(self, status=200, reason=None):
        self._status = status
        self._reason = reason or HTTP_STATUS_CODES[status]

    def __int__(self):
        return self._status

    def __cmp__(self, other):
        if isinstance(other, int):
            return cmp(other, self._status)
        return super(HTTPStatus, self).__cmp__(other)

    def __str__(self):
        return "{0:d} {1:s}".format(self._status, self._reason)

    def __repr__(self):
        return "<Status (status={0:d} reason={1:s}>".format(
            self._status, self._reason
        )

    @property
    def status(self):
        return self._status

    @property
    def reason(self):
        return self._reason


class Request(object):
    """Creates a new Request object to hold information about a request.

    :param sock: The socket object of the request.
    :type  sock: socket.socket

{'fraction_non_alphanumeric': 0.09510869565217392, 'fraction_numerical': 0.00794314381270903, 'mean_word_length': 2.782608695652174, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '7186517', 'n_tokens_mistral': 1462, 'n_tokens_neox': 1399, 'n_words': 475}