mutt_ldap.py: Add an output-encoding option
This avoids crashing with:
UnicodeEncodeError: 'ascii' codec can't encode characters
when mutt_ldap.py's stdout is not connected to a terminal (and
therefore doesn't have sys.stdout.encodign set up).
$ python2.7 -c "print(u'α')" | cat
Traceback (most recent call last):
File "<string>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode characters in
position 0-1: ordinal not in range(128)
$ python2.7 -c 'import sys; print(sys.stdout.encoding)'
UTF-8
$ python2.7 -c 'import sys; print(sys.stdout.encoding)' | cat
None
$ python3.2 -c "print('α')" | cat
α
$ python3.2 -c 'import sys; print(sys.stdout.encoding)'
UTF-8
$ python3.2 -c 'import sys; print(sys.stdout.encoding)' | cat
UTF-8
Both settings should match the value of the Mutt configuration
variable $charset [1,2]:
On Thu, Jan 24, 2013 at 06:25:24PM +0000, Michael Elkins wrote:
> On Thu, Jan 24, 2013 at 12:36:02PM -0500, W. Trevor King wrote:
> > I have a script that queries for address completion using the
> > query_command setting, but the docs are silent on the encoding for
> > the arguments and expected output [1]. ...
>
> It expects the output to be in the same encoding as $charset.
> Mutt performs the RFC2047 encoding automatically.
On Thu, Jan 24, 2013 at 07:00:53PM +0000, Michael Elkins wrote:
> On Thu, Jan 24, 2013 at 01:42:34PM -0500, W. Trevor King wrote:
> > ...Is it also $charset for the argv input?
>
> Yes.
If you don't specify a $charset in your Mutt config, you can probably
get away with not specifying charsets for these config options,
because Mutt's default charset detection will likely match up with
Python's locale.getpreferredencoding().
[1]: http://marc.info/?l=mutt-dev&m=
135905197022081&w=2
[2]: http://marc.info/?l=mutt-dev&m=
135905407723082&w=2