'Modify `env.stdout` and `env.stdout_isatty` based on args, if needed.'

def _setup_standard_streams(self):

    self.args.output_file_specified = bool(self.args.output_file)
    if self.args.download:
        if ((not self.args.output_file) and (not self.env.stdout_isatty)):
            self.args.output_file = self.env.stdout
        self.env.stdout = self.env.stderr
        self.env.stdout_isatty = self.env.stderr_isatty
    elif self.args.output_file:
        self.args.output_file.seek(0)
        try:
            self.args.output_file.truncate()
        except IOError as e:
            if (e.errno == errno.EINVAL):
                pass
            else:
                raise
        self.env.stdout = self.args.output_file
        self.env.stdout_isatty = False
