On Tue, May 19, 2020 at 8:43 PM Cameron Simpson <cs@cskk.id.au> wrote:
>salt = salt.rstrip("=", maxstrip=2)
>assert not salt.endswith("=")

Reiterating the Python 3.9 suggestion, what about:

  salt2 = salt.cutsuffix(('==', '='))

You'd have to call cutsuffix twice.  Valid base64 might end in one, two, or zero '=', but the result wants to have none.  Actually, no... even two calls won't always do the right thing.  I'm happy to have the new method .cutsuffix() , but I don't think it addresses this case.

I was going to suggest an example about dynamically built path components that may or may not end in '/'.  However:

A. I couldn't find an example in my own code easily, even though I know I've fiddled with that
B. Someone would scold me for playing with strings rather than using Pathlib (they'd be right, I realize... but I am sinful in my quick-script ways).

I'll let someone else, like the OP, advance the case more.  I kinda like it, but it's not a big deal for me.

--
The dead increasingly dominate and strangle both the living and the
not-yet born.  Vampiric capital and undead corporate persons abuse
the lives and control the thoughts of homo faber. Ideas, once born,
become abortifacients against new conceptions.