Merge lp:~a1s/brz/3.2-windows-separators into lp:brz/3.2

Proposed by Aleksandr Smyshliaev
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: no longer in the source branch.
Merge reported by: The Breezy Bot
Merged at revision: not available
Proposed branch: lp:~a1s/brz/3.2-windows-separators
Merge into: lp:brz/3.2
Diff against target: 47 lines (+12/-6)
1 file modified
breezy/osutils.py (+12/-6)
To merge this branch: bzr merge lp:~a1s/brz/3.2-windows-separators
Reviewer Review Type Date Requested Status
Jelmer Vernooij Approve
Review via email: mp+411935@code.launchpad.net

Commit message

Let osutils path functions on Windows accept byte strings as well as unicode strings

Description of the change

As far as I understand, Breezy hasn't decided yet if file paths should be byte strings or Unicode strings. A lot of calls to osutils functions pass byte strings, but the regression tests use mostly Unicode strings.

This change makes osutils accept both bytes and strings, just as posixpath and ntpath from the Standard Library do.

To post a comment you must log in.
Revision history for this message
Jelmer Vernooij (jelmer) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'breezy/osutils.py'
2--- breezy/osutils.py 2020-07-18 23:14:00 +0000
3+++ breezy/osutils.py 2021-11-16 16:14:23 +0000
4@@ -335,31 +335,37 @@
5 drive, path = ntpath.splitdrive(path)
6 return drive.upper() + path
7
8+def _win32_fix_separators(path):
9+ """Return path with directory separators changed to forward slashes"""
10+ if isinstance(path, bytes):
11+ return path.replace(b'\\', b'/')
12+ else:
13+ return path.replace('\\', '/')
14
15 def _win32_abspath(path):
16 # Real ntpath.abspath doesn't have a problem with a unicode cwd
17- return _win32_fixdrive(ntpath.abspath(path).replace('\\', '/'))
18+ return _win32_fixdrive(_win32_fix_separators(ntpath.abspath(path)))
19
20
21 def _win32_realpath(path):
22 # Real ntpath.realpath doesn't have a problem with a unicode cwd
23- return _win32_fixdrive(ntpath.realpath(path).replace('\\', '/'))
24+ return _win32_fixdrive(_win32_fix_separators(ntpath.realpath(path)))
25
26
27 def _win32_pathjoin(*args):
28- return ntpath.join(*args).replace('\\', '/')
29+ return _win32_fix_separators(ntpath.join(*args))
30
31
32 def _win32_normpath(path):
33- return _win32_fixdrive(ntpath.normpath(path).replace('\\', '/'))
34+ return _win32_fixdrive(_win32_fix_separators(ntpath.normpath(path)))
35
36
37 def _win32_getcwd():
38- return _win32_fixdrive(_getcwd().replace('\\', '/'))
39+ return _win32_fixdrive(_win32_fix_separators(_getcwd()))
40
41
42 def _win32_mkdtemp(*args, **kwargs):
43- return _win32_fixdrive(tempfile.mkdtemp(*args, **kwargs).replace('\\', '/'))
44+ return _win32_fixdrive(_win32_fix_separators(tempfile.mkdtemp(*args, **kwargs)))
45
46
47 def _win32_rename(old, new):

Subscribers

People subscribed via source and target branches