[python-win32] [Fwd: Re: Running the COM MakePy Utility from python]

Grant Paton-Simpson grant at p-s.co.nz
Fri Aug 28 00:47:26 CEST 2009


Cool - that's what I love about the open source community.  You can see 
the code, fix the code, and share the fix.

Massa, Harald Armin wrote:
> Grant,
>
> for your problems with the assertion there is a patch...
>
> - 
> -----------------------------------------------------------------------------------------------
>
> 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)
> - 
> -----------------------------------------------------------------------------------------------
>
> (of which you could not know; I guess it got lost somewhere between 
> Europe and Australia, where Mark Hammond, the master of pywin32, was 
> before)
>
> Now I have put out this patch to the public, for others to enjoy 
> untill it may or may not be worked into makepy.py
>
> best wishes,
>
> Harald
>
> On Thu, Aug 27, 2009 at 1:51 PM, Grant Paton-Simpson <grant at p-s.co.nz 
> <mailto:grant at p-s.co.nz>> wrote:
>
>     Hi Harald,
>
>     I managed to make a file containing everything I needed.  NB the
>     command
>     is makepy.py not makepy.  There was, however, an issue with genpy.py
>     asserting there had to be a self.file.encoding even though I couldn't
>     see where that was set.  I temporarily commented that assert out.
>      File
>     creation then worked.  I then took out the small portion of the
>     script I
>     needed - all the data type constants - and put those in my own
>     module. Success!
>
>     For the benefit of others, the reason you don't have to specify the
>     library e.g. ActiveX 2.8, is that you will be prompted for it via
>     a pop
>     up GUI.
>
>
>     All the best, Grant
>
>
>     Massa, Harald Armin wrote:
>     > Grant,
>     >
>     > that is possible. Just read the makepy.py script within
>     > win32com.client, and you will find that someway down main() there is
>     >
>     > ---------
>     > GenerateFromTypeLibSpec(arg, f, verboseLevel = verboseLevel,
>     > bForDemand = bForDemand, bBuildHidden = hiddenSpec)
>     > ---------
>     >
>     > which does this.
>     >
>     > BUT, for "static" usage of makepy-COM-Mappings I suggest to make
>     > makepy output it's results in a named file
>     >
>     > makepy -o ADO28.py
>     >
>     > and furtheron import that ADO28 file to access the variables. That
>     > does also work  with Excel and Word, and I am used to
>     >
>     > import ExcelXX as Excel
>     > ec=Excel.constants
>     >
>     > and further on us ec.* for excel constants.
>     >
>     > Best wishes,
>     >
>     > HArald
>     >
>     > On Thu, Aug 27, 2009 at 2:51 AM, Grant Paton-Simpson
>     <grant at p-s.co.nz <mailto:grant at p-s.co.nz>
>     > <mailto:grant at p-s.co.nz <mailto:grant at p-s.co.nz>>> wrote:
>     >
>     >     Hi,
>     >
>     >     Basically I want to have an installation package
>     automatically run the
>     >     COM MakePy utility for the ADO 2.8 library. I believe I need
>     to do
>     >     this
>     >     so that constants like win32com.client.constants.adTinyInt
>     will be
>     >     available when my application (http://www.sofastatistics.com)
>     >     connects to
>     >     MS Access and MS SQL Server databases.
>     >
>     >     Ideally I would have a line doing something like this:
>     >
>     >     win32com.runmakepy("Microsoft ActiveX Data Objects 2.8
>     Library (2.8)")
>     >
>     >     Is it possible to do this programmatically?
>     >
>     >
>     >     All the best, Grant
>     >     _______________________________________________
>     >     python-win32 mailing list
>     >     python-win32 at python.org <mailto:python-win32 at python.org>
>     <mailto:python-win32 at python.org <mailto:python-win32 at python.org>>
>     >     http://mail.python.org/mailman/listinfo/python-win32
>     >
>     >
>     >
>     >
>     > --
>     > 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?
>
>
>     _______________________________________________
>     python-win32 mailing list
>     python-win32 at python.org <mailto:python-win32 at python.org>
>     http://mail.python.org/mailman/listinfo/python-win32
>
>
>
>
> -- 
> 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?


More information about the python-win32 mailing list