<commit_before># -*- coding: utf-8 -*-

""" License

    Copyright (C) 2018 YUNOHOST.ORG

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as published
    by the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program; if not, see http://www.gnu.org/licenses

"""
from publicsuffix import PublicSuffixList

YNH_DYNDNS_DOMAINS = ["nohost.me", "noho.st", "ynh.fr"]

def get_public_suffix(domain):
    """get_public_suffix("www.example.com") -> "example.com"

    Return the public suffix of a domain name based 
    """
    # Load domain public suffixes
    psl = PublicSuffixList()

    public_suffix = psl.get_public_suffix(domain)
    if public_suffix in YNH_DYNDNS_DOMAINS:
        domain_prefix = domain_name[0:-(1 + len(public_suffix))]
        public_suffix =  domain_prefix.plit(".")[-1] + "." + public_suffix

    return public_suffix

def get_dns_zone_from_domain(domain):
    """
    Get the DNS zone of a domain

    Keyword arguments:
        domain -- The domain name
        
    """
    separator = "."
    domain_subs = domain.split(separator)
    for i in range(0, len(domain_subs)):
        answer = dig(separator.join(domain_subs), rdtype="NS", full_answers=True)
        if answer[0] == "ok" :
            return separator.join(domain_subs)
        elif answer[1][0] == "NXDOMAIN" :
            return None
        domain_subs.pop(0)

    # Should not be executed
    return None<commit_msg>Fix import issue in utils/dns<commit_after># -*- coding: utf-8 -*-

""" License

    Copyright (C) 2018 YUNOHOST.ORG

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU Affero General Public License as published
    by the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Affero General Public License for more details.

    You should have received a copy of the GNU Affero General Public License
    along with this program; if not, see http://www.gnu.org/licenses

"""
from publicsuffix import PublicSuffixList
from yunohost.utils.network import dig

YNH_DYNDNS_DOMAINS = ["nohost.me", "noho.st", "ynh.fr"]

def get_public_suffix(domain):
    """get_public_suffix("www.example.com") -> "example.com"

    Return the public suffix of a domain name based 
    """
    # Load domain public suffixes
    psl = PublicSuffixList()

    public_suffix = psl.get_public_suffix(domain)
    if public_suffix in YNH_DYNDNS_DOMAINS:
        domain_prefix = domain_name[0:-(1 + len(public_suffix))]
        public_suffix =  domain_prefix.plit(".")[-1] + "." + public_suffix

    return public_suffix

def get_dns_zone_from_domain(domain):
    """
    Get the DNS zone of a domain

    Keyword arguments:
        domain -- The domain name
        
    """
    separator = "."
    domain_subs = domain.split(separator)
    for i in range(0, len(domain_subs)):
        answer = dig(separator.join(domain_subs), rdtype="NS", full_answers=True)
        if answer[0] == "ok" :
            return separator.join(domain_subs)
        elif answer[1][0] == "NXDOMAIN" :
            return None
        domain_subs.pop(0)

    # Should not be executed
    return None
{'fraction_non_alphanumeric': 0.08804544280919184, 'fraction_numerical': 0.007229537825974697, 'mean_word_length': 3.027027027027027, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '3188567', 'n_tokens_mistral': 1196, 'n_tokens_neox': 1124, 'n_words': 397}