<commit_before>#!/usr/bin/env python3

'''Contains classes that maniuplate and manage the contents of responses
and requests.
'''

import zlib

from aiospamc.headers import ContentLength


class BodyHeaderManager:
    '''Class that implements header and body management for requests and
    responses.'''

    def __init__(self, body=None, *headers):
        '''
        Parameters
        ----------
        body : str
            String representation of the body.  An instance of the
            aiospamc.headers.ContentLength will be automatically added.
        *headers : tuple of aiospamc.headers.Header
            Collection of headers to be added.  If it contains an instance of
            aiospamc.headers.Compress then the body is automatically
            compressed.
        '''

        self._headers = {item.header_field_name() : item for item in headers}
        self._body = None
        if body:
            self.body = body

    @property
    def body(self):
        '''Contains the contents of the body.

        Returns
        -------
        bytes
            Contents of the body.  If the aiospamc.headers.Compress header is
            present then the value of body will be compressed.'''

        return self._body

    @body.setter
    def body(self, value):
        '''Sets the contents of the body.

        Parameters
        ----------
        value : str
            The contents to be added.  If the aiospamc.headers.Compress header is
            present then the value of body will be compressed.
        '''

        self._body = value.encode()<commit_msg>When viewing the 'body' attribute of BodyHeaderManager classes the body will automatically decompress. Will fix issues with repr and str functions when encountering bytes it can't convert to unicode<commit_after>#!/usr/bin/env python3

'''Contains classes that maniuplate and manage the contents of responses
and requests.
'''

import zlib

from aiospamc.headers import ContentLength


class BodyHeaderManager:
    '''Class that implements header and body management for requests and
    responses.'''

    def __init__(self, body=None, *headers):
        '''
        Parameters
        ----------
        body : str
            String representation of the body.  An instance of the
            aiospamc.headers.ContentLength will be automatically added.
        *headers : tuple of aiospamc.headers.Header
            Collection of headers to be added.  If it contains an instance of
            aiospamc.headers.Compress then the body is automatically
            compressed.
        '''

        self._headers = {item.header_field_name() : item for item in headers}
        self._body = None
        if body:
            self.body = body

    @property
    def body(self):
        '''Contains the contents of the body.

        Returns
        -------
        bytes
            Contents of the body.  If the aiospamc.headers.Compress header is
            present then the value of body will be compressed.'''

        if 'Compress' in self._headers:
            return zlib.decompress(self._body)
        else:
            return self._body

    @body.setter
    def body(self, value):
        '''Sets the contents of the body.

        Parameters
        ----------
        value : str
            The contents to be added.  If the aiospamc.headers.Compress header is
            present then the value of body will be compressed.
        '''

        self._body = value.encode()
{'fraction_non_alphanumeric': 0.0778735632183908, 'fraction_numerical': 0.0005747126436781609, 'mean_word_length': 1.9450084602368867, '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': '2322956', 'n_tokens_mistral': 885, 'n_tokens_neox': 843, 'n_words': 344}