예제 #1
0
파일: domain.py 프로젝트: plafl/frontera
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,
    }
예제 #2
0
 def test_missing_scheme(self):
     self.assertEqual(parse_domain_from_url('www.example.com'),
                      ('www.example.com', 'example.com', '', 'example', 'com', 'www'))
예제 #3
0
 def test_missing_subdomain(self):
     self.assertEqual(parse_domain_from_url('https://example.com'),
                      ('example.com', 'example.com', 'https', 'example', 'com', ''))
예제 #4
0
 def test_missing_tld(self):
     self.assertEqual(parse_domain_from_url('http://www.example'),
                      ('www.example', 'example', 'http', 'example', '', 'www'))
예제 #5
0
 def test_complete_url(self):
     self.assertEqual(parse_domain_from_url(complete_url),
                      ('www.example.com', 'example.com', 'http', 'example', 'com', 'www'))
예제 #6
0
 def test_missing_scheme(self):
     self.assertEqual(
         parse_domain_from_url('www.example.com'),
         ('www.example.com', 'example.com', '', 'example', 'com', 'www'))
예제 #7
0
 def test_missing_subdomain(self):
     self.assertEqual(
         parse_domain_from_url('https://example.com'),
         ('example.com', 'example.com', 'https', 'example', 'com', ''))
예제 #8
0
 def test_missing_tld(self):
     self.assertEqual(
         parse_domain_from_url('http://www.example'),
         ('www.example', 'example', 'http', 'example', '', 'www'))
예제 #9
0
 def test_complete_url(self):
     self.assertEqual(parse_domain_from_url(complete_url),
                      ('www.example.com', 'example.com', 'http', 'example',
                       'com', 'www'))