<commit_before>from lxml import etree

from banzai.settings import (BANZAI_API_DOMAIN, BANZAI_API_VERSION,
                             BANZAI_API_KEY)


class MailPackage(object):

    def __init__(self, email_from, name_from, subject, message, send_at=None,
                 headers=[], attach_images='0', description=''):
        self.email_from = email_from
        self.name_from = name_from
        self.subject = subject
        self.message = message
        self.send_at = send_at
        self.headers = headers
        self.attach_images = attach_images
        self.description = description

        self._users_data = []
        self._xml = etree.Element('list')
        self._generation_complete = False

    def add_user(self, email_to, name_to='', header={}, fields={}):
        if self._generation_complete:
            raise RuntimeError('Impossibly add user, because '
                               'generation already complete!')
        self._users_data.append({
            'email_to': email_to,
            'name_to': name_to,
            'header': header,
            'fields': fields
        })

    def save(self):
        pass

    def xml_tostring(self):
        self._generate()
        return etree.tostring(self._xml, encoding='UTF-8',
                              xml_declaration=True)

    def _generate(self):
        body_tag = etree.Element('body')
<commit_msg>improve mail package generation: not generate package, if is already generated<commit_after>from lxml import etree

from banzai.settings import (BANZAI_API_DOMAIN, BANZAI_API_VERSION,
                             BANZAI_API_KEY)


class MailPackage(object):

    def __init__(self, email_from, name_from, subject, message, send_at=None,
                 headers=[], attach_images='0', description=''):
        self.email_from = email_from
        self.name_from = name_from
        self.subject = subject
        self.message = message
        self.send_at = send_at
        self.headers = headers
        self.attach_images = attach_images
        self.description = description

        self._users_data = []
        self._xml = etree.Element('list')
        self._generation_complete = False

    def add_user(self, email_to, name_to='', header={}, fields={}):
        if self._generation_complete:
            raise RuntimeError('Impossibly add user, because '
                               'generation already complete!')
        self._users_data.append({
            'email_to': email_to,
            'name_to': name_to,
            'header': header,
            'fields': fields
        })

    def save(self):
        pass

    def xml_tostring(self):
        self._generate()
        return etree.tostring(self._xml, encoding='UTF-8',
                              xml_declaration=True)

    def _generate(self):
        if self._generation_complete:
            return
        body_tag = etree.Element('body')

{'fraction_non_alphanumeric': 0.09520547945205479, 'fraction_numerical': 0.0013698630136986301, 'mean_word_length': 2.071503680336488, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, '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': '2170191', 'n_tokens_mistral': 828, 'n_tokens_neox': 802, 'n_words': 177}