Пример #1
0
    def _validate(self) -> dict:
        result = dict()
        result['errors'] = []
        result['records'] = []
        if not self.mx_records or len(self.mx_records) == 0:
            result['errors'].append(MXErrors.NO_MX_RECORDS)
            self.errors = result['errors']
            return result

        for record in self.mx_records:
            if not record:
                result['errors'].append(MXErrors.BLANK_MX_RECORD)
                continue
            parts = record.split(' ')

            if len(parts) > 2:
                result['errors'].append(MXErrors.TOO_MANY_PARTS)
                continue

            if len(parts) < 2:
                result['errors'].append(MXErrors.TOO_FEW_PARTS)
                continue

            preference = parts[0]
            exchange = parts[1]

            # Check preference to be an unsigned 16 bit int, RFC 974 (Page 2)
            preference, preference_errors = validate_numbers(preference, MXErrors.INVALID_PREFERENCE,
                                                                  MXErrors.PREFERENCE_OUT_OF_RANGE, MaxValue.USIXTEEN)
            result['errors'].extend(preference_errors)

            if preference_errors:
                continue

            if is_an_ip(exchange):
                result['errors'].append(MXErrors.EXCHANGE_IS_AN_IP)
                continue

            if not validate_domain(exchange):
                result['errors'].append(MXErrors.INVALID_EXCHANGE)
                continue

            if not publicsuffix2.get_tld(exchange) in publicsuffix2.PublicSuffixList().tlds:
                result['errors'].append(MXErrors.NOT_PUBLIC_DOMAIN)
                continue

            if not exchange.endswith('.') and exchange.endswith(publicsuffix2.get_tld(exchange)):
                result['errors'].append(MXErrors.POSSIBLE_BAD_EXCHANGE)

            result['records'].append(MxRecord(preference, exchange))

        self.errors = result['errors']
        self.valid_mx_records = result['records']
        return result
Пример #2
0
def colorize_host(host):
    tld = get_tld(host)
    sld = get_sld(host)

    attr = []

    tld_size = len(tld)
    sld_size = len(sld) - tld_size

    for letter in reversed(range(len(host))):
        character = host[letter]
        if tld_size > 0:
            style = 'url_domain'
            tld_size -= 1
        elif tld_size == 0:
            style = 'text'
            tld_size -= 1
        elif sld_size > 0:
            sld_size -= 1
            style = 'url_extension'
        else:
            style = 'text'
        rle_append_beginning_modify(attr, (style, len(character.encode())))
    return attr
 def test_get_tld_TLD_with_some_2_level_rules9(self):
     assert 'ac' == publicsuffix.get_tld('test.ac', strict=True)
 def test_get_tld_TLD_with_only_1_rule1(self):
     assert 'biz' == publicsuffix.get_tld('biz')
 def test_get_tld_Listed_but_non_Internet_TLD1(self):
     assert 'local' == publicsuffix.get_tld('local')
 def test_get_tld_Leading_dot4(self):
     assert 'example' == publicsuffix.get_tld('.example.example')
 def test_get_tld_Same_as_above_but_punycoded9(self):
     assert 'xn--fiqs8s' == publicsuffix.get_tld('xn--fiqs8s', strict=True)
 def test_get_tld_Same_as_above_but_punycoded1(self):
     assert 'com.cn' == publicsuffix.get_tld('xn--85x722f.com.cn',
                                             strict=True)
 def test_get_tld_Mixed_case(self):
     assert 'com' == publicsuffix.get_tld('COM')
 def test_get_tld_More_complex_TLD11(self):
     assert 'ide.kyoto.jp' == publicsuffix.get_tld('a.b.ide.kyoto.jp',
                                                   strict=True)
 def test_get_tld_More_complex_TLD8(self):
     assert 'kyoto.jp' == publicsuffix.get_tld('test.kyoto.jp', strict=True)
 def test_get_tld_More_complex_TLD6(self):
     assert 'ac.jp' == publicsuffix.get_tld('www.test.ac.jp', strict=True)
 def test_get_tld_null_input(self):
     assert None == publicsuffix.get_tld(None)
 def test_get_tld_More_complex_TLD1(self):
     assert 'jp' == publicsuffix.get_tld('jp', strict=True)
 def test_get_tld_TLD_with_only_1_wildcard_rule4(self):
     assert 'c.bd' == publicsuffix.get_tld('a.b.c.bd', strict=True)
 def test_get_tld_Mixed_case3(self):
     assert 'com' == publicsuffix.get_tld('WwW.example.COM')
 def test_get_tld_Leading_dot1(self):
     assert 'com' == publicsuffix.get_tld('.com')
 def test_get_tld_More_complex_TLD14(self):
     assert 'c.kobe.jp' == publicsuffix.get_tld('a.b.c.kobe.jp',
                                                strict=True)
 def test_get_tld_Same_as_above_but_punycoded5(self):
     assert 'xn--55qx5d.cn' == publicsuffix.get_tld('xn--55qx5d.cn',
                                                    strict=True)
 def test_get_tld_More_complex_TLD16(self):
     assert 'kobe.jp' == publicsuffix.get_tld('www.city.kobe.jp',
                                              strict=True)
 def test_get_tld_Leading_dot3(self):
     assert 'com' == publicsuffix.get_tld('.example.com')
 def test_get_tld_TLD_with_a_wildcard_rule_and_exceptions4(self):
     assert 'test.ck' == publicsuffix.get_tld('a.b.test.ck', strict=True)
 def test_get_tld_Unlisted_TLD4(self):
     assert 'example' == publicsuffix.get_tld('a.b.example.example')
 def test_get_tld_TLD_with_a_wildcard_rule_and_exceptions6(self):
     assert 'ck' == publicsuffix.get_tld('www.www.ck', strict=True)
 def test_get_tld_Listed_but_non_Internet_TLD4(self):
     assert 'local' == publicsuffix.get_tld('a.b.example.local')
 def test_get_tld_US_K123(self):
     assert 'us' == publicsuffix.get_tld('www.test.us', strict=True)
 def test_get_tld_TLD_with_only_1_rule4(self):
     assert 'biz' == publicsuffix.get_tld('a.b.domain.biz')
 def test_get_tld_US_K125(self):
     assert 'ak.us' == publicsuffix.get_tld('test.ak.us', strict=True)
 def test_get_tld_US_K129(self):
     assert 'k12.ak.us' == publicsuffix.get_tld('www.test.k12.ak.us',
                                                strict=True)
 def test_get_tld_TLD_with_some_2_level_rules8(self):
     assert 'uk.com' == publicsuffix.get_tld('a.b.example.uk.com',
                                             strict=True)