@contextlib.contextmanager
def safe_query_string(request):
 qs = request.META['QUERY_STRING']
 try:
  request.META['QUERY_STRING'] = iri_to_uri(qs)
  (yield)
 finally:
  request.META['QUERY_STRING'] = qs

@ contextlib . contextmanager def safe_query_string ( request ) : qs = request . META [ 'QUERY_STRING' ] try : request . META [ 'QUERY_STRING' ] = iri_to_uri ( qs ) ( yield ) finally : request . META [ 'QUERY_STRING' ] = qs
turn the query_string into a unicode- and ascii-safe string .