binascii: Implement newline param in function b2a_base64.

See: https://docs.python.org/3/library/binascii.html#binascii.b2a_base64
pull/502/head
Diefesson de Sousa SIlva 2020-10-05 16:50:55 -03:00 zatwierdzone przez Damien George
rodzic e7e8eff86b
commit be327a7bc7
1 zmienionych plików z 3 dodań i 2 usunięć

Wyświetl plik

@ -331,7 +331,7 @@ def a2b_base64(ascii):
table_b2a_base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" table_b2a_base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
def b2a_base64(bin): def b2a_base64(bin, newline=True):
"Base64-code line of data." "Base64-code line of data."
newlength = (len(bin) + 2) // 3 newlength = (len(bin) + 2) // 3
@ -357,5 +357,6 @@ def b2a_base64(bin):
elif leftbits == 4: elif leftbits == 4:
res.append(table_b2a_base64[(leftchar & 0xF) << 2]) res.append(table_b2a_base64[(leftchar & 0xF) << 2])
res.append(PAD) res.append(PAD)
res.append("\n") if newline:
res.append("\n")
return "".join(res).encode("ascii") return "".join(res).encode("ascii")