def save(self):
<EOL>if self.compression and hasattr(self.path_or_buf, '<STR_LIT>'):<EOL><INDENT>msg = ("<STR_LIT>"<EOL>"<STR_LIT>")<EOL>warnings.warn(msg, RuntimeWarning, stacklevel=<NUM_LIT:2>)<EOL><DEDENT>is_zip = isinstance(self.path_or_buf, ZipFile) or (<EOL>not hasattr(self.path_or_buf, '<STR_LIT>')<EOL>and self.compression == '<STR_LIT>')<EOL>if is_zip:<EOL><INDENT>f = StringIO()<EOL>close = False<EOL><DEDENT>elif hasattr(self.path_or_buf, '<STR_LIT>'):<EOL><INDENT>f = self.path_or_buf<EOL>close = False<EOL><DEDENT>else:<EOL><INDENT>f, handles = _get_handle(self.path_or_buf, self.mode,<EOL>encoding=self.encoding,<EOL>compression=self.compression)<EOL>close = True<EOL><DEDENT>try:<EOL><INDENT>writer_kwargs = dict(lineterminator=self.line_terminator,<EOL>delimiter=self.sep, quoting=self.quoting,<EOL>doublequote=self.doublequote,<EOL>escapechar=self.escapechar,<EOL>quotechar=self.quotechar)<EOL>if self.encoding == '<STR_LIT:ascii>':<EOL><INDENT>self.writer = csvlib.writer(f, **writer_kwargs)<EOL><DEDENT>else:<EOL><INDENT>writer_kwargs['<STR_LIT>'] = self.encoding<EOL>self.writer = UnicodeWriter(f, **writer_kwargs)<EOL><DEDENT>self._save()<EOL><DEDENT>finally:<EOL><INDENT>if is_zip:<EOL><INDENT>buf = f.getvalue()<EOL>if hasattr(self.path_or_buf, '<STR_LIT>'):<EOL><INDENT>self.path_or_buf.write(buf)<EOL><DEDENT>else:<EOL><INDENT>f, handles = _get_handle(self.path_or_buf, self.mode,<EOL>encoding=self.encoding,<EOL>compression=self.compression)<EOL>f.write(buf)<EOL>close = True<EOL><DEDENT><DEDENT>if close:<EOL><INDENT>f.close()<EOL>for _fh in handles:<EOL><INDENT>_fh.close()<EOL><DEDENT><DEDENT><DEDENT>
Create the writer & save