473,320 Members | 1,936 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How Can I overide a function in an existing class

Hi all,

I am using ZSI SOAP library for a web service. My service runs fine,
but it outputs a line

localhost - - [14/Sep/2004 20:21:55] "POST / HTTP/1.1" 200 -

every time the web service is accessed. I traced it down to the
BaseHTTPServer.log_message function that the ZSI Soap library uses for
the web server.

I want to turn this service into a windows NT service and I need to
stop the program from outputing the line.

I cannot make a new class derived from BaseHTTPServer and override the
log_message function because I can't change the web server object used
by ZSI.

I also can't redirect stderr because the service messes with stdout
and error already.

I have changed the BaseHTTPServer.py file to do what I want and
included it in the directory with my service. This works, but there
has to be a better way.

Is there some other way to override the function?

Thanks in advance for any help

Eddie
Jul 18 '05 #1
2 1547
Eddie wrote:
I have changed the BaseHTTPServer.py file to do what I want and
included it in the directory with my service. This works, but there
has to be a better way.

Is there some other way to override the function?


Often I've found it possible and relatively "clean" to write
code that modifies the class involved dynamically, often
just wrapping the existing method in another one that does
what I want (or undoes it, perhaps), or just by sticking
in a replacement.

Trivialized example that I hope gives you the idea:

# file BaseHTTPServer.py
class SomeClass:
def someMethod(self):
log_message(somemsg) # undesirable call
# other stuff that is good
# in your own file

import BaseHTTPServer
def replacementMethod(self):
# only the good stuff

BaseHTTPServer.SomeClass.someMethod = replacementMethod

# followed by the rest of your existing code that
# actually instantiates a SomeClass, even if indirectly

Any help?

-Peter
Jul 18 '05 #2
> Trivialized example that I hope gives you the idea:

# in your own file

import BaseHTTPServer
def replacementMethod(self):
# only the good stuff

BaseHTTPServer.SomeClass.someMethod = replacementMethod

Any help?

-Peter


Thanks Peter. This is exactly what I was looking for. It works
perfectly and is very simple.

Thanks again
Eddie
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: David Morgenthaler | last post by:
How does one overide the iterator implied by the construct "for line in file:"? For example, suppose I have a file containing row,col pairs on each line, and I wish to write a subclass of file...
4
by: Roy Yao | last post by:
Why the following code let my compiler complain an overloaded function Init()? // code begin template<class T> class BicircularList { template<class T> class Iterator; template<class T> class...
2
by: Martin Arvidsson, Visual Systems AB | last post by:
Hi! I have a textBox on a windows form. Can i overide the textbox OnPaint directly in the form, if so how. Or do i have to inherit the textbox control and overide it there? Regards Martin
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.