Esempio n. 1
0
def parse_domain_info(url, test_mode=False):
    if test_mode:
        match = re.match('([A-Z])\w+', url)
        netloc = name = match.groups()[0] if match else '?'
        scheme = sld = tld = subdomain = '-'
    else:
        netloc, name, scheme, sld, tld, subdomain = parse_domain_from_url(url)
    return {
        'netloc': netloc,
        'name': name,
        'scheme': scheme,
        'sld': sld,
        'tld': tld,
        'subdomain': subdomain,
    }
Esempio n. 2
0
 def test_missing_scheme(self):
     self.assertEqual(parse_domain_from_url('www.example.com'),
                      ('www.example.com', 'example.com', '', 'example', 'com', 'www'))
Esempio n. 3
0
 def test_missing_subdomain(self):
     self.assertEqual(parse_domain_from_url('https://example.com'),
                      ('example.com', 'example.com', 'https', 'example', 'com', ''))
Esempio n. 4
0
 def test_missing_tld(self):
     self.assertEqual(parse_domain_from_url('http://www.example'),
                      ('www.example', 'example', 'http', 'example', '', 'www'))
Esempio n. 5
0
 def test_complete_url(self):
     self.assertEqual(parse_domain_from_url(complete_url),
                      ('www.example.com', 'example.com', 'http', 'example', 'com', 'www'))
Esempio n. 6
0
 def test_missing_scheme(self):
     self.assertEqual(
         parse_domain_from_url('www.example.com'),
         ('www.example.com', 'example.com', '', 'example', 'com', 'www'))
Esempio n. 7
0
 def test_missing_subdomain(self):
     self.assertEqual(
         parse_domain_from_url('https://example.com'),
         ('example.com', 'example.com', 'https', 'example', 'com', ''))
Esempio n. 8
0
 def test_missing_tld(self):
     self.assertEqual(
         parse_domain_from_url('http://www.example'),
         ('www.example', 'example', 'http', 'example', '', 'www'))
Esempio n. 9
0
 def test_complete_url(self):
     self.assertEqual(parse_domain_from_url(complete_url),
                      ('www.example.com', 'example.com', 'http', 'example',
                       'com', 'www'))