Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#97 patch to reenable makepy.py / against missing encoding error

closed-out-of-date
nobody
None
5
2010-07-11
2010-07-11
No

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)

Discussion

  • Roger Upole
    Roger Upole
    2010-07-11

    Thanks for the patch! However, this is already fixed in r1.29.

     
  • Roger Upole
    Roger Upole
    2010-07-11

    • status: open --> closed-out-of-date