# Path: weechat/common/decorators.py
# def disable_for_loaddata(signal_handler):
#     """
#     Decorator that turns off signal handlers when loading fixture data.
#     """
#     @wraps(signal_handler)
#     def wrapper(*args, **kwargs):
#         if kwargs.get('raw'):
#             return
#         signal_handler(*args, **kwargs)
#     return wrapper
# 
# Path: weechat/common/i18n.py
# def i18n_autogen(app, name, strings):
#     """Create a file '_i18n_xxx.py' with strings to translate."""
#     # build content of file
#     content = [
#         '# This file is auto-generated after changes in database, '
#         'DO NOT EDIT!',
#         '',
#         f'"""Translations for {app}/{name}."""',
#         '',
#         '# flake8: noqa',
#         '# pylint: disable=line-too-long,too-many-statements',
#     ]
#     if strings:
#         content += [
#             '',
#             'from django.utils.translation import gettext_noop',
#             '',
#             '',
#             f'def __i18n_{app}_{name}():',
#             f'    """Translations for {app}/{name}."""',
#         ]
#         done = set()
#         for string in sorted(strings):
#             if isinstance(string, tuple):
#                 # if type is tuple of 2 strings: use the second as note for
#                 # translators
#                 (message, translators) = (string[0], string[1])
#             else:
#                 # single string (no note for translators)
#                 (message, translators) = (string, None)
#             # add string if not already done
#             if message not in done:
#                 if translators:
#                     content.append(f'    # Translators: {translators}')
#                 message = (message
#                            .replace('\\', '\\\\')
#                            .replace('"', '\\"')
#                            .replace('\r\n', '\\n'))
#                 content.append(f'    gettext_noop("{message}")')
#                 done.add(message)
#     content.append('')
#     # write file
#     filename = project_path_join(app, f'_i18n_{name}.py')
#     with open(filename, 'w', encoding='utf-8') as _file:
#         data = '\n'.join(content)
#         if hasattr(data, 'decode') and isinstance(data, str):
#             data = data.decode('utf-8')
#         _file.write(data)
# 
# Path: weechat/common/path.py
# def files_path_join(*args):
#     """Join multiple paths after settings.FILES_ROOT."""
#     return __path_join(settings.FILES_ROOT, *args)


import gzip
import hashlib
import json
import os
from collections import OrderedDict
from io import open
from xml.sax.saxutils import escape
from django.conf import settings
from django.db import models
from django.db.models.signals import pre_save, post_save, post_delete
from django.utils import translation
from django.utils.safestring import mark_safe
from django.utils.translation import gettext
from weechat.common.decorators import disable_for_loaddata
from weechat.common.i18n import i18n_autogen
from weechat.common.path import files_path_join
                value = ''
            else:
                if key == 'url':
                    # FIXME: use the "Host" from request, but…
                    # request is not available in this handler!
                    value = f'https://weechat.org/{script.build_url()[1:]}'
                elif key == 'mail':
                    value = value.replace('@', ' [at] ')
                    value = value.replace('.', ' [dot] ')
                elif key == 'md5sum':
                    value = script.get_md5sum()
                elif key == 'sha512sum':
                    value = script.get_sha512sum()
                elif key == 'desc_en':
                    for lang, locale in settings.LANGUAGES_LOCALES.items():
                        if lang[0:2] != 'en':
                            translation.activate(lang)
                            value_i18n[f'desc_{locale}'] = gettext(value)
                            translation.deactivate()
            value = f'{value}'
            xml += f'    <{key}>{escape(value)}</{key}>\n'
            json_script[key] = value
            for field, field_value in value_i18n.items():
                xml += f'    <{field}>{escape(field_value)}</{field}>\n'
                json_script[field] = value_i18n[field]
        xml += '  </plugin>\n'
        json_data.append(json_script)
    xml += '</plugins>\n'

    # create scripts.xml

# Path: weechat/common/decorators.py
# def disable_for_loaddata(signal_handler):
#     """
#     Decorator that turns off signal handlers when loading fixture data.
#     """
#     @wraps(signal_handler)
#     def wrapper(*args, **kwargs):
#         if kwargs.get('raw'):
#             return
#         signal_handler(*args, **kwargs)
#     return wrapper
# 
# Path: weechat/common/i18n.py
# def i18n_autogen(app, name, strings):
#     """Create a file '_i18n_xxx.py' with strings to translate."""
#     # build content of file
#     content = [
#         '# This file is auto-generated after changes in database, '
#         'DO NOT EDIT!',
#         '',
#         f'"""Translations for {app}/{name}."""',
#         '',
#         '# flake8: noqa',
#         '# pylint: disable=line-too-long,too-many-statements',
#     ]
#     if strings:
#         content += [
#             '',
#             'from django.utils.translation import gettext_noop',
#             '',
#             '',
#             f'def __i18n_{app}_{name}():',
#             f'    """Translations for {app}/{name}."""',
#         ]
#         done = set()
#         for string in sorted(strings):
#             if isinstance(string, tuple):
#                 # if type is tuple of 2 strings: use the second as note for
#                 # translators
#                 (message, translators) = (string[0], string[1])
#             else:
#                 # single string (no note for translators)
#                 (message, translators) = (string, None)
#             # add string if not already done
#             if message not in done:
#                 if translators:
#                     content.append(f'    # Translators: {translators}')
#                 message = (message
#                            .replace('\\', '\\\\')
#                            .replace('"', '\\"')
#                            .replace('\r\n', '\\n'))
#                 content.append(f'    gettext_noop("{message}")')
#                 done.add(message)
#     content.append('')
#     # write file
#     filename = project_path_join(app, f'_i18n_{name}.py')
#     with open(filename, 'w', encoding='utf-8') as _file:
#         data = '\n'.join(content)
#         if hasattr(data, 'decode') and isinstance(data, str):
#             data = data.decode('utf-8')
#         _file.write(data)
# 
# Path: weechat/common/path.py
# def files_path_join(*args):
#     """Join multiple paths after settings.FILES_ROOT."""
#     return __path_join(settings.FILES_ROOT, *args)


# Path: weechat/scripts/models.py
import gzip
import hashlib
import json
import os
from collections import OrderedDict
from io import open
from xml.sax.saxutils import escape
from django.conf import settings
from django.db import models
from django.db.models.signals import pre_save, post_save, post_delete
from django.utils import translation
from django.utils.safestring import mark_safe
from django.utils.translation import gettext
from weechat.common.decorators import disable_for_loaddata
from weechat.common.i18n import i18n_autogen
from weechat.common.path import files_path_join

                value = ''
            else:
                if key == 'url':
                    # FIXME: use the "Host" from request, but…
                    # request is not available in this handler!
                    value = f'https://weechat.org/{script.build_url()[1:]}'
                elif key == 'mail':
                    value = value.replace('@', ' [at] ')
                    value = value.replace('.', ' [dot] ')
                elif key == 'md5sum':
                    value = script.get_md5sum()
                elif key == 'sha512sum':
                    value = script.get_sha512sum()
                elif key == 'desc_en':
                    for lang, locale in settings.LANGUAGES_LOCALES.items():
                        if lang[0:2] != 'en':
                            translation.activate(lang)
                            value_i18n[f'desc_{locale}'] = gettext(value)
                            translation.deactivate()
            value = f'{value}'
            xml += f'    <{key}>{escape(value)}</{key}>\n'
            json_script[key] = value
            for field, field_value in value_i18n.items():
                xml += f'    <{field}>{escape(field_value)}</{field}>\n'
                json_script[field] = value_i18n[field]
        xml += '  </plugin>\n'
        json_data.append(json_script)
    xml += '</plugins>\n'

    # create scripts.xml

    filename = files_path_join('scripts.xml')