def encode_for_querystring(s):
 if (not isinstance(s, unicode)):
  raise TypeError(u'unicode required')
 return urlsafe_b64encode(s.encode(u'utf8')).replace('=', '~').decode(u'ascii')

def encode_for_querystring ( s ) : if ( not isinstance ( s , unicode ) ) : raise TypeError ( u'unicode required' ) return urlsafe_b64encode ( s . encode ( u'utf8' ) ) . replace ( '=' , '~' ) . decode ( u'ascii' )
given a unicode .