зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1575375 - Make mozpack.path.normsep work with both bytes and unicode strings in python 3. r=nalexander
Differential Revision: https://phabricator.services.mozilla.com/D42753 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
86dcd49bdf
Коммит
843c5016d9
|
@ -23,9 +23,17 @@ def normsep(path):
|
||||||
:py:const:`os.sep` is.
|
:py:const:`os.sep` is.
|
||||||
'''
|
'''
|
||||||
if os.sep != '/':
|
if os.sep != '/':
|
||||||
path = path.replace(os.sep, '/')
|
# Python 2 is happy to do things like byte_string.replace(u'foo',
|
||||||
|
# u'bar'), but not Python 3.
|
||||||
|
if isinstance(path, bytes):
|
||||||
|
path = path.replace(os.sep.encode('ascii'), b'/')
|
||||||
|
else:
|
||||||
|
path = path.replace(os.sep, '/')
|
||||||
if os.altsep and os.altsep != '/':
|
if os.altsep and os.altsep != '/':
|
||||||
path = path.replace(os.altsep, '/')
|
if isinstance(path, bytes):
|
||||||
|
path = path.replace(os.altsep.encode('ascii'), b'/')
|
||||||
|
else:
|
||||||
|
path = path.replace(os.altsep, '/')
|
||||||
return path
|
return path
|
||||||
|
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче