Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _str_path(path, mkdir=False):
"""Get a file-system path as text_type, suitable for passing into io.open.
Parameters
----------
path : {text_type, Path}
A fs path either as Path instance or as text_type.
mkdir : bool (default=False)
If True, create the directories within the path.
Returns
-------
path : text_type
The path as text_type.
"""
res = Path(path_component(path))
if mkdir and res.parent and not res.parent.exists():
res.parent.mkdir(parents=True)
return res.as_posix()