code: def validated_url(url):
      
      try:
          u = urlparse(url)
          u.port  # Trigger 'invalid port' exception
      except Exception:
          raise error.URLError(url)
      else:
          if not u.scheme or not u.netloc:
              raise error.URLError(url)
          return url
docs: Return url if valid, raise URLError otherwise