#53 Encoding problems

closed-fixed
nobody
None
7
2005-02-08
2005-02-07
No

Problem mit encoding (never used until now)
I don't know, what to choose.
i have no unicode, so i didn't check the autodetect
encoding
the first entry is empty, cp1252, ascii, latin1, utf-8
and utf16.
But none of these work (for text files with german
umlaute).

I only want to open a file as until now (without encoding),
but thats not possible anymore.

(in this case, Enocding preference was empty)

There was an error opening the document C:/test.txt.

Traceback (most recent call last):
File "c:/drpython/plugins\KeyBoardMacros.py", line
274, in OpenMacroFile

self.txtDocument.SetText(drEncoding.EncodeText(self,
oof, encoding))
File
"C:\Python23\lib\site-packages\wx-2.5.3-msw-ansi\wx\stc.py",
line 1761, in SetText
return _stc.StyledTextCtrl_SetText(*args, **kwargs)
TypeError: String or Unicode type required

Discussion

    • priority: 5 --> 7
     
  • Logged In: YES
    user_id=796750

    Can you open the file through the normal drpython file dialog?

    Can you attach a copy of the villianous file?

    Basically, if unicode detect is off, and the default encoding
    value is empty (I should make this more clear), then
    the file should be opened as ascii.

    Of course, if the file then has characters outside the ascii
    range,
    the EncodeText function will return None.
    (I could throw an exception as well).

    Probably, opening a file with no encoding works for you with
    your wxpython version. However if you open an file with the
    wrong encoding with the unicode version, serious problems
    can arise:

    During saving, drpython will simply blank the file!
    If you enter offending characters into the prompt, instant
    segfault.

    So to protect against this, I changed drpython so it
    requires you
    to either tell it to use the autodetect, or at least tell it
    what encoding to use for non ascii text, so users don't
    suddenly find a file gone, or their unsaved work lost.

    So where does this leave us?

    1. If you turn on autodetect, does all work as planned?
    2. Looking through the encodings in the python docs,
    can you find the encoding you need? (I can add it to the list).
    (http://www.python.org/doc/2.4/lib/standard-encodings.html)

    This could be an odd bug, but testing it with the latin-1
    encoding, everything seems to work as planned.

     
  • Logged In: YES
    user_id=772872

    No, I cannot open the file with wxFileDialog because of an
    exception.

    Traceback (most recent call last):
    File "C:\Eigene Dateien\python\drpython\drpython.py", line
    2053, in OnOpen
    theencoding = dlg.GetEncoding()
    AttributeError: 'FileDialog' object has no attribute
    'GetEncoding'

    >(I should make this more clear), then
    >the file should be opened as ascii.
    Apparantly, this is not so.

    In drFileDialog, there is <default Encoding>.
    Trying to open test.txt:

    There was an error opening the document C:/test.txt.

    Traceback (most recent call last):
    File "c:/drpython/plugins\KeyBoardMacros.py", line 274, in
    OpenMacroFile
    self.txtDocument.SetText(drEncoding.EncodeText(self,
    oof, encoding))
    File
    "C:\Python23\lib\site-packages\wx-2.5.3-msw-ansi\wx\stc.py",
    line 1761, in SetText
    return _stc.StyledTextCtrl_SetText(*args, **kwargs)
    TypeError: String or Unicode type required

    (I have updated KeyBoardMacros)
    So in "EncodeText", there seems to be the problem.

    I only want to open the file as until now (without any
    encoding) and never used encoding.
    I will attach the offending file.

     
  •  
    Attachments
    • status: open --> closed-fixed
     
  • Logged In: YES
    user_id=796750

    So I tried the unicode test. I think it will make all work
    as planned.
    It seems that drpython will save files fine if wxpython is
    not compiled with unicode support. So everything will work
    as before.
    It will only check for unicode and/or use the default
    encoding if unicode support is built in (and it is necessary).

    I will look at the wxpython dialog bit.