Bugs item #3137807, was opened at 2010-12-15 22:13
Message generated for change (Settings changed) made by mhammond
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=551954&aid=3137807&group_id=78018
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: pythonwin
Group: None
Status: Closed
Resolution: Fixed
Priority: 5
Private: No
Submitted By: Greg Hazel (ghazel)
Assigned to: Nobody/Anonymous (nobody)
Summary: Pythonwin can't open a file with # -*- encoding: binary -*-
Initial Comment:
If a file starts with "# -*- encoding: binary -*-", Pythonwin cannot seem to open it.
----------------------------------------------------------------------
Comment By: Mark Hammond (mhammond)
Date: 2010-12-18 10:38
Message:
I checked in a fix - but be warned - pythonwin will now open the file but
will refuse the save it - it is much harder to argue Pythonwin should
*create* invalid files...
Checking in Pythonwin/pywin/scintilla/document.py;
new revision: 1.13; previous revision: 1.12
----------------------------------------------------------------------
Comment By: Mark Hammond (mhammond)
Date: 2010-12-16 10:50
Message:
(which actually *is* what happens if the encoding name is known but the
decode fails! - so the current check just needs to be extended to cover the
invalid encoding case.)
----------------------------------------------------------------------
Comment By: Mark Hammond (mhammond)
Date: 2010-12-16 10:48
Message:
Yeah - I guess it is reasonable that in the case of an unknown encoding
pythonwin should print a warning and treat it as latin-1 (the default)
instead of dumping an exception..
----------------------------------------------------------------------
Comment By: Greg Hazel (ghazel)
Date: 2010-12-16 10:40
Message:
Well, I'm not the original author of any files I've encountered with this
preamble, so I can't say why it was chosen, nor can I use something
different to start with.
However, I believe the author's intention, and certainly a reasonable
approach, would be to treat binary encoding like 8bit ascii, which I assume
is the same as you would treat it if there was no encoding specified at
all.
----------------------------------------------------------------------
Comment By: Mark Hammond (mhammond)
Date: 2010-12-16 10:24
Message:
Hrm - pep 263 which defines this behaviour says the encoding must be
"known" and my tests demonstrate python itself refuses to work with such
files. It is hard to justify a special case for the string "binary" -
can't you just use latin-1 or similar to achieve the same result? The
issue is pythonwin uses that encoding to determine how to translate the
bytes into characters...
----------------------------------------------------------------------
Comment By: Greg Hazel (ghazel)
Date: 2010-12-16 08:49
Message:
I have run in to this with several source files, which were some reason
marked with that preamble but otherwise perfectly editable. Also, I can
open notepad.exe in pythonwin just fine. I'm not expecting pythonwin to
work miracles and let me edit binary data correctly, I just think it should
let me open files no matter what they say at the beginning (like
notepad.exe opens just fine).
Otherwise, I have to open the file with Wordpad, strip the preamble, then
open with Pythonwin (and remember to put it back later). Very troublesome.
----------------------------------------------------------------------
Comment By: Mark Hammond (mhammond)
Date: 2010-12-16 06:43
Message:
pythonwin only supports editing text and without a text based encoding it
can't do much. If the problem is that the error message is unclear I can
look at fixing that, but will not enable actual editing of the file.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=551954&aid=3137807&group_id=78018
|