mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #49708 from rallytime/bp-49555
Back-port #49555 to 2018.3
This commit is contained in:
commit
b082f79fcb
1 changed files with 6 additions and 5 deletions
|
@ -17,9 +17,10 @@ import salt.utils.hashutils
|
|||
import salt.utils.stringutils
|
||||
|
||||
if six.PY2:
|
||||
import StringIO
|
||||
from StringIO import StringIO
|
||||
BytesIO = StringIO
|
||||
elif six.PY3:
|
||||
from io import StringIO
|
||||
from io import BytesIO, StringIO
|
||||
|
||||
|
||||
def digest(instr, checksum='md5'):
|
||||
|
@ -155,13 +156,13 @@ def base64_encodefile(fname):
|
|||
|
||||
salt '*' hashutil.base64_encodefile /path/to/binary_file
|
||||
'''
|
||||
encoded_f = StringIO.StringIO()
|
||||
encoded_f = BytesIO()
|
||||
|
||||
with salt.utils.files.fopen(fname, 'rb') as f:
|
||||
base64.encode(f, encoded_f)
|
||||
|
||||
encoded_f.seek(0)
|
||||
return encoded_f.read()
|
||||
return salt.utils.stringutils.to_str(encoded_f.read())
|
||||
|
||||
|
||||
def base64_decodestring(instr):
|
||||
|
@ -192,7 +193,7 @@ def base64_decodefile(instr, outfile):
|
|||
|
||||
salt '*' hashutil.base64_decodefile instr='Z2V0IHNhbHRlZAo=' outfile='/path/to/binary_file'
|
||||
'''
|
||||
encoded_f = StringIO.StringIO(instr)
|
||||
encoded_f = StringIO(instr)
|
||||
|
||||
with salt.utils.files.fopen(outfile, 'wb') as f:
|
||||
base64.decode(encoded_f, f)
|
||||
|
|
Loading…
Add table
Reference in a new issue