'Sets the encoding to use for `writing and reading` in the current connection.
The given ``encoding`` specifies the encoding to use when written/read
text is encoded/decoded, and ``errors`` specifies the error handler to
use if encoding/decoding fails. Either of these can be omitted and in
that case the old value is not affected. Use string ``NONE`` to disable
encoding altogether.
See `Configuration` section for more information about encoding and
error handlers, as well as global and connection specific configuration
in general.
The old values are returned and can be used to restore the encoding
and the error handler later. See `Set Prompt` for a similar example.
If terminal emulation is used, the encoding can not be changed on an open
connection.
Setting encoding in general is a new feature in Robot Framework 2.7.6.
Specifying the error handler and disabling encoding were added in 2.7.7.'

def set_encoding(self, encoding=None, errors=None):

    self._verify_connection()
    if self._terminal_emulator:
        raise AssertionError('Encoding    can    not    be    changed    when    terminal    emulation    is    used.')
    old = self._encoding
    self._set_encoding((encoding or old[0]), (errors or old[1]))
    return old
