473,406 Members | 2,849 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,406 software developers and data experts.

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=None):
...

# 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 1204
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=None):
...

# 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.open_https = None
pyURLopener.open_https
pytype(URLopener.open_https)
<type 'NoneType'>
pydef doit(self, url, data=None, ssl_context=None):
.... print 'self is %s, url is %s' % (self, url)
....
....
pyURLopener.open_https = doit
pyu = URLopener()
pyu = u.open_https('http://wherever.com')
self is <urllib.URLopener 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
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...
11
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...
4
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...
8
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?...
18
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...
3
by: john | last post by:
Hi to All To demonstrate: public class MyBaseGenericClass<T> { } public class MyGenericClass1<T: MyBaseGenericClass<T> {
14
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...
16
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....
162
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
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...
0
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,...

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.