Merge pull request #1649 from mroutis/fix-makedirs

py2: raise OSErrors on makedirs
This commit is contained in:
Ruslan Kuprieiev
2019-02-21 22:14:22 +02:00
committed by GitHub
+4 -5
View File
@@ -14,9 +14,6 @@ is_py2 = _ver[0] == 2
#: Python 3.x?
is_py3 = _ver[0] == 3
# NOTE: cast_bytes_py2 is taken from https://github.com/ipython/ipython_genutils
# NOTE _makedirs is taken from https://github.com/python/cpython/blob/3ce3dea60646d8a5a1c952469a2eb65f937875b3/Lib/os.py#L196-L226
# simplified version of ipython_genutils/encoding.py
DEFAULT_ENCODING = sys.getdefaultencoding()
@@ -30,12 +27,14 @@ def encode(u, encoding=None):
return u.encode(encoding, "replace")
# NOTE: cast_bytes_py2 is taken from https://github.com/ipython/ipython_genutils
def cast_bytes(s, encoding=None):
if not isinstance(s, bytes):
return encode(s, encoding)
return s
# NOTE _makedirs is taken from https://github.com/python/cpython/blob/3ce3dea60646d8a5a1c952469a2eb65f937875b3/Lib/os.py#L196-L226
def _makedirs(name, mode=0o777, exist_ok=False):
head, tail = os.path.split(name)
if not tail:
@@ -44,8 +43,8 @@ def _makedirs(name, mode=0o777, exist_ok=False):
try:
_makedirs(head, exist_ok=exist_ok)
except OSError as e:
if e.errno == errno.EEXIST:
pass
if e.errno != errno.EEXIST:
raise
cdir = os.curdir
if isinstance(tail, bytes):
cdir = bytes(os.curdir, "ASCII")