def encode_string(text):
if six.PY3:<EOL><INDENT>return text<EOL><DEDENT>if isinstance(text, str):<EOL><INDENT>return text.decode('<STR_LIT:utf-8>').encode('<STR_LIT:utf-8>', '<STR_LIT:ignore>')<EOL><DEDENT>return text.encode('<STR_LIT:utf-8>', '<STR_LIT:ignore>')<EOL>
On Python 3 this method does nothing and returns the ``text`` string itself.
On Python 2 this method returns the ``text`` string encoded with UTF-8.

See:
* https://pythonhosted.org/six/#six.python_2_unicode_compatible
* https://www.azavea.com/blog/2014/03/24/solving-unicode-problems-in-python-2-7/