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:
Mike Hommey 2019-08-21 03:03:53 +00:00
Родитель 86dcd49bdf
Коммит 843c5016d9
1 изменённых файлов: 10 добавлений и 2 удалений

Просмотреть файл

@ -23,9 +23,17 @@ def normsep(path):
:py:const:`os.sep` is.
'''
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 != '/':
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