Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

quopri uses conditionalbinascii import, when it is always available #133896

Open
Assignees
sobolevn
Labels
stdlibPython modules in the Lib dirtype-featureA feature request or enhancement
@sobolevn

Description

@sobolevn

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:

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).

Image

So, we can simplify the implementation and remove a lot of duplicated code, example:

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?

Linked PRs

Metadata

Metadata

Assignees

Labels

stdlibPython modules in the Lib dirtype-featureA feature request or enhancement

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp