def asbytes(s):
try:<EOL><INDENT>return b(s)<EOL><DEDENT>except TypeError:<EOL><INDENT>try:<EOL><INDENT>return s.asbytes()<EOL><DEDENT>except AttributeError:<EOL><INDENT>return s<EOL><DEDENT><DEDENT>
Coerce to bytes if possible or return unchanged.