[Python-ideas] Chaining coders

Soni L. fakedme+py at gmail.com
Fri Jan 19 17:08:29 EST 2018

windows-1252 is based on iso-8859-1. Thus, I'd like to be able to chain 
coders as follows:

bytes.decode("windows-1252-ext", else=lambda r: r.decode("iso-8859-1"))

What this "else" does is that it's a lambda, and it gets passed an 
object with a decode method identical to the bytes decode method, except 
that it doesn't affect already-decoded characters. In this case, 
"windows-1252-ext" only includes things in the \x80-\x9F range, leaving 
it up to "iso-8859-1" to handle the rest.

A similar process would happen for encoding: encode with 
"windows-1252-ext", else = "iso-8859-1".

(Technically, "windows-1252-ext" isn't needed - you can use the existing 
"windows-1252" and combine it with the "iso-8859-1" to get 

This would be a novel way to think of encodings as not just flat 
translation tables but highly composable translation tables. I have a 
thing for composition.

More information about the Python-ideas mailing list