[python-win32] patch to makepy.py / genpy.py
Massa, Harald Armin
chef at ghum.de
Wed Jul 8 16:17:33 CEST 2009
Hello,
in Version 213 of pywin32 within
win32com\client\genpy.py
on line 814, within def do_gen_file_header(self): there is the assertion:
# You must provide a file correctly configured for writing unicode.
# We assert this is it may indicate somewhere in pywin32 that needs
# upgrading.
assert self.file.encoding, self.file
But using makepy.py via
makepy.py -v -o OLE_Excel11.py "Microsoft Excel 11.0 Object Library"
this assertion fails ... as self.file.encoding is None
The culprit is makepy.py itself:
starting at line 367ff there is:
if outputName is not None:
path = os.path.dirname(outputName)
if path is not '' and not os.path.exists(path):
os.makedirs(path)
f = open(outputName, "w")
else:
f = None
and this "f" will have encoding=None
I patched this to:
if outputName is not None:
path = os.path.dirname(outputName)
if path is not '' and not os.path.exists(path):
os.makedirs(path)
#~ f = open(outputName, "w")
import codecs
f= codecs.open(outputName, mode="w",encoding="mbcs")
else:
f = None
use codecs to create a file with mbcs encoding. After this, I get a nice
create ole_excel11.py file, with the good line
# -*- coding: mbcs -*-
at the beginning.
I propose to put this fix into makepy.py for everybody; (any rights you need
are hereby granted)
best wishes,
Harald
--
GHUM Harald Massa
persuadere et programmare
Harald Armin Massa
Spielberger Straße 49
70435 Stuttgart
0173/9409607
no fx, no carrier pigeon
-
LASIK good, steroids bad?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20090708/cdd61dbe/attachment.htm>
More information about the python-win32
mailing list