brendonh / pyth

Python text markup and conversion
MIT License
89 stars 79 forks source link

Fix codecs search function to only match 'symbol' #22

Closed somakrdas closed 10 years ago

somakrdas commented 10 years ago

The current search function matches all encodings, which break other packages that use the codecs registry like cssutils. According to the codecs documentation:

In case a search function cannot find a given encoding, it should return None.

This pull request fixes the search function to only match 'symbol'.

Before:

>>> from pyth.plugins.rtf15.reader import Rtf15Reader
>>> import codecs
>>> print codecs.getdecoder('symbol')
<function symbol_decode at 0x109774140>
>>> print codecs.getdecoder('<some_encoding>')
<function symbol_decode at 0x109774140>

After:

>>> from pyth.plugins.rtf15.reader import Rtf15Reader
>>> import codecs
>>> print codecs.getdecoder('symbol')
<function symbol_decode at 0x1043b3140>
>>> print codecs.getdecoder('<some_encoding>')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/somakrdas/.envs/work/lib/python2.7/codecs.py", line 946, in getdecoder
    return lookup(encoding).decode
LookupError: unknown encoding: <some_encoding>
somakrdas commented 10 years ago

@brendonh, could you take a look and, when possible, release to PyPI? (pyth still conflicts with other packages that use codecs for us.)

brendonh commented 10 years ago

Seems reasonable!

somakrdas commented 10 years ago

Great, thanks!