def CreateFile(filename, contents, eol_style=EOL_STYLE_NATIVE, create_dir=True, encoding=None, binary=False):
<EOL>if binary:<EOL><INDENT>if isinstance(contents, six.text_type):<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if not isinstance(contents, six.text_type):<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT>contents = _HandleContentsEol(contents, eol_style)<EOL>encoding = encoding or sys.getfilesystemencoding()<EOL>contents = contents.encode(encoding)<EOL>binary = True<EOL><DEDENT>if create_dir:<EOL><INDENT>dirname = os.path.dirname(filename)<EOL>if dirname:<EOL><INDENT>CreateDirectory(dirname)<EOL><DEDENT><DEDENT>from six.moves.urllib.parse import urlparse<EOL>filename_url = urlparse(filename)<EOL>if _UrlIsLocal(filename_url):<EOL><INDENT>with open(filename, '<STR_LIT:wb>') as oss:<EOL><INDENT>oss.write(contents)<EOL><DEDENT><DEDENT>elif filename_url.scheme == '<STR_LIT>':<EOL><INDENT>from ._exceptions import NotImplementedProtocol<EOL>raise NotImplementedProtocol(directory_url.scheme)<EOL><DEDENT>else:<EOL><INDENT>from ._exceptions import NotImplementedProtocol<EOL>raise NotImplementedProtocol(filename_url.scheme)<EOL><DEDENT>return filename<EOL>
Create a file with the given contents.

:param unicode filename:
    Filename and path to be created.

:param unicode contents:
    The file contents as a string.

:type eol_style: EOL_STYLE_XXX constant
:param eol_style:
    Replaces the EOL by the appropriate EOL depending on the eol_style value.
    Considers that all content is using only "\n" as EOL.

:param bool create_dir:
    If True, also creates directories needed in filename's path

:param unicode encoding:
    Target file's content encoding. Defaults to sys.getfilesystemencoding()
    Ignored if `binary` = True

:param bool binary:
    If True, file is created in binary mode. In this case, `contents` must be `bytes` and not
    `unicode`

:return unicode:
    Returns the name of the file created.

:raises NotImplementedProtocol:
    If file protocol is not local or FTP

:raises ValueError:
    If trying to mix unicode `contents` without `encoding`, or `encoding` without
    unicode `contents`

.. seealso:: FTP LIMITATIONS at this module's doc for performance issues information