Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d2b2e53

Browse files
committed
header_encode(), encode(): Use _floordiv() from the appropriate
compatibility module.
1 parent 21f77ac commit d2b2e53

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

Lib/email/base64MIME.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@
2727
from binascii import b2a_base64, a2b_base64
2828
from email.Utils import fix_eols
2929

30+
try:
31+
from email._compat22 import _floordiv
32+
except SyntaxError:
33+
# Python 2.1 spells integer division differently
34+
from email._compat21 import _floordiv
35+
36+
3037
CRLF = '\r\n'
3138
NL = '\n'
3239
EMPTYSTRING = ''
@@ -87,7 +94,7 @@ def header_encode(header, charset='iso-8859-1', keep_eols=0, maxlinelen=76,
8794
# length, after the RFC chrome is added in.
8895
base64ed = []
8996
max_encoded = maxlinelen - len(charset) - MISC_LEN
90-
max_unencoded = max_encoded * 3 // 4
97+
max_unencoded = _floordiv(max_encoded * 3, 4)
9198

9299
# BAW: Ben's original code used a step of max_unencoded, but I think it
93100
# ought to be max_encoded. Otherwise, where's max_encoded used? I'm
@@ -131,7 +138,7 @@ def encode(s, binary=1, maxlinelen=76, eol=NL):
131138
s = fix_eols(s)
132139

133140
encvec = []
134-
max_unencoded = maxlinelen * 3 // 4
141+
max_unencoded = _floordiv(maxlinelen * 3, 4)
135142
for i in range(0, len(s), max_unencoded):
136143
# BAW: should encode() inherit b2a_base64()'s dubious behavior in
137144
# adding a newline to the encoded string?

0 commit comments

Comments
 (0)