Hello,
The new documentation system is really a major improvement: congratulations!
However, I run into a problem while trying to build the new python docs. I initially used python2.5 on windows, but Linux seems to have the same problem. Am I really the only one who gets this error?
The offending code is in Doc\tools\sphinx\builder.py, and looks like this:
from __future__ import with_statement import codecs with codecs.open('foo.txt', 'w', 'utf-8') as fp: ... print type(fp), fp ... fp.write(u"\xb6") ...
<type 'file'> <open file 'foo.txt', mode 'wb' at 0x00C649E8> Traceback (most recent call last): File "<stdin>", line 3, in <module> UnicodeEncodeError: 'ascii' codec can't encode character u'\xb6' in position 0: ordinal not in range(128)
Where does the 'ascii' codec come from? I propose the following explanation:
An obvious workaround is to add the __enter__ method to StreamReaderWriter: def __enter__(self): return self This is not perfect though, because one may want to wrap say a socket.makefile instead of a file.
It seems like the delegation pattern does not mix well with context managers... Is there another solution? Or did I miss something obvious?
-- Amaury Forgeot d'Arc
However, I run into a problem while trying to build the new python docs. I initially used python2.5 on windows, but Linux seems to have the same problem. Am I really the only one who gets this error?
Not sure - but it works fine for me.
from __future__ import with_statement import codecs with codecs.open('foo.txt', 'w', 'utf-8') as fp: ... print type(fp), fp ... fp.write(u"\xb6") ...
<type 'file'> <open file 'foo.txt', mode 'wb' at 0x00C649E8>
That is surprising. Are you sure codecs.open is what it should be on your system? I get
<type 'instance'> <open file 'foo.txt', mode 'wb' at 0xb7d89e78>
Where does the 'ascii' codec come from? I propose the following explanation:
Good explanation. I'm using Python 2.5.1, and this may be relevant:
r52518 | georg.brandl | 2006-10-29 09:39:27 +0100 (So, 29 Okt 2006) | 4 lines
Fix codecs.EncodedFile which did not use file_encoding in 2.5.0, and fix all codecs file wrappers to work correctly with the "with" statement (bug #1586513). (backport from rev. 52517)
It seems like the delegation pattern does not mix well with context managers... Is there another solution? Or did I miss something obvious?
I think the obvious thing you missed is that the problem got fixed already. Whether the documentation system should be more defensive and work with 2.5.0 also is a different question.
Regards, Martin