<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _ensure_url_string(url):
 """Convert `url` to a string URL if it isn't one already."""

    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,))