Luc Xation | 27 Aug 2011 23:05
Picon

some little problems

Hi
i tries to use the hachoir-editor library and i got some problems.

first
there is no setup.py script in the directory ( it's not important but more easier to use )

second

in this example

from hachoir_editor import createEditor
from hachoir_core.field import writeIntoFile

editor = createEditor(u"file.gz")
del editor["filename"]
editor["has_filename"].value = False
writeIntoFile(editor, u"noname.gz")


I got this error
Traceback (most recent call last):
  File "first.py", line 6, in <module>
    editor["has_filename"].value = False
  File "/usr/local/lib/python2.6/dist-packages/hachoir_editor/fieldset.py", line 244, in __getitem__
    raise MissingField(self, key)
hachoir_core.field.field.MissingField

in this example

from hachoir_editor import createEditor
from hachoir_core.field import writeIntoFile
from hachoir_editor import EditableInteger, EditableBytes
//// i modified this line
editor = createEditor(u"file.gz")
extra = "abcd"
editor["has_extra"].value = True
editor.insertAfter("os", EditableInteger(editor, "extra_length", False, 16, len(extra)), EditableBytes(editor, "extra", extra))
writeIntoFile(editor, u"file_extra.gz")

I got this error
Traceback (most recent call last):
File "second.py", line 7, in <module>
editor["has_extra"].value = True
File "/usr/local/lib/python2.6/dist-packages/hachoir_editor/fieldset.py", line 244, in __getitem__
raise MissingField(self, key)

Thanks for your help
Luc Xation
Victor Stinner | 27 Aug 2011 23:53

Re: some little problems

Le samedi 27 août 2011 23:05:01, Luc Xation a écrit :
> in this example
> ....
> editor = createEditor(u"file.gz")
> del editor["filename"]
...
> *I got this error ... MissingField

Are you testing hachoir_editor on a gzip file?

Victor

Victor Stinner | 28 Aug 2011 04:10

Re: some little problems

Le samedi 27 août 2011 23:05:01, Luc Xation a écrit :
> in this example
> 
> *from hachoir_editor import createEditor
> from hachoir_core.field import writeIntoFile
> 
> editor = createEditor(u"file.gz")
> del editor["filename"]
> editor["has_filename"].value = False
> writeIntoFile(editor, u"noname.gz")
> 
> 
> *I got this error

Oh, I realized that all examples were wrong... I fixed (again) all examples on 
the webpage:
https://bitbucket.org/haypo/hachoir/wiki/hachoir-editor

createEditor() expects a parser object, not a Unicode string...

Victor

Luc Xation | 28 Aug 2011 07:42
Picon

Re: some little problems

thanks a lot victor!!!

2011/8/28 Victor Stinner <victor.stinner-XgyrR7WU8tJ8UrSeD/g0lQ@public.gmane.org>
Le samedi 27 août 2011 23:05:01, Luc Xation a écrit :
> in this example
>
> *from hachoir_editor import createEditor
> from hachoir_core.field import writeIntoFile
>
> editor = createEditor(u"file.gz")
> del editor["filename"]
> editor["has_filename"].value = False
> writeIntoFile(editor, u"noname.gz")
>
>
> *I got this error

Oh, I realized that all examples were wrong... I fixed (again) all examples on
the webpage:
https://bitbucket.org/haypo/hachoir/wiki/hachoir-editor

createEditor() expects a parser object, not a Unicode string...

Victor



Gmane