def cast_bytes(s, encoding='utf8', errors='strict'):
 if isinstance(s, bytes):
  return s
 elif isinstance(s, unicode):
  return s.encode(encoding, errors)
 else:
  raise TypeError(('Expected unicode or bytes, got %r' % s))

def cast_bytes ( s , encoding = 'utf8' , errors = 'strict' ) : if isinstance ( s , bytes ) : return s elif isinstance ( s , unicode ) : return s . encode ( encoding , errors ) else : raise TypeError ( ( 'Expected unicode or bytes, got %r' % s ) )
cast unicode or bytes to bytes .