code: def extract_bytes(mv):
      
      if isinstance(mv, memoryview):
          return mv.tobytes() if six.PY3 else bytes(mv)
  
      if isinstance(mv, bytes):
          return mv
  
      raise ValueError
docs: Retrieve bytes out of memoryview/buffer or bytes.