def buffer_to_bytes(buf):
 if (not isinstance(buf, bytes)):
  buf = bytes(buf)
 return buf

def buffer_to_bytes ( buf ) : if ( not isinstance ( buf , bytes ) ) : buf = bytes ( buf ) return buf
cast a buffer object to bytes .