Issue #1 resolved

Hachoir Metadata and ipython

Nicolas Vandamme
created an issue

Hi,

It seems there is a bug wih ipython and hachoir_metadata. When I import hachoir_metadata within ipython shell, all directionals keys are not catched anymore (the shell is printing there key codes instead).

In [3]: import hachoir_metadata

In [4]: ^[[A^[[A^[[C^[[C^[[C^[[C^C

Anyways thanks for this very usefull lib.

Bye

Comments (6)

  1. Anonymous

    The problem comes from hachoir_core.i18n which replaces sys.stdout and sys.stderr by an unicode friendly files. It's possible to disable that by setting hachoir_core.config.unicode_stdout *before* loading any hachoir module. Eg.

    from hachoir_core import config
    config.unicode_stdout = False
    from hachoir_metadata import ...   # depends on hachoir_core.i18n
    

    The unicode hack is required to avoid encoding bugs when printing unicode characters like japanese.

    I should add a test to check if readline is used or not, or if sys.stdout is a tty, or... i don't know :-/

  2. Anonymous

    Oh, I just realized that the issue is not assigned to the right project! This is the Fusil bug tracker, not the Hachoir project :-)

  3. Nicolas Vandamme reporter

    Hi,

    If i use your tip, i get the following errors on hahoir_metadata import:

    In [1]: import hachoir_core.config
    
    In [2]: hachoir_core.config.unicode_stdout = False
    
    In [3]: import hachoir_metadata
    ---------------------------------------------------------------------------
    LookupError                               Traceback (most recent call last)
    
    /Users/nvandamme/Workspace/pylons/domocore/<ipython console> in <module>()
    
    /Users/nvandamme/Workspace/pylons/domocore/build/bdist.macosx-10.5-i386/egg/hachoir_metadata/__init__.py in <module>()
    ----> 2 """This directory is meant for special-purpose extensions to IPython.
          3 
          4 This can include things which alter the syntax processing stage (see
          5 PhysicalQ_Input for an example of how to do this).
          6 
    
    /Users/nvandamme/Workspace/pylons/domocore/build/bdist.macosx-10.5-i386/egg/hachoir_metadata/metadata.py in <module>()
    
    /Users/nvandamme/Workspace/pylons/lib/python2.5/site-packages/hachoir_core-1.2.1-py2.5.egg/hachoir_core/endian.py in <module>()
         10 
         11 endian_name = {
    ---> 12     BIG_ENDIAN: _("Big endian"),
         13     LITTLE_ENDIAN: _("Little endian"),
         14 }
    
    /Users/nvandamme/Workspace/pylons/lib/python2.5/site-packages/hachoir_core-1.2.1-py2.5.egg/hachoir_core/i18n.pyc in <lambda>(text)
        142     # => find native function to do that
        143     unicode_gettext = lambda text: \
    --> 144         unicode(translate(text), (charset if charset else ''))
        145     unicode_ngettext = lambda singular, plural, count: \
        146         unicode(ngettext(singular, plural, count), charset)
    
    LookupError: unknown encoding:
    

    So i lookup hachoir_core_i18n.py and set line 144 as this:

        144    unicode(translate(text), (charset if charset else sys.getdefaultencoding()))
    

    And it works: no import error, and ipython compatibility!

  4. Log in to comment