You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The quopri module conditionally imports binascii and uses custom code if binascii can't be found. For example, the encode() function currently has 60 lines (including empty lines and the docstring), of which only 47 lines are dedicated to the workaround:
# RFC 1521 requires that the line ending in a space or tab must have
# that trailing character encoded.
ifsands[-1:] inb' \t':
output.write(s[:-1] +quote(s[-1:]) +lineEnd)
elifs==b'.':
output.write(quote(s) +lineEnd)
else:
output.write(s+lineEnd)
prevline=None
while1:
line=input.readline()
ifnotline:
break
outline= []
# Strip off any readline induced trailing newline
stripped=b''
ifline[-1:] ==b'\n':
line=line[:-1]
stripped=b'\n'
# Calculate the un-length-limited encoded line
forcinline:
c=bytes((c,))
ifneedsquoting(c, quotetabs, header):
c=quote(c)
ifheaderandc==b' ':
outline.append(b'_')
else:
outline.append(c)
# First, write out the previous line
ifprevlineisnotNone:
write(prevline)
# Now see if we need any soft line breaks because of RFC-imposed
# length limitations. Then do the thisline->prevline dance.
thisline=EMPTYSTRING.join(outline)
whilelen(thisline) >MAXLINESIZE:
# Don't forget to include the soft line break `=' sign in the
# length calculation!
write(thisline[:MAXLINESIZE-1], lineEnd=b'=\n')
thisline=thisline[MAXLINESIZE-1:]
# Write out the current line
prevline=thisline
# Write out the last line, without a trailing newline
ifprevlineisnotNone:
write(prevline, lineEnd=stripped)
This is essentially dead code, since I don't think there are any (sane) scenarios nowadays, where binascii is not available. I recommend to remove the conditional import and dead code. I'm willing to write a PR.
Your environment
CPython versions tested on: Seen on cpython HEAD as of 2022-11-03
The text was updated successfully, but these errors were encountered:
This is essentially dead code, since I don't think there are any (sane) scenarios nowadays, where binascii is not available
No, some of the alternative implementations use the CPython library directly, and some of them don't have the implementation for binsacii, I would like to maintain the code as-is.
Possible Refactoring
The
quopri
module conditionally importsbinascii
and uses custom code ifbinascii
can't be found. For example, theencode()
function currently has 60 lines (including empty lines and the docstring), of which only 47 lines are dedicated to the workaround:cpython/Lib/quopri.py
Lines 44 to 104 in e9ac890
This is essentially dead code, since I don't think there are any (sane) scenarios nowadays, where
binascii
is not available. I recommend to remove the conditional import and dead code. I'm willing to write a PR.Your environment
The text was updated successfully, but these errors were encountered: