def _urlunquote(byte_string, remap=None, preserve=None):
 if (byte_string is None):
  return byte_string
 byte_string = unquote_to_bytes(byte_string)
 if preserve:
  replacements = [u'\x1a', u'\x1c', u'\x1d', u'\x1e', u'\x1f']
  preserve_unmap = {}
  for char in remap:
   replacement = replacements.pop(0)
   preserve_unmap[replacement] = char
   byte_string = byte_string.replace(char.encode(u'ascii'), replacement.encode(u'ascii'))
 if remap:
  for char in remap:
   byte_string = byte_string.replace(char.encode(u'ascii'), (u'%%%02x' % ord(char)).encode(u'ascii'))
 output = byte_string.decode(u'utf-8', u'iriutf8')
 if preserve:
  for (replacement, original) in preserve_unmap.items():
   output = output.replace(replacement, original)
 return output

def _urlunquote ( byte_string , remap = None , preserve = None ) : if ( byte_string is None ) : return byte_string byte_string = unquote_to_bytes ( byte_string ) if preserve : replacements = [ u'\x1a' , u'\x1c' , u'\x1d' , u'\x1e' , u'\x1f' ] preserve_unmap = { } for char in remap : replacement = replacements . pop ( 0 ) preserve_unmap [ replacement ] = char byte_string = byte_string . replace ( char . encode ( u'ascii' ) , replacement . encode ( u'ascii' ) ) if remap : for char in remap : byte_string = byte_string . replace ( char . encode ( u'ascii' ) , ( u'%%%02x' % ord ( char ) ) . encode ( u'ascii' ) ) output = byte_string . decode ( u'utf-8' , u'iriutf8' ) if preserve : for ( replacement , original ) in preserve_unmap . items ( ) : output = output . replace ( replacement , original ) return output
unquotes a uri portion from a byte string into unicode using utf-8 .