code: def url_quote(string, charset='utf-8', errors='strict', safe='/:'):
      
      if not isinstance(string, (text_type, bytes, bytearray)):
          string = text_type(string)
      if isinstance(string, text_type):
          string = string.encode(charset, errors)
      if isinstance(safe, text_type):
          safe = safe.encode(charset, errors)
      safe = frozenset(bytearray(safe) + _always_safe)
      rv = bytearray()
      for char in bytearray(string):
          if char in safe:
              rv.append(char)
          else:
              rv.extend(('%%%02X' % char).encode('ascii'))
      return to_native(bytes(rv))
docs: URL encode a single string with a given encoding.
  
      :param s: the string to quote.
      :param charset: the charset to be used.
      :param safe: an optional sequence of safe characters.