[PATCH 2 of 4] py3: make os.pardir a bytes

Yuya Nishihara yuya at tcha.org
Sat Mar 3 14:38:13 EST 2018


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1520098475 18000
#      Sat Mar 03 12:34:35 2018 -0500
# Node ID e6c7422051775cd8c5e50f77b2bdd5a399cb9342
# Parent  fd2dba485a2af4f3de5ce0c3b7d8c9690115c4bd
py3: make os.pardir a bytes

diff --git a/mercurial/hgweb/common.py b/mercurial/hgweb/common.py
--- a/mercurial/hgweb/common.py
+++ b/mercurial/hgweb/common.py
@@ -138,7 +138,7 @@ def ispathsafe(path):
     """Determine if a path is safe to use for filesystem access."""
     parts = path.split('/')
     for part in parts:
-        if (part in ('', os.curdir, os.pardir) or
+        if (part in ('', os.curdir, pycompat.ospardir) or
             pycompat.ossep in part or
             pycompat.osaltsep is not None and pycompat.osaltsep in part):
             return False
diff --git a/mercurial/pathutil.py b/mercurial/pathutil.py
--- a/mercurial/pathutil.py
+++ b/mercurial/pathutil.py
@@ -65,7 +65,7 @@ class pathauditor(object):
         parts = util.splitpath(path)
         if (os.path.splitdrive(path)[0]
             or _lowerclean(parts[0]) in ('.hg', '.hg.', '')
-            or os.pardir in parts):
+            or pycompat.ospardir in parts):
             raise error.Abort(_("path contains illegal component: %s") % path)
         # Windows shortname aliases
         for p in parts:
diff --git a/mercurial/pycompat.py b/mercurial/pycompat.py
--- a/mercurial/pycompat.py
+++ b/mercurial/pycompat.py
@@ -51,6 +51,7 @@ if ispy3:
     oslinesep = os.linesep.encode('ascii')
     osname = os.name.encode('ascii')
     ospathsep = os.pathsep.encode('ascii')
+    ospardir = os.pardir.encode('ascii')
     ossep = os.sep.encode('ascii')
     osaltsep = os.altsep
     if osaltsep:
@@ -323,6 +324,7 @@ else:
     oslinesep = os.linesep
     osname = os.name
     ospathsep = os.pathsep
+    ospardir = os.pardir
     ossep = os.sep
     osaltsep = os.altsep
     stdin = sys.stdin
diff --git a/mercurial/templater.py b/mercurial/templater.py
--- a/mercurial/templater.py
+++ b/mercurial/templater.py
@@ -1600,7 +1600,7 @@ def stylemap(styles, paths=None):
     for style in styles:
         # only plain name is allowed to honor template paths
         if (not style
-            or style in (os.curdir, os.pardir)
+            or style in (os.curdir, pycompat.ospardir)
             or pycompat.ossep in style
             or pycompat.osaltsep and pycompat.osaltsep in style):
             continue


More information about the Mercurial-devel mailing list