From 5e397b19285565ef7390094c6bd8ebe9544054e7 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Mon, 20 Jan 2020 21:49:14 -0800 Subject: [PATCH] Simplify normalize_sep. --- voussoirkit/pathclass.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/voussoirkit/pathclass.py b/voussoirkit/pathclass.py index 2d1d001..3a9304e 100644 --- a/voussoirkit/pathclass.py +++ b/voussoirkit/pathclass.py @@ -35,7 +35,7 @@ class Path: path = os.path.abspath(path) self.absolute_path = path - self.absolute_path = self.absolute_path.replace('/', self.sep).replace('\\', self.sep) + self.absolute_path = normalize_sep(self.absolute_path, self.sep) def __contains__(self, other): other = Path(other, force_sep=self.force_sep) @@ -307,10 +307,11 @@ def glob_patternize(piece): break return piece -def normalize_sep(path): - for char in ('\\', '/'): - if char != os.sep: - path = path.replace(char, os.sep) +def normalize_sep(path, sep=None): + sep = sep or os.sep + path = path.replace('/', sep) + path = path.replace('\\', sep) + return path def system_root():