473,804 Members | 3,034 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

sockets don't play nice with new style classes :(

Just a slight rant, I think I can find a workaround.

I wanted to trace all the output being sent through a socket:

from socket import *
sock = socket()
socket.connect( (host, post))
socket.send('he llo over there\n') # I want to log the string

Sounds like a job for new style classes:

class wsocket(socket) :
def send(self, msg):
print 'socket sending (%s)'% repr(msg)
socket.send(msg )

sock = wsocket()
sock.connect(.. .)
# other stuff same as before

However, my print statement never got run.

After much head scratching it turns out that the library socket class
really makes a wrapper for an internal _socket.socket object. It goes
and manually sets the send and recv instance variables to the ones
from the _socket.socket, and does similar things for some other methods
and the doc strings.

It seems to me that the socket module itself should be rewritten to use
new style classes, so that socket.socket objects can extend _socket.socket
instead of wrapping them.

Am I missing something?
Jul 19 '05 #1
1 1356

Paul> It seems to me that the socket module itself should be rewritten
Paul> to use new style classes, so that socket.socket objects can extend
Paul> _socket.socket instead of wrapping them.

Paul> Am I missing something?

Probably not. The socket module could use some attention.

Skip
Jul 19 '05 #2

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

Similar topics

303
17798
by: mike420 | last post by:
In the context of LATEX, some Pythonista asked what the big successes of Lisp were. I think there were at least three *big* successes. a. orbitz.com web site uses Lisp for algorithms, etc. b. Yahoo store was originally written in Lisp. c. Emacs The issues with these will probably come up, so I might as well mention them myself (which will also make this a more balanced
10
2721
by: Cory Nelson | last post by:
I've created a new C++ sockets library - small, cross-platform, IPv4 and IPv6. If anyone would like to critique it, I'd appreciate it. Doesn't support the more exotic protocols - only TCP and UDP. It also lacks get/setsockopt and ioctl, but those may be added in the future. There is no webpage for it yet, I plan on making one once I'm 100% sure of everything. For now the source is available here: http://dev.int64.org/netx.zip PS....
4
7257
by: Garam | last post by:
I need to write a substantial amount of network code in C. The thing is, it has to be able to run on both Unix and Windows. Rather than writing separate code for each, I was looking for something that would abstract away the difference between sys/socket.h and winsock, and provide me with a simple socket API that would work on both operating systems. Does anyone here know of such a library? Thank you.
1
2096
by: Ray Ackley | last post by:
Is it possible to use the NetworkSteam or Sockets to somehow fill out a remote HTTP form? Can this be done with another class (or even a 3rd party utility?) I need to automate resetting the password on about 250 server-based applications and the only way to do so is through an HTTP form. Obviously every time time the password needs to be changed I don't want to fill out 250 forms. I understand how to use the NetworkSteam and Sockets...
2
3317
by: djc | last post by:
I am very new to this... I just started playing around with some network programming. I really only use vb.net. I say that so I don't get the 'use c/c++' answer. Programming is a hobby for me, not a career. I'm only interested, at least right now, in playing around with vb.net and maybe some c#.net. I'm not sure if this is the right forum or not but... my first question is to make sure I understand something: 1) the main difference...
2
24284
by: dariophoenix | last post by:
Hi, I am trying to encapsulate Linux sockets and POSIX threads in C++ classes (I work in Knoppix, using KDevelop). Since sockets and threads are new to me, I searched for example code and found the following: #include <stdlib.h> #include <stdio.h> #include <string.h> #include <errno.h> #include <netdb.h>
2
6673
by: a_agaga | last post by:
Do you know are there some reasons why many do not make processes to communicate through memory? Why network connections (sockets) are used so commonly in IPC (inter process communication) instead of memory? (Is IPC harder to maintain / handle if it is made through memory, when compared to communication through sockets?) Some background things:
0
1456
by: rossabri | last post by:
This topic has been addressed in limited detail in other threads: "sockets don't play nice with new style classes :(" May 14 2005. http://groups.google.com/group/comp.lang.python/browse_thread/thread/76d27388b0d286fa/c9849013e37c995b "Subclassing socket" Dec 20 2005 - Jan 14 2006. http://groups.google.com/group/comp.lang.python/browse_thread/thread/391728cd442339c8/c0581b9ee5e7ceaf Briefly, the socket module ("socket.py") provides a...
31
1931
by: Jo | last post by:
class A { public: char text_a; A() { *text_a=0; } ~A() {} }; //-----------------------------------------------------------------------------
0
9572
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
10319
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...
1
10303
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10070
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
9132
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...
0
5508
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...
0
5639
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4282
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
2
3803
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.