def _maximalPercentEncode(text, safe):
 quoted = urlquote(normalize('NFC', text).encode('utf-8'), (safe + u'%').encode('ascii'))
 if (not isinstance(quoted, unicode)):
  quoted = quoted.decode('ascii')
 return quoted

def _maximalPercentEncode ( text , safe ) : quoted = urlquote ( normalize ( 'NFC' , text ) . encode ( 'utf-8' ) , ( safe + u'%' ) . encode ( 'ascii' ) ) if ( not isinstance ( quoted , unicode ) ) : quoted = quoted . decode ( 'ascii' ) return quoted
percent-encode everything required to convert a portion of an iri to a portion of a uri .