lib/py: JavaOutputProtocol: encode in ASCII before escaping string