def download_file(file_from_path, file_to_path, force=False, binary=False,
        real_browser=False):
    url = get_sanitized_url(file_from_path)

    if os.path.exists(file_to_path) and \
       os.path.getsize(file_to_path) > 0 and \
       not force:
        logger.info('Skipped downloading {0} because it already exists in '
                '{1}'.format(url, file_to_path))
        return
    try:
        if not real_browser:
            file_from = get_file_from(url)
        else:
            file_from = get_file_from_real_browser(url)

        if binary:
            file_to = open(file_to_path, 'wb')
        else:
            file_to = codecs.open(file_to_path, 'w', encoding='utf8')

        logger.info('Downloading {0} to {1} in mode binary? {2}'.format(url,
            file_to_path, binary))
        if not binary:
            content = file_from.read()
            encoding = get_encoding(content)
            content = unicode(content, encoding)
            file_to.write(content)
            file_from.close()
            file_to.close()
        else:
            shutil.copyfileobj(file_from, file_to)
            file_from.close()
            file_to.close()
    except Exception:
        logger.info('Error while downloading a file: {0}'.format(
            url))
        if os.path.exists(file_to_path):
            os.remove(file_to_path)
        raise RecoDocError('Error downloading {0}'.format(url))
dataset/ETHPy150Open bartdag/recodoc2/recodoc2/apps/docutil/commands_util.py/download_file/original