[python-win32] Converting VB to Python

Mark Hammond mhammond at skippinet.com.au
Fri Jul 2 02:18:30 EDT 2004


The equivalent of "implements" is for your Python COM object to support that
interface, like any other COM interface.

The slightly tricky thing here is that the interface is described in a
type-library.  So, you code would look something like:

from win32com import universal
universal.RegisterInterfaces(
       '{F5078F18-C551-11D3-89B9-0000F81FE221}', 0, 4, 0,
       ["_IVBSAXErrorHandler"])

class MyHandler:
    _com_interfaces_ = ['IVBSAXErrorHandler']
    def error(self, locator, strError, nErrorCode):
     ...

Note that the magic numbers passed to RegisterInterfaces is the ID of the
type-library.  I obtained these by running "makepy.py -i", then selecting
the Microsoft XML library version 4.  (Version 2 didn't have this interface)

To setup the validator, the code would look something like:

# create the instance
validator = MyHandler()
# turn it into a COM object
from win32com.server.util import wrap
validator = wrap(validator)
rdr.errorHandler = validator


Note that:
validator = wrap(validator, debug=1)

May be useful if the code does not run from a console - Pythonwin's "Remote
Collector" will see any output or errors generated by your object.

I hope this makes sense.

Mark.

-----Original Message-----
From: python-win32-bounces at python.org
[mailto:python-win32-bounces at python.org]On Behalf Of
Peter.Winstanley at scotland.gsi.gov.uk
Sent: Wednesday, 30 June 2004 4:32 PM
To: python-win32 at python.org
Subject: [python-win32] Converting VB to Python


****************************************************************************
***************************************************************************
This email and any files transmitted with it are intended solely for the use
of the individual or entity to whom they are addressed.
****************************************************************************
***************************************************************************


I would be grateful for help and advice on the following: 
I am trying to convert into Python an example VB program that uses MSXML 4.0
and the SAXXMLReader40 and XMLSchemaCache40 to  validate an XML file against
an XSD schema and to provide exhaustive errors.  The routine is given here:
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q315497
In the VB version a class module is created to act as an error handler.  The
class starts with the statement 
"Implements MSXML2.IVBSAXErrorHandler" 


How do I convert an "Implements" statement to Python? 
Thanks for your help 



The original of this email was scanned for viruses by the Government Secure
Intranet (GSi) virus scanning service supplied exclusively by Energis in
partnership with MessageLabs.

On leaving the GSi this email was certified virus-free
-------------- next part --------------
A non-text attachment was scrubbed...
Name: winmail.dat
Type: application/ms-tnef
Size: 3144 bytes
Desc: not available
Url : http://mail.python.org/pipermail/python-win32/attachments/20040702/9aff01dd/winmail.bin


More information about the Python-win32 mailing list