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
bfa3470b
Commit
bfa3470b
authored
Oct 30, 2010
by
Antoine Pitrou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #10246: uu.encode didn't close file objects explicitly when filenames
were given to it. Patch by Brian Brazil.
parent
b046b807
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
31 deletions
+41
-31
Lib/uu.py
Lib/uu.py
+38
-31
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/uu.py
View file @
bfa3470b
...
...
@@ -44,40 +44,47 @@ def encode(in_file, out_file, name=None, mode=None):
#
# If in_file is a pathname open it and change defaults
#
if
in_file
==
'-'
:
in_file
=
sys
.
stdin
.
buffer
elif
isinstance
(
in_file
,
str
):
opened_files
=
[]
try
:
if
in_file
==
'-'
:
in_file
=
sys
.
stdin
.
buffer
elif
isinstance
(
in_file
,
str
):
if
name
is
None
:
name
=
os
.
path
.
basename
(
in_file
)
if
mode
is
None
:
try
:
mode
=
os
.
stat
(
in_file
).
st_mode
except
AttributeError
:
pass
in_file
=
open
(
in_file
,
'rb'
)
opened_files
.
append
(
in_file
)
#
# Open out_file if it is a pathname
#
if
out_file
==
'-'
:
out_file
=
sys
.
stdout
.
buffer
elif
isinstance
(
out_file
,
str
):
out_file
=
open
(
out_file
,
'wb'
)
opened_files
.
append
(
out_file
)
#
# Set defaults for name and mode
#
if
name
is
None
:
name
=
os
.
path
.
basename
(
in_file
)
name
=
'-'
if
mode
is
None
:
try
:
mode
=
os
.
stat
(
in_file
).
st_mode
except
AttributeError
:
pass
in_file
=
open
(
in_file
,
'rb'
)
#
# Open out_file if it is a pathname
#
if
out_file
==
'-'
:
out_file
=
sys
.
stdout
.
buffer
elif
isinstance
(
out_file
,
str
):
out_file
=
open
(
out_file
,
'wb'
)
#
# Set defaults for name and mode
#
if
name
is
None
:
name
=
'-'
if
mode
is
None
:
mode
=
0o666
#
# Write the data
#
out_file
.
write
((
'begin %o %s
\
n
'
%
((
mode
&
0o777
),
name
)).
encode
(
"ascii"
))
data
=
in_file
.
read
(
45
)
while
len
(
data
)
>
0
:
out_file
.
write
(
binascii
.
b2a_uu
(
data
))
mode
=
0o666
#
# Write the data
#
out_file
.
write
((
'begin %o %s
\
n
'
%
((
mode
&
0o777
),
name
)).
encode
(
"ascii"
))
data
=
in_file
.
read
(
45
)
out_file
.
write
(
b'
\
n
end
\
n
'
)
while
len
(
data
)
>
0
:
out_file
.
write
(
binascii
.
b2a_uu
(
data
))
data
=
in_file
.
read
(
45
)
out_file
.
write
(
b'
\
n
end
\
n
'
)
finally
:
for
f
in
opened_files
:
f
.
close
()
def
decode
(
in_file
,
out_file
=
None
,
mode
=
None
,
quiet
=
False
):
...
...
Misc/NEWS
View file @
bfa3470b
...
...
@@ -57,6 +57,9 @@ Core and Builtins
Library
-------
- Issue #10246: uu.encode didn't close file objects explicitly when filenames
were given to it. Patch by Brian Brazil.
- Issue #10198: fix duplicate header written to wave files when writeframes()
is called without data.
...
...
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