<commit_before># Copyright 2013 Hewlett-Packard Development Company, L.P.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import functools
import logging
import re

from designateclient import exceptions as designate_exceptions
from django.core.exceptions import ValidationError  # noqa
from django.core import validators
from django.template.loader import render_to_string
from django.utils.translation import ugettext_lazy as _  # noqa

from horizon import forms
from horizon import messages

from designatedashboard import api
from designatedashboard.dashboards.project.dns_domains.utils\
    import limit_records_to_fips


LOG = logging.getLogger(__name__)

MAX_TTL = 2147483647
# These regexes were given to me by <NAME> here:
# https://gerrit.hpcloud.net/#/c/25300/2/
DOMAIN_NAME_REGEX = r'^(?!.{255,})(?:(?!\-)[A-Za-z0-9_\-]{1,63}(?<!\-)\.)+$'
WILDCARD_DOMAIN_NAME_REGEX = r'^(?!.{255,})(?:(^\*|(?!\-)[A-Za-z0-9_\-]{1,63})(?<!\-)\.)+$'  # noqa
SRV_NAME_REGEX = r'^(?:_[A-Za-z0-9_\-]{1,62}\.){2}'
SRV_DATA_REGEX = r'^(?:(?:6553[0-5]|655[0-2][0-9]|65[0-4][0-9]{2}|6[0-4][0-9]{3}|[1-5][0-9]{4}|[1-9][0-9]{1,3}|[0-9])\s){2}(?!.{255,})((?!\-)[A-Za-z0-9_\-]{1,63}(?<!\-)\.)+$'  # noqa
SSHFP_DATA_REGEX = r'^[1-3]\s[1-2]\s\b([0-9a-fA-F]{5,40}|[0-9a-fA-F]{64})\b$'
# The max length for a dns label
NAME_MAX_LENGTH = 63


def handle_exc(func):
    @functools.wraps(func)
    def wrapped(form, request, *args, **kwargs):
        try:
            return func(form, request, *args, **kwargs)
        except designate_exceptions.RemoteError as ex:
            msg = ""
            data = {}

            if ex.message is not None:
                data['message'] = ex.message
                msg += "Error: %(message)s"
            else:
                data["type"] = ex.type
                msg += "Error Type: %(type)s"

            if ex.code >= 500:
                msg += " (Request ID: %(request_id)s"
                data["request_id"] = ex.request_id

            form.api_error(_(msg) % data)  # noqa

            return False
        except Exception:
            messages.error(request, form.exc_message)
            return True<commit_msg>SSHFP validation: Allow algorithm 4 - ED25519<commit_after># Copyright 2013 Hewlett-Packard Development Company, L.P.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import functools
import logging
import re

from designateclient import exceptions as designate_exceptions
from django.core.exceptions import ValidationError  # noqa
from django.core import validators
from django.template.loader import render_to_string
from django.utils.translation import ugettext_lazy as _  # noqa

from horizon import forms
from horizon import messages

from designatedashboard import api
from designatedashboard.dashboards.project.dns_domains.utils\
    import limit_records_to_fips


LOG = logging.getLogger(__name__)

MAX_TTL = 2147483647
# These regexes were given to me by <NAME> here:
# https://gerrit.hpcloud.net/#/c/25300/2/
DOMAIN_NAME_REGEX = r'^(?!.{255,})(?:(?!\-)[A-Za-z0-9_\-]{1,63}(?<!\-)\.)+$'
WILDCARD_DOMAIN_NAME_REGEX = r'^(?!.{255,})(?:(^\*|(?!\-)[A-Za-z0-9_\-]{1,63})(?<!\-)\.)+$'  # noqa
SRV_NAME_REGEX = r'^(?:_[A-Za-z0-9_\-]{1,62}\.){2}'
SRV_DATA_REGEX = r'^(?:(?:6553[0-5]|655[0-2][0-9]|65[0-4][0-9]{2}|6[0-4][0-9]{3}|[1-5][0-9]{4}|[1-9][0-9]{1,3}|[0-9])\s){2}(?!.{255,})((?!\-)[A-Za-z0-9_\-]{1,63}(?<!\-)\.)+$'  # noqa
SSHFP_DATA_REGEX = r'^[1-4]\s[1-2]\s\b([0-9a-fA-F]{5,40}|[0-9a-fA-F]{64})\b$'
# The max length for a dns label
NAME_MAX_LENGTH = 63


def handle_exc(func):
    @functools.wraps(func)
    def wrapped(form, request, *args, **kwargs):
        try:
            return func(form, request, *args, **kwargs)
        except designate_exceptions.RemoteError as ex:
            msg = ""
            data = {}

            if ex.message is not None:
                data['message'] = ex.message
                msg += "Error: %(message)s"
            else:
                data["type"] = ex.type
                msg += "Error Type: %(type)s"

            if ex.code >= 500:
                msg += " (Request ID: %(request_id)s"
                data["request_id"] = ex.request_id

            form.api_error(_(msg) % data)  # noqa

            return False
        except Exception:
            messages.error(request, form.exc_message)
            return True
{'fraction_non_alphanumeric': 0.16159338594513342, 'fraction_numerical': 0.04321683577602405, 'mean_word_length': 3.0386949924127467, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6538445', 'n_tokens_mistral': 1958, 'n_tokens_neox': 1827, 'n_words': 452}