Fix safe_encode(): return bytes on Python 3

safe_decode() decodes bytes to text. safe_encode() should be the reverse
operation: encode text to bytes. Currently, it returns text on Python 3
which is wrong in my opinion.

The patch fixes also test_encode() on Python 3.

Change-Id: If91a866d864a22d28a352152beff4c7406a27b7b
Merge "Fix safe_encode(): return bytes on Python 3"