mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
bpo-30103: Allow Uuencode in Python using backtick as zero instead of space (#1326)
This commit is contained in:
parent
0360a9d015
commit
13f1f423fa
10 changed files with 137 additions and 67 deletions
13
Lib/uu.py
13
Lib/uu.py
|
@ -26,8 +26,8 @@
|
|||
|
||||
"""Implementation of the UUencode and UUdecode functions.
|
||||
|
||||
encode(in_file, out_file [,name, mode])
|
||||
decode(in_file [, out_file, mode])
|
||||
encode(in_file, out_file [,name, mode], *, backtick=False)
|
||||
decode(in_file [, out_file, mode, quiet])
|
||||
"""
|
||||
|
||||
import binascii
|
||||
|
@ -39,7 +39,7 @@ __all__ = ["Error", "encode", "decode"]
|
|||
class Error(Exception):
|
||||
pass
|
||||
|
||||
def encode(in_file, out_file, name=None, mode=None):
|
||||
def encode(in_file, out_file, name=None, mode=None, *, backtick=False):
|
||||
"""Uuencode file"""
|
||||
#
|
||||
# If in_file is a pathname open it and change defaults
|
||||
|
@ -79,9 +79,12 @@ def encode(in_file, out_file, name=None, mode=None):
|
|||
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))
|
||||
out_file.write(binascii.b2a_uu(data, backtick=backtick))
|
||||
data = in_file.read(45)
|
||||
out_file.write(b' \nend\n')
|
||||
if backtick:
|
||||
out_file.write(b'`\nend\n')
|
||||
else:
|
||||
out_file.write(b' \nend\n')
|
||||
finally:
|
||||
for f in opened_files:
|
||||
f.close()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue