code: def _ensure_url_string(url):
      
      if isinstance(url, str):
          return url
      elif isinstance(url, (ParseResult, SplitResult)):
          return url.geturl()
      else:
          raise TypeError(
              "Could not convert %r to a string URL." % (url,))
docs: Convert `url` to a string URL if it isn't one already.