code: def write_bytes(self, data):
          
          if not isinstance(data, six.binary_type):
              raise TypeError(
                  'data must be %s, not %s' %
                  (six.binary_type.__class__.__name__, data.__class__.__name__))
          with self.open(mode='wb') as f:
              return f.write(data)
docs: Open the file in bytes mode, write to it, and close the file.