def _DeleteFile(self, file_name):
    """Delete a file.

    Args:
      file_name: A string, the file name.

    Raises:
      DeleteFileError, if the deletion failed.
    """
    try:
      self._connection.child.send('\r')
      self._connection.child.expect('\r\n', timeout=self.timeout_act_user)
      self._connection.child.expect(self._connection.re_prompt,
                                    timeout=self.timeout_act_user,
                                    searchwindowsize=128)
      self._connection.child.send('delete %s\r' % file_name)
    except pexpect.ExceptionPexpect:
      raise DeleteFileError('DeleteFile operation failed. %s' %
                            self._connection.child)

    try:
      pindex = self._connection.child.expect(
          [r'Delete filename \[.*\]\?',
           r'%.*Error.*'],
          timeout=self.timeout_act_user)
      if pindex == 0:
        self._connection.child.send('\r')
        logging.debug('DeleteFile: answering first confirmation.')
        self._connection.child.expect([r'Delete .*\[confirm\]'],
                                      timeout=self.timeout_act_user)
        logging.debug('DeleteFile: answering second confirmation.')
        self._connection.child.send('\r')
      elif pindex == 1:
        raise DeleteFileError('DeleteFile operation failed. %s' %
                              self._connection.child.match)

      pindex = self._connection.child.expect([self._connection.re_prompt,
                                              r'%.*Error.*'],
                                             timeout=self.timeout_act_user)
      if pindex == 1:
        raise DeleteFileError('DeleteFile operation failed. %s' %
                              self._connection.child.match)
      logging.debug('DeleteFile: success.')
    except pexpect.ExceptionPexpect:
      raise DeleteFileError('DeleteFile operation failed. %s' %
                            self._connection.child)
dataset/ETHPy150Open google/capirca/tools/ldpush/ios.py/IosDevice._DeleteFile/original