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, }
def test_missing_scheme(self): self.assertEqual(parse_domain_from_url('www.example.com'), ('www.example.com', 'example.com', '', 'example', 'com', 'www'))
def test_missing_subdomain(self): self.assertEqual(parse_domain_from_url('https://example.com'), ('example.com', 'example.com', 'https', 'example', 'com', ''))
def test_missing_tld(self): self.assertEqual(parse_domain_from_url('http://www.example'), ('www.example', 'example', 'http', 'example', '', 'www'))
def test_complete_url(self): self.assertEqual(parse_domain_from_url(complete_url), ('www.example.com', 'example.com', 'http', 'example', 'com', 'www'))
def test_missing_scheme(self): self.assertEqual( parse_domain_from_url('www.example.com'), ('www.example.com', 'example.com', '', 'example', 'com', 'www'))
def test_missing_subdomain(self): self.assertEqual( parse_domain_from_url('https://example.com'), ('example.com', 'example.com', 'https', 'example', 'com', ''))
def test_missing_tld(self): self.assertEqual( parse_domain_from_url('http://www.example'), ('www.example', 'example', 'http', 'example', '', 'www'))