215
216
return posixpath.realpath(path.encode(_fs_enc)).decode(_fs_enc)
219
def _win32_fixdrive(path):
220
"""Force drive letters to be consistent.
222
win32 is inconsistent whether it returns lower or upper case
223
and even if it was consistent the user might type the other
224
so we force it to uppercase
225
running python.exe under cmd.exe return capital C:\\
226
running win32 python inside a cygwin shell returns lowercase c:\\
228
drive, path = _nt_splitdrive(path)
229
return drive.upper() + path
218
232
def _win32_abspath(path):
219
233
# Real _nt_abspath doesn't have a problem with a unicode cwd
220
return _nt_abspath(unicode(path)).replace('\\', '/')
234
return _win32_fixdrive(_nt_abspath(unicode(path)).replace('\\', '/'))
223
237
def _win32_realpath(path):
224
238
# Real _nt_realpath doesn't have a problem with a unicode cwd
225
return _nt_realpath(unicode(path)).replace('\\', '/')
239
return _win32_fixdrive(_nt_realpath(unicode(path)).replace('\\', '/'))
228
242
def _win32_pathjoin(*args):
232
246
def _win32_normpath(path):
233
return _nt_normpath(unicode(path)).replace('\\', '/')
247
return _win32_fixdrive(_nt_normpath(unicode(path)).replace('\\', '/'))
236
250
def _win32_getcwd():
237
return os.getcwdu().replace('\\', '/')
251
return _win32_fixdrive(os.getcwdu().replace('\\', '/'))
240
254
def _win32_mkdtemp(*args, **kwargs):
241
return tempfile.mkdtemp(*args, **kwargs).replace('\\', '/')
255
return _win32_fixdrive(tempfile.mkdtemp(*args, **kwargs).replace('\\', '/'))
244
258
def _win32_rename(old, new):
245
fancy_rename(old, new, rename_func=os.rename, unlink_func=os.unlink)
259
"""We expect to be able to atomically replace 'new' with old.
261
On win32, if new exists, it must be moved out of the way first,
265
fancy_rename(old, new, rename_func=os.rename, unlink_func=os.unlink)
267
if e.errno in (errno.EPERM, errno.EACCES, errno.EBUSY):
268
# If we try to rename a non-existant file onto cwd, we get EPERM
269
# instead of ENOENT, this will raise ENOENT if the old path
248
275
# Default is to just use the python builtins, but these can be rebound on