#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2004
    Location
    Canada
    Posts
    242
    Rep Power
    0

    Socket Module Implementation


    When looking in the socket module code the first comment reads:

    Code:
    # Wrapper module for _socket, providing some additional facilities
    # implemented in Python.
    Does anyone know where _socket is?

    Also, is it possible to write a lower level socket module?
  2. #2
  3. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Under windows i'd assume it were in the DLL folder within Pythons main directory. If you do a search for _socket.pyd then you should find it .

    The socket module is a wrapper over that defined by C/C++ so i would highly dout it although if you look into how C/C++ implements this then maybe...

    Mark.
    Last edited by netytan; June 5th, 2004 at 12:47 PM.
    programming language development: www.netytan.com Hula

  4. #3
  5. Only the strong survives!!.
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Feb 2003
    Location
    A World of wonders.
    Posts
    5,583
    Rep Power
    407
    Originally Posted by NetBSD
    When looking in the socket module code the first comment reads:

    Code:
    # Wrapper module for _socket, providing some additional facilities
    # implemented in Python.
    Does anyone know where _socket is?

    Also, is it possible to write a lower level socket module?
    socket is a low level socket with blocking
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2004
    Location
    Canada
    Posts
    242
    Rep Power
    0
    Originally Posted by netytan
    Under windows i'd assume it were in the DLL folder within Pythons main directory. If you do a search for _socket.pyd then you should find it .
    Weird... it doesn't find it?
  8. #5
  9. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Mmm, thats strange. Does the socket module import properly. You might also want to try searching for _socket.dll though it should b _socket.pyd by convention.

    Mark.
    programming language development: www.netytan.com Hula

  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2004
    Location
    Canada
    Posts
    242
    Rep Power
    0
    Code:
    [Aurora:~] chris% python
    Python 2.3 (#1, Sep 13 2003, 00:49:11) 
    [GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import socket
    >>> sock = socket.socket()
    >>> sock
    <socket._socketobject object at 0x538a0>
    >>>
    I'm on Mac OS X, so it wouldn't be .dll. I just searched for "_socket" and it found nothing. I downloaded the 2.3.4 source and I can't find it in there either.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    133
    Rep Power
    12
    Let's say you can import _socket (you should be able to):
    Code:
    >>> import _socket
    >>> print _socket.__file__
    You should get the implementation file.

    Of course, this is nicer and works with many more objects:
    Code:
    >>> import inspect
    >>> import _socket
    >>> print inspect.getfile(_socket)
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2004
    Location
    Canada
    Posts
    242
    Rep Power
    0
    Code:
    [Aurora:~] chris% python
    Python 2.3 (#1, Sep 13 2003, 00:49:11) 
    [GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import _socket
    >>> print _socket.__file__
    /System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/lib-dynload/_socket.so
    This seems to point me to the shared library. Do you know where I can get the Python source for it (_socket is written in Python, isn't it?)?
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Posts
    133
    Rep Power
    12
    No. The _socket module is not written in Python. It's written in C.

    You can find the wrapper source in Python-Src/Modules/socketmodule.c and the header file in Python-Src/Modules/socketmodule.h.
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2004
    Location
    Canada
    Posts
    242
    Rep Power
    0
    Sorry to drag this on longer, but I just need one more clarification: Does socketmodule.c wrap _socket (socket->sockmodule->_socket) or is socketmodule.c the file for _socket?

    Bah... I don't even understand how Python can import a C file...
  20. #11
  21. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2001
    Location
    Houston, TX
    Posts
    383
    Rep Power
    13
    The better question is - what do you need a lower level socket for?
    Debian - because life's too short for worrying.
    Best. (Python.) IRC bot. ever.
  22. #12
  23. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2004
    Location
    Canada
    Posts
    242
    Rep Power
    0
    For fun?
  24. #13
  25. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2001
    Location
    Houston, TX
    Posts
    383
    Rep Power
    13
    But what exactly would you need to make it a lower-level one? The socket module provides you pretty much the same control over sockets as the equivalent C socket library would. In other words, they are already fairly low-level in that you have a good amount of control over them, but they are high-level in the respect that they are wrapped in a nice interface that you can easily use without a lot of setup.
    Debian - because life's too short for worrying.
    Best. (Python.) IRC bot. ever.
  26. #14
  27. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2004
    Location
    Canada
    Posts
    242
    Rep Power
    0
    Originally Posted by Strike
    But what exactly would you need to make it a lower-level one? The socket module provides you pretty much the same control over sockets as the equivalent C socket library would. In other words, they are already fairly low-level in that you have a good amount of control over them, but they are high-level in the respect that they are wrapped in a nice interface that you can easily use without a lot of setup.
    I'm interested in low-level stuff (don't tell me to "use C then", because I already do ). Although, it was the actual implementation of the socket module for Python that interested me, and writing it over again would be a waste so the alternative was to write a lower level one.

IMN logo majestic logo threadwatch logo seochat tools logo