Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.1k
Description
Feature or enhancement
This module is quite old, it uses a conditional import ofbinascii
since times when it was possible to not have it whenzlib
was missing:
Lines 12 to 17 in13cb8ca
try: | |
frombinasciiimporta2b_qp,b2a_qp | |
exceptImportError: | |
a2b_qp=None | |
b2a_qp=None | |
However, right now it is always available under all python implementations (like RustPython and PyPy).

So, we can simplify the implementation and remove a lot of duplicated code, example:
Lines 51 to 99 in13cb8ca
ifb2a_qpisnotNone: | |
data=input.read() | |
odata=b2a_qp(data,quotetabs=quotetabs,header=header) | |
output.write(odata) | |
return | |
defwrite(s,output=output,lineEnd=b'\n'): | |
# 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 | |
whileline:=input.readline(): | |
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) |
There are also several helper functions with public names, which are not in__all__
which will be unused after this. We can keep them and deprecate their use.
Sincebinascii
is always available, python implementation is never used anyway.
So, the main pro:
- We can remove some dead code
There are several cons to my proposal:
- There are no real user reported problems
- The module is old and stable
- It does not require a lot of maintaince
I will open a draft PR, so people can see the amount of changes and decide better with that.
Should we do this?