GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Support multiline output in binascii.b2a_base64() and base64.b64encode() · Issue #143214 · python/cpython

Support multiline output in binascii.b2a_base64() and base64.b64encode() #143214

New issue
Copy link
New issue
Copy link
Closed
Closed
Support multiline output in binascii.b2a_base64() and base64.b64encode()#143214
Copy link
Assignees
serhiy-storchaka
Labels
3.15bugs and security fixesbugs and security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement

Description

@serhiy-storchaka
serhiy-storchaka
opened on Dec 27, 2025
Issue body actions

Feature or enhancement

According to RFC 4648, section 3.1:

Implementations MUST NOT add line feeds to base-encoded data unless
the specification referring to this document explicitly directs base
encoders to add line feeds after a specific number of characters.

But many specifications use Base 64 separated on lines of fixed length. The stdlib code contains multiple functions that take the Base 64 data and split it on multiple lines. It is worth to add a special support of this in the base functions that encode to Base 64 -- to improve maintenability (there is a known bug in email.base64mime.body_encode()), convenience and performance.

I choose name wrapcol for the parameter because it is already used in base64.a85encode(). Other (mostly private) functions that implement the Base 64 wrapping use different names: maxlinelen, maxlen, max_line_length. PR #102753 propose name width for binascii.b2a_ascii85() (it is also used in textwrap). So there is no consistency or single dominant option, but I am open for suggestions.

Linked PRs

  • gh-143214: Add the wrapcol parameter in binascii.b2a_base64() and base64.b64encode() #143216

Activity

  1. serhiy-storchaka
    self-assigned this
    on Dec 27, 2025
  2. serhiy-storchaka
    added
    type-featureA feature request or enhancementA feature request or enhancement
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    3.15bugs and security fixesbugs and security fixes
    on Dec 27, 2025
  3. serhiy-storchaka
    added a commit that references this issue on Dec 27, 2025

    pythongh-143214: Add the wrapcol parameter in binascii.b2a_base64() a…

    b7196ba
  4. picnixz commented on Dec 27, 2025

    @picnixz
    picnixz
    on Dec 27, 2025
    Member
    More actions

    Usually I like parameters with short names because I don't need to wrap lines if I exceed the max line length. Ideally, I would have an explanatory name like "max_line_length", but I think wrapcol or maxcols is good. Note that the Unix base64 util uses --wrap=COLS for wrapping the output while xxd uses -c cols for wrapping. So including the notion of a "colunn" instead of of line/width seems better to me. Thus, I'm inclined to "colwrap=..." (instead of wrapcol), then "maxcols", and "width" for parity with textwrap (which may also be a strong argument for).

  5. cmaloney commented on Dec 27, 2025

    @cmaloney
    cmaloney
    on Dec 27, 2025
    Contributor
    More actions

    This is similar to gh-141966; wrapcol works as a name for me. Happy for this issue to implement/ship. Ideally this should be usable for the cases in base64, email.contentmanager, imaplib, and plistlib.

  6. serhiy-storchaka commented on Dec 27, 2025

    @serhiy-storchaka
    serhiy-storchaka
    on Dec 27, 2025
    MemberAuthor
    More actions

    Oh, I searched for base64 issues, but missed your issue at the top of the list due to my sight condition.

    Yes, #143216 utilizes the new argument in all these modules.

    Reacted by Cody Maloney
  7. cmaloney
    marked Add bytes_per_line parameter to binascii.b2a_base64 #141966 as a duplicate of this issue on Dec 27, 2025
  8. serhiy-storchaka commented on Dec 27, 2025

    @serhiy-storchaka
    serhiy-storchaka
    on Dec 27, 2025
    MemberAuthor
    More actions

    Oh, it is binascii.b2a_hex() that have a bytes_per_sep parameter with weird semantic. Anyway, it is not usable for Base 64 and other encodings which encode a byte in non-integer number of characters. Is is also not usable for Ascii 85 with variable characters-per-byte ratio. Control the number of characters per line in the output is more practical.

    Reacted by Cody Maloney
  9. serhiy-storchaka
    added a commit that references this issue on Jan 14, 2026

    gh-143214: Add the wrapcol parameter in binascii.b2a_base64() and bas…

    a471a32
  10. serhiy-storchaka
    closed this as completedon Jan 14, 2026
  11. thunder-coding
    added a commit that references this issue on Feb 15, 2026

    pythongh-143214: Add the wrapcol parameter in binascii.b2a_base64() a…

    abd5771
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @serhiy-storchaka
    serhiy-storchaka

Labels

3.15bugs and security fixesbugs and security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-featureA feature request or enhancementA feature request or enhancement

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.