[PATCH 00/17] nmbug-status: Python-3-compabitility and general refactoring

Tomi Ollila tomi.ollila at iki.fi
Tue Feb 4 12:06:01 PST 2014


On Tue, Feb 04 2014, "W. Trevor King" <wking at tremily.us> wrote:

>> 
>> I don't know what to paste, so i paste this:
>> 
>> $ python
>> Python 2.6.6 (r266:84292, Nov 21 2013, 12:39:37) 
>> [GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
>> Type "help", "copyright", "credits" or "license" for more information.
>
> It looks like you left out:
>
>   from __future__ import unicode_literals
>
> Can you try again with that line as the first command?
>
>> >>> data = {'from': '\u017b'}
>> >>> print(type(data['from'])) 
>> <type 'str'>
>
> which is why your data is a 'str' and not a 'unicode' instance.
>
>> >>> string = '  <td>{from}</td>\n'.format(**data)
>> >>> print string
>>   <td>\u017b</td>

Quick update before getting to sleep:

$ python 
Python 2.6.6 (r266:84292, Nov 21 2013, 12:39:37) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from __future__ import print_function
>>> from __future__ import unicode_literals
>>> data = {'from': '\u017b'}
>>> print(type(data['from']))
<type 'unicode'>
>>> string = '  <td>{from}</td>\n'.format(**data)
>>> print(string)
  <td>Ż</td>

so getting success there

$ PYTHONPATH=$PWD/bindings/python/ ./devel/nmbug/nmbug-status
...
Traceback (most recent call last):
  File "devel/nmbug/nmbug-status", line 318, in <module>
    page.write(database=db, views=config['views'])
  File "devel/nmbug/nmbug-status", line 94, in write
    self._write_view(database=database, view=view, stream=stream)
  File "devel/nmbug/nmbug-status", line 113, in _write_view
    self._write_threads(threads=threads, stream=stream)
  File "devel/nmbug/nmbug-status", line 215, in _write_threads
    ).format(**message_display_data))
  File "/usr/lib64/python2.6/codecs.py", line 351, in write
    data, consumed = self.encode(object, self.errors)
UnicodeEncodeError: 'ascii' codec can't encode character u'\u017b' in
position 176: ordinal not in range(128)


I'll dig deeper tomorrow.


Tomi


More information about the notmuch mailing list