human
Complete this python program:
def _urlquote(string, safe=u''):
assistant
#Here is the Python program you requested.

    """Quotes a unicode string for use in a URL
    :param string:
    A unicode string
    :param safe:
    A unicode string of character to not encode
    :return:
    None (if string is None) or an ASCII byte string of the quoted string
    """
    if ((string is None) or (string == u'')):
        return None
    escapes = []
    if re.search(u'%[0-9a-fA-F]{2}', string):
        def _try_unescape(match):
            byte_string = unquote_to_bytes(match.group(0))
            unicode_string = byte_string.decode(u'utf-8', u'iriutf8')
            for safe_char in list(safe):
                unicode_string = unicode_string.replace(safe_char, (u'%%%02x' % ord(safe_char)))
            return unicode_string
        string = re.sub(u'(?:%[0-9a-fA-F]{2})+', _try_unescape, string)
        def _extract_escape(match):
            escapes.append(match.group(0).encode(u'ascii'))
            return u'\x00'
        string = re.sub(u'%[0-9a-fA-F]{2}', _extract_escape, string)
    output = urlquote(string.encode(u'utf-8'), safe=safe.encode(u'utf-8'))
    if (not isinstance(output, byte_cls)):
        output = output.encode(u'ascii')
    if (len(escapes) > 0):
        def _return_escape(_):
            return escapes.pop(0)
        output = re.sub('%00', _return_escape, output)
    return output