move encoding from ruby to python - JRuby seems happier with this