Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
a3a01b6a
Commit
a3a01b6a
authored
Jan 11, 2013
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #15539: Fix a backup file creation in pindent.py on Windows.
parent
5e12bb72
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
12 deletions
+21
-12
Lib/test/test_tools.py
Lib/test/test_tools.py
+1
-0
Tools/scripts/pindent.py
Tools/scripts/pindent.py
+20
-12
No files found.
Lib/test/test_tools.py
View file @
a3a01b6a
...
...
@@ -58,6 +58,7 @@ class PindentTests(unittest.TestCase):
return
'
\
n
'
.
join
(
line
.
lstrip
()
for
line
in
data
.
splitlines
())
+
'
\
n
'
def
test_selftest
(
self
):
self
.
maxDiff
=
None
with
temp_dir
()
as
directory
:
data_path
=
os
.
path
.
join
(
directory
,
'_test.py'
)
with
open
(
self
.
script
)
as
f
:
...
...
Tools/scripts/pindent.py
View file @
a3a01b6a
...
...
@@ -370,6 +370,23 @@ def reformat_string(source, stepsize = STEPSIZE, tabsize = TABSIZE, expandtabs =
return
output
.
getvalue
()
# end def reformat_string
def
make_backup
(
filename
):
import
os
,
os
.
path
backup
=
filename
+
'~'
if
os
.
path
.
lexists
(
backup
):
try
:
os
.
remove
(
backup
)
except
os
.
error
:
print
(
"Can't remove backup %r"
%
(
backup
,),
file
=
sys
.
stderr
)
# end try
# end if
try
:
os
.
rename
(
filename
,
backup
)
except
os
.
error
:
print
(
"Can't rename %r to %r"
%
(
filename
,
backup
),
file
=
sys
.
stderr
)
# end try
# end def make_backup
def
complete_file
(
filename
,
stepsize
=
STEPSIZE
,
tabsize
=
TABSIZE
,
expandtabs
=
EXPANDTABS
):
with
open
(
filename
,
'r'
)
as
f
:
source
=
f
.
read
()
...
...
@@ -377,10 +394,7 @@ def complete_file(filename, stepsize = STEPSIZE, tabsize = TABSIZE, expandtabs =
result
=
complete_string
(
source
,
stepsize
,
tabsize
,
expandtabs
)
if
source
==
result
:
return
0
# end if
import
os
try
:
os
.
rename
(
filename
,
filename
+
'~'
)
except
os
.
error
:
pass
# end try
make_backup
(
filename
)
with
open
(
filename
,
'w'
)
as
f
:
f
.
write
(
result
)
# end with
...
...
@@ -394,10 +408,7 @@ def delete_file(filename, stepsize = STEPSIZE, tabsize = TABSIZE, expandtabs = E
result
=
delete_string
(
source
,
stepsize
,
tabsize
,
expandtabs
)
if
source
==
result
:
return
0
# end if
import
os
try
:
os
.
rename
(
filename
,
filename
+
'~'
)
except
os
.
error
:
pass
# end try
make_backup
(
filename
)
with
open
(
filename
,
'w'
)
as
f
:
f
.
write
(
result
)
# end with
...
...
@@ -411,10 +422,7 @@ def reformat_file(filename, stepsize = STEPSIZE, tabsize = TABSIZE, expandtabs =
result
=
reformat_string
(
source
,
stepsize
,
tabsize
,
expandtabs
)
if
source
==
result
:
return
0
# end if
import
os
try
:
os
.
rename
(
filename
,
filename
+
'~'
)
except
os
.
error
:
pass
# end try
make_backup
(
filename
)
with
open
(
filename
,
'w'
)
as
f
:
f
.
write
(
result
)
# end with
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment