[Python-Dev] [python 2.7] a question about exporting a new method to socket object (original) (raw)
Ani Sinha ani at aristanetworks.com
Fri Jun 21 19:28:20 CEST 2013
- Previous message: [Python-Dev] [python 2.7] a question about exporting a new method to socket object
- Next message: [Python-Dev] PEP 409 and the stdlib
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Hi Guido :
Thanks a lot. That helped.
I will try StackOverflow next time.
cheers, ani
On Fri, Jun 21, 2013 at 8:07 AM, Guido van Rossum <guido at python.org> wrote:
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)
-- Ani -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20130621/1c5b0c85/attachment.html>
- Previous message: [Python-Dev] [python 2.7] a question about exporting a new method to socket object
- Next message: [Python-Dev] PEP 409 and the stdlib
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]