code: def namespace_from_url(url):
      
      parsed = urlparse(url)
      if parsed.hostname is None or parsed.hostname in ['localhost', 'localhost.localdomain'] or (
              _ipv4_re.search(parsed.hostname)):
          return None
  
      namespace = parsed.hostname.split('.')
      namespace.reverse()
      if namespace and not namespace[0]:
          namespace.pop(0)
      if namespace and namespace[-1] == 'www':
          namespace.pop(-1)
      return type(url)('.'.join(namespace))
docs: Construct a dotted namespace string from a URL.