473,806 Members | 2,654 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Does class patching actually work

In M2Crypto/m2urllib there is this:

import string, sys, urllib
from urllib import *

def open_https(self , url, data=None, ssl_context=Non e):
...

# Minor brain surgery.
URLopener.open_ https = open_https

The intent of this is to replace method open_https of class URLopener
with a local, patched version.

Does that actually work? When I've tried to do that in other code, it
seems to have no effect. In fact, I can write

URLopener.open_ https = None

and nothing changes.

John Nagle
Jan 16 '07 #1
2 1218
John Nagle wrote:
In M2Crypto/m2urllib there is this:

import string, sys, urllib
from urllib import *

def open_https(self , url, data=None, ssl_context=Non e):
...

# Minor brain surgery.
URLopener.open_ https = open_https

The intent of this is to replace method open_https of class URLopener
with a local, patched version.

Does that actually work? When I've tried to do that in other code, it
seems to have no effect. In fact, I can write

URLopener.open_ https = None

and nothing changes.

John Nagle
I'm not able to reproduce your results with python 2.5.

pyfrom urllib import *
pyURLopener.ope n_https = None
pyURLopener.ope n_https
pytype(URLopene r.open_https)
<type 'NoneType'>
pydef doit(self, url, data=None, ssl_context=Non e):
.... print 'self is %s, url is %s' % (self, url)
....
....
pyURLopener.ope n_https = doit
pyu = URLopener()
pyu = u.open_https('h ttp://wherever.com')
self is <urllib.URLopen er instance at 0x4066070c>, url is
http://wherever.com
Jan 16 '07 #2
James Stroud wrote:
John Nagle wrote:
>The intent of this is to replace method open_https of class URLopener
with a local, patched version.

Does that actually work? When I've tried to do that in other code, it
seems to have no effect. In fact, I can write

URLopener.open_ https = None

and nothing changes.
My mistake. Confusion between

import a.b
c = foo

and

import a
b.c = foo

which result in different namespaces.

John Nagle
Jan 17 '07 #3

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

Similar topics

5
3642
by: me | last post by:
I have a Class Library that contains a Form and several helper classes. A thread gets created that performs processing of data behind the scenes and the Form never gets displayed (it is for debug puposes only and is not normally visable to the user.) The Thread function is actually in the Form class. Now.. What I am seeing is that when I create an instance of this Class Library's Form, which starts the worker thread, it seems to hose up...
11
1875
by: Michi Henning | last post by:
Hi, I'm using a blocking Select() call on a socket with a timeout value of -1. I'd expect the call to block indefinitely, but it doesn't. When I use Poll() instead, a timeout of -1 works fine and blocks indefinitely. The net effect is that I cannot write a select on more than one file descripter if I want to block. (With timeout values >= 0, both Select() and Poll() work fine.)
4
3119
by: Uchiha Jax | last post by:
Hello everyone, I am a plenty silly person who is trying to learn .NET remoting through trial and error (all articles I read are going over my head at the moment (mostly) so I thought i'd give it a go). What I want to do is this: Have a server instance of the program, this server instance will receive communication from client programs (as demonstrated in the AddMessage()
8
2639
by: shawnz | last post by:
Is there any way to either derive a sealed class, or access private members of a sealed class? Either that, or is there a way to run internal methods in a sealed class outside the current assembly? I don't mind if the solution is hackish, the dll i'm writing is already full of code hacks. =p
18
1986
by: cj | last post by:
members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe. I'm under the impression before you can use a class you have to make an instance of it. So how can a class be threadsafe by itself but an instance of it not be? I guess I don't get what exactly being threadsafe means. Multiple theads can use the same instance of a class?
3
2831
by: john | last post by:
Hi to All To demonstrate: public class MyBaseGenericClass<T> { } public class MyGenericClass1<T: MyBaseGenericClass<T> {
14
4867
by: Anoop | last post by:
Hi, I am new to this newsgroup and need help in the following questions. 1. I am workin' on a GUI application. Does C# provides Layout Managers the way Java does to design GUI? I know that it can be done using the designer but I intentionally don't want to use that. The one reason is that you cannot change the code generated by the designer. The other could be that you have more free hand and control to design your GUI. 2....
16
4087
by: chosechu | last post by:
Hello Pythoneers: I need to pass a list of named arguments to a function in a given order, and make sure these named arguments are retrieved using keys() in the same order they were given. Example: keyargs={} keyargs=1 keyargs=2
162
10329
by: Sh4wn | last post by:
Hi, first, python is one of my fav languages, and i'll definitely keep developing with it. But, there's 1 one thing what I -really- miss: data hiding. I know member vars are private when you prefix them with 2 underscores, but I hate prefixing my vars, I'd rather add a keyword before it. Python advertises himself as a full OOP language, but why does it miss one of the basic principles of OOP? Will it ever be added to python?
0
9597
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10618
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10366
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10110
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9187
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7649
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6877
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5546
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4329
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.