[Python-Dev] [python 2.7] a question about exporting a new method to socket object (original) (raw)
Guido van Rossum guido at python.org
Fri Jun 21 17:07:04 CEST 2013
- Previous message: [Python-Dev] [python 2.7] a question about exporting a new method to socket object
- Next message: [Python-Dev] [python 2.7] a question about exporting a new method to socket object
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Technically this list isn't the right place, but you probably are bitten by the duplication of functionality in Lib/socket.py. There's a list of methods at the top of that file, _socketmethods.
But you really shouldn't be asking here -- this list is for changes to Python, not using or hacking it. (Try StackOverflow for that.)
--Guido
On Thu, Jun 20, 2013 at 10:18 PM, Ani Sinha <ani at aristanetworks.com> wrote:
Hi python devs :
As a part of exploring an idea, I am trying to add a new method to the python socket object. Here's what I have been trying to do (the patch may be whitespace damaged so please bear with me) :
Index: Python-2.7/Modules/socketmodule.c =================================================================== --- Python-2.7.orig/Modules/socketmodule.c +++ Python-2.7/Modules/socketmodule.c @@ -126,6 +126,7 @@ makefile([mode, [bufsize]]) -- return a _recv(buflen[, flags]) -- receive data\n_ _recvinto(buffer[, nbytes[, flags]]) -- receive data (into a buffer)\n_ _recvfrom(buflen[, flags]) -- receive data and sender's address\n_ _+arecvfrom(buflen[, flags]) -- same as recvfrom \n_ _recvfrominto(buffer[, nbytes, [, flags])\n_ _-- receive data and sender's address (into a buffer)\n_ _sendall(data[, flags]) -- send all data\n_ @@ -468,6 +469,13 @@ static PyTypeObject socktype; _#define ISSELECTABLE(s) ((s)->sockfd < FDSETSIZE || s->socktimeout <=_ _0.0)_ _#endif_ _@@ -2620,6 +2802,58 @@ PyDocSTRVAR(recvfromdoc,_ _\n_ _Like recv(buffersize, flags) but also return the sender's address info.");_ _+static PyObject _ +sockarecvfrom(PySocketSockObject *s, PyObject *args) +{ + return sockrecvfrom(s,args); +} + +PyDocSTRVAR(arecvfromdoc, _+"arecvfrom(buffersize[, flags]) -> (data, address info)\n_ _+\n_ + experimental stuff"); _/ s.recvfrominto(buffer[, nbytes [,flags]]) method */_ @@ -2963,6 +3197,8 @@ static PyMethodDef sockmethods[] = { recvintodoc}, {"recvfrom", (PyCFunction)sockrecvfrom, METHVARARGS, recvfromdoc}, + {"arecvfrom", (PyCFunction)sockarecvfrom, METHVARARGS, + arecvfromdoc}, {"recvfrominto", (PyCFunction)sockrecvfrominto, METHVARARGS | METHKEYWORDS, recvfromintodoc}, {"send", (PyCFunction)socksend, METHVARARGS, When I compile this and run a simple script like the following that uses arecvfrom() : sock = socket.socket( socket.PFPACKET, socket.SOCKRAW ) sock.bind( ( intf, ETHPALL ) ) (pkt,dontcare) = dst.arecvfrom( 500, socket.MSGDONTWAIT ) I get this exception : AttributeError: 'socketobject' object has no attribute 'arecvfrom' So what am I doing wrong? How do I export this new socket method? any help/pointer will be greatly appreciated. cheers, ani -- Ani
Python-Dev mailing list Python-Dev at python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/guido%40python.org
-- --Guido van Rossum (python.org/~guido)
- Previous message: [Python-Dev] [python 2.7] a question about exporting a new method to socket object
- Next message: [Python-Dev] [python 2.7] a question about exporting a new method to socket object
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]