Mercurial > public > mercurial-scm > hg
comparison mercurial/util.py @ 30613:1112ff99d965
py3: replace os.sep with pycompat.ossep (part 1 of 4)
os.sep returns unicodes on Python 3. We have pycompat.ossep which returns
bytes. This patch is a part of 4 patch series which will replace all the
occurrences of os.sep to pycompat.ossep
author | Pulkit Goyal <7895pulkit@gmail.com> |
---|---|
date | Sat, 17 Dec 2016 19:56:30 +0530 |
parents | 98d7636c4729 |
children | bcf4a975f93d |
comparison
equal
deleted
inserted
replaced
30612:d623cc6b3742 | 30613:1112ff99d965 |
---|---|
914 b.reverse() | 914 b.reverse() |
915 while a and b and a[-1] == b[-1]: | 915 while a and b and a[-1] == b[-1]: |
916 a.pop() | 916 a.pop() |
917 b.pop() | 917 b.pop() |
918 b.reverse() | 918 b.reverse() |
919 return os.sep.join((['..'] * len(a)) + b) or '.' | 919 return pycompat.ossep.join((['..'] * len(a)) + b) or '.' |
920 | 920 |
921 def mainfrozen(): | 921 def mainfrozen(): |
922 """return True if we are a frozen executable. | 922 """return True if we are a frozen executable. |
923 | 923 |
924 The code supports py2exe (most common, Windows only) and tools/freeze | 924 The code supports py2exe (most common, Windows only) and tools/freeze |
1301 The root should be normcase-ed, too. | 1301 The root should be normcase-ed, too. |
1302 ''' | 1302 ''' |
1303 def _makefspathcacheentry(dir): | 1303 def _makefspathcacheentry(dir): |
1304 return dict((normcase(n), n) for n in os.listdir(dir)) | 1304 return dict((normcase(n), n) for n in os.listdir(dir)) |
1305 | 1305 |
1306 seps = os.sep | 1306 seps = pycompat.ossep |
1307 if os.altsep: | 1307 if os.altsep: |
1308 seps = seps + os.altsep | 1308 seps = seps + os.altsep |
1309 # Protect backslashes. This gets silly very quickly. | 1309 # Protect backslashes. This gets silly very quickly. |
1310 seps.replace('\\','\\\\') | 1310 seps.replace('\\','\\\\') |
1311 pattern = remod.compile(r'([^%s]+)|([%s]+)' % (seps, seps)) | 1311 pattern = remod.compile(r'([^%s]+)|([%s]+)' % (seps, seps)) |
1368 except OSError: | 1368 except OSError: |
1369 pass | 1369 pass |
1370 | 1370 |
1371 def endswithsep(path): | 1371 def endswithsep(path): |
1372 '''Check path ends with os.sep or os.altsep.''' | 1372 '''Check path ends with os.sep or os.altsep.''' |
1373 return path.endswith(os.sep) or os.altsep and path.endswith(os.altsep) | 1373 return (path.endswith(pycompat.ossep) |
1374 or os.altsep and path.endswith(os.altsep)) | |
1374 | 1375 |
1375 def splitpath(path): | 1376 def splitpath(path): |
1376 '''Split path by os.sep. | 1377 '''Split path by os.sep. |
1377 Note that this function does not use os.altsep because this is | 1378 Note that this function does not use os.altsep because this is |
1378 an alternative of simple "xxx.split(os.sep)". | 1379 an alternative of simple "xxx.split(os.sep)". |
1379 It is recommended to use os.path.normpath() before using this | 1380 It is recommended to use os.path.normpath() before using this |
1380 function if need.''' | 1381 function if need.''' |
1381 return path.split(os.sep) | 1382 return path.split(pycompat.ossep) |
1382 | 1383 |
1383 def gui(): | 1384 def gui(): |
1384 '''Are we running in a GUI?''' | 1385 '''Are we running in a GUI?''' |
1385 if sys.platform == 'darwin': | 1386 if sys.platform == 'darwin': |
1386 if 'SSH_CONNECTION' in os.environ: | 1387 if 'SSH_CONNECTION' in os.environ: |