<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def url_quote(url):
 """Ensure url is valid"""

    try:
        return quote(url, safe=URL_SAFE)
    except KeyError:
        return quote(encode(url), safe=URL_SAFE)