Поиск по блогу

воскресенье, 4 мая 2014 г.

Today I`m learning "Socket Programming HOWTO" and improve my English

I have read Socket programming Python Docs... There are two objects in Python 2.7 I insert to this post helpl(socket) and Soxypy readme.txt
There are 7 links here ...and huge help(socket) file... and SocksiPy link and readme.txt ... And the question "Who use the SocketServer object" is still a charade for me...
Part of the trouble with understanding these things is that “socket” can mean a number of subtly different things, depending on context. So first, let’s make a distinction between a “client” socket - an endpoint of a conversation, and a “server” socket, which is more like a switchboard operator. The client application (your browser, for example) uses “client” sockets exclusively; the web server it’s talking to uses both “server” sockets and “client” sockets.
In [3]:
import socket
In [6]:
help(socket)
Help on module socket:

NAME
    socket

FILE
    /usr/lib/python2.7/socket.py

MODULE DOCS
    http://docs.python.org/library/socket

DESCRIPTION
    This module provides socket operations and some related functions.
    On Unix, it supports IP (Internet Protocol) and Unix domain sockets.
    On other systems, it only supports IP. Functions specific for a
    socket are available as methods of the socket object.
    
    Functions:
    
    socket() -- create a new socket object
    socketpair() -- create a pair of new socket objects [*]
    fromfd() -- create a socket object from an open file descriptor [*]
    gethostname() -- return the current hostname
    gethostbyname() -- map a hostname to its IP number
    gethostbyaddr() -- map an IP number or hostname to DNS info
    getservbyname() -- map a service name and a protocol name to a port number
    getprotobyname() -- map a protocol name (e.g. 'tcp') to a number
    ntohs(), ntohl() -- convert 16, 32 bit int from network to host byte order
    htons(), htonl() -- convert 16, 32 bit int from host to network byte order
    inet_aton() -- convert IP addr string (123.45.67.89) to 32-bit packed format
    inet_ntoa() -- convert 32-bit packed format IP to string (123.45.67.89)
    ssl() -- secure socket layer support (only available if configured)
    socket.getdefaulttimeout() -- get the default timeout value
    socket.setdefaulttimeout() -- set the default timeout value
    create_connection() -- connects to an address, with an optional timeout and
                           optional source address.
    
     [*] not available on all platforms!
    
    Special objects:
    
    SocketType -- type object for socket objects
    error -- exception raised for I/O errors
    has_ipv6 -- boolean value indicating if IPv6 is supported
    
    Integer constants:
    
    AF_INET, AF_UNIX -- socket domains (first argument to socket() call)
    SOCK_STREAM, SOCK_DGRAM, SOCK_RAW -- socket types (second argument)
    
    Many other constants may be defined; these may be used in calls to
    the setsockopt() and getsockopt() methods.

CLASSES
    __builtin__.object
        _socketobject
        _socketobject
    exceptions.IOError(exceptions.EnvironmentError)
        error
            gaierror
            herror
            timeout
    
    SocketType = class _socketobject(__builtin__.object)
     |  socket([family[, type[, proto]]]) -> socket object
     |  
     |  Open a socket of the given type.  The family argument specifies the
     |  address family; it defaults to AF_INET.  The type argument specifies
     |  whether this is a stream (SOCK_STREAM, this is the default)
     |  or datagram (SOCK_DGRAM) socket.  The protocol argument defaults to 0,
     |  specifying the default protocol.  Keyword arguments are accepted.
     |  
     |  A socket object represents one endpoint of a network connection.
     |  
     |  Methods of socket objects (keyword arguments not allowed):
     |  
     |  accept() -- accept a connection, returning new socket and client address
     |  bind(addr) -- bind the socket to a local address
     |  close() -- close the socket
     |  connect(addr) -- connect the socket to a remote address
     |  connect_ex(addr) -- connect, return an error code instead of an exception
     |  dup() -- return a new socket object identical to the current one [*]
     |  fileno() -- return underlying file descriptor
     |  getpeername() -- return remote address [*]
     |  getsockname() -- return local address
     |  getsockopt(level, optname[, buflen]) -- get socket options
     |  gettimeout() -- return timeout or None
     |  listen(n) -- start listening for incoming connections
     |  makefile([mode, [bufsize]]) -- return a file object for the socket [*]
     |  recv(buflen[, flags]) -- receive data
     |  recv_into(buffer[, nbytes[, flags]]) -- receive data (into a buffer)
     |  recvfrom(buflen[, flags]) -- receive data and sender's address
     |  recvfrom_into(buffer[, nbytes, [, flags])
     |    -- receive data and sender's address (into a buffer)
     |  sendall(data[, flags]) -- send all data
     |  send(data[, flags]) -- send data, may not send all of it
     |  sendto(data[, flags], addr) -- send data to a given address
     |  setblocking(0 | 1) -- set or clear the blocking I/O flag
     |  setsockopt(level, optname, value) -- set socket options
     |  settimeout(None | float) -- set or clear the timeout
     |  shutdown(how) -- shut down traffic in one or both directions
     |  
     |   [*] not available on all platforms!
     |  
     |  Methods defined here:
     |  
     |  __init__(self, family=2, type=1, proto=0, _sock=None)
     |  
     |  accept(self)
     |      accept() -> (socket object, address info)
     |      
     |      Wait for an incoming connection.  Return a new socket representing the
     |      connection, and the address of the client.  For IP sockets, the address
     |      info is a pair (hostaddr, port).
     |  
     |  bind(...)
     |      bind(address)
     |      
     |      Bind the socket to a local address.  For IP sockets, the address is a
     |      pair (host, port); the host must refer to the local host. For raw packet
     |      sockets the address is a tuple (ifname, proto [,pkttype [,hatype]])
     |  
     |  close(self, _closedsocket=<class 'socket._closedsocket'>, _delegate_methods=('recv', 'recvfrom', 'recv_into', 'recvfrom_into', 'send', 'sendto'), setattr=<built-in function setattr>)
     |      close()
     |      
     |      Close the socket.  It cannot be used after this call.
     |  
     |  connect(...)
     |      connect(address)
     |      
     |      Connect the socket to a remote address.  For IP sockets, the address
     |      is a pair (host, port).
     |  
     |  connect_ex(...)
     |      connect_ex(address) -> errno
     |      
     |      This is like connect(address), but returns an error code (the errno value)
     |      instead of raising an exception when an error occurs.
     |  
     |  dup(self)
     |      dup() -> socket object
     |      
     |      Return a new socket object connected to the same system resource.
     |  
     |  fileno(...)
     |      fileno() -> integer
     |      
     |      Return the integer file descriptor of the socket.
     |  
     |  getpeername(...)
     |      getpeername() -> address info
     |      
     |      Return the address of the remote endpoint.  For IP sockets, the address
     |      info is a pair (hostaddr, port).
     |  
     |  getsockname(...)
     |      getsockname() -> address info
     |      
     |      Return the address of the local endpoint.  For IP sockets, the address
     |      info is a pair (hostaddr, port).
     |  
     |  getsockopt(...)
     |      getsockopt(level, option[, buffersize]) -> value
     |      
     |      Get a socket option.  See the Unix manual for level and option.
     |      If a nonzero buffersize argument is given, the return value is a
     |      string of that length; otherwise it is an integer.
     |  
     |  gettimeout(...)
     |      gettimeout() -> timeout
     |      
     |      Returns the timeout in seconds (float) associated with socket 
     |      operations. A timeout of None indicates that timeouts on socket 
     |      operations are disabled.
     |  
     |  listen(...)
     |      listen(backlog)
     |      
     |      Enable a server to accept connections.  The backlog argument must be at
     |      least 0 (if it is lower, it is set to 0); it specifies the number of
     |      unaccepted connections that the system will allow before refusing new
     |      connections.
     |  
     |  makefile(self, mode='r', bufsize=-1)
     |      makefile([mode[, bufsize]]) -> file object
     |      
     |      Return a regular file object corresponding to the socket.  The mode
     |      and bufsize arguments are as for the built-in open() function.
     |  
     |  sendall(...)
     |      sendall(data[, flags])
     |      
     |      Send a data string to the socket.  For the optional flags
     |      argument, see the Unix manual.  This calls send() repeatedly
     |      until all data is sent.  If an error occurs, it's impossible
     |      to tell how much data has been sent.
     |  
     |  setblocking(...)
     |      setblocking(flag)
     |      
     |      Set the socket to blocking (flag is true) or non-blocking (false).
     |      setblocking(True) is equivalent to settimeout(None);
     |      setblocking(False) is equivalent to settimeout(0.0).
     |  
     |  setsockopt(...)
     |      setsockopt(level, option, value)
     |      
     |      Set a socket option.  See the Unix manual for level and option.
     |      The value argument can either be an integer or a string.
     |  
     |  settimeout(...)
     |      settimeout(timeout)
     |      
     |      Set a timeout on socket operations.  'timeout' can be a float,
     |      giving in seconds, or None.  Setting a timeout of None disables
     |      the timeout feature and is equivalent to setblocking(1).
     |      Setting a timeout of zero is the same as setblocking(0).
     |  
     |  shutdown(...)
     |      shutdown(flag)
     |      
     |      Shut down the reading side of the socket (flag == SHUT_RD), the writing side
     |      of the socket (flag == SHUT_WR), or both ends (flag == SHUT_RDWR).
     |  
     |  ----------------------------------------------------------------------
     |  Data descriptors defined here:
     |  
     |  __weakref__
     |      list of weak references to the object (if defined)
     |  
     |  family
     |      the socket family
     |  
     |  proto
     |      the socket protocol
     |  
     |  recv
     |  
     |  recv_into
     |  
     |  recvfrom
     |  
     |  recvfrom_into
     |  
     |  send
     |  
     |  sendto
     |  
     |  type
     |      the socket type
    
    class error(exceptions.IOError)
     |  Method resolution order:
     |      error
     |      exceptions.IOError
     |      exceptions.EnvironmentError
     |      exceptions.StandardError
     |      exceptions.Exception
     |      exceptions.BaseException
     |      __builtin__.object
     |  
     |  Data descriptors defined here:
     |  
     |  __weakref__
     |      list of weak references to the object (if defined)
     |  
     |  ----------------------------------------------------------------------
     |  Methods inherited from exceptions.IOError:
     |  
     |  __init__(...)
     |      x.__init__(...) initializes x; see help(type(x)) for signature
     |  
     |  ----------------------------------------------------------------------
     |  Data and other attributes inherited from exceptions.IOError:
     |  
     |  __new__ = <built-in method __new__ of type object>
     |      T.__new__(S, ...) -> a new object with type S, a subtype of T
     |  
     |  ----------------------------------------------------------------------
     |  Methods inherited from exceptions.EnvironmentError:
     |  
     |  __reduce__(...)
     |  
     |  __str__(...)
     |      x.__str__() <==> str(x)
     |  
     |  ----------------------------------------------------------------------
     |  Data descriptors inherited from exceptions.EnvironmentError:
     |  
     |  errno
     |      exception errno
     |  
     |  filename
     |      exception filename
     |  
     |  strerror
     |      exception strerror
     |  
     |  ----------------------------------------------------------------------
     |  Methods inherited from exceptions.BaseException:
     |  
     |  __delattr__(...)
     |      x.__delattr__('name') <==> del x.name
     |  
     |  __getattribute__(...)
     |      x.__getattribute__('name') <==> x.name
     |  
     |  __getitem__(...)
     |      x.__getitem__(y) <==> x[y]
     |  
     |  __getslice__(...)
     |      x.__getslice__(i, j) <==> x[i:j]
     |      
     |      Use of negative indices is not supported.
     |  
     |  __repr__(...)
     |      x.__repr__() <==> repr(x)
     |  
     |  __setattr__(...)
     |      x.__setattr__('name', value) <==> x.name = value
     |  
     |  __setstate__(...)
     |  
     |  __unicode__(...)
     |  
     |  ----------------------------------------------------------------------
     |  Data descriptors inherited from exceptions.BaseException:
     |  
     |  __dict__
     |  
     |  args
     |  
     |  message
    
    class gaierror(error)
     |  Method resolution order:
     |      gaierror
     |      error
     |      exceptions.IOError
     |      exceptions.EnvironmentError
     |      exceptions.StandardError
     |      exceptions.Exception
     |      exceptions.BaseException
     |      __builtin__.object
     |  
     |  Data descriptors inherited from error:
     |  
     |  __weakref__
     |      list of weak references to the object (if defined)
     |  
     |  ----------------------------------------------------------------------
     |  Methods inherited from exceptions.IOError:
     |  
     |  __init__(...)
     |      x.__init__(...) initializes x; see help(type(x)) for signature
     |  
     |  ----------------------------------------------------------------------
     |  Data and other attributes inherited from exceptions.IOError:
     |  
     |  __new__ = <built-in method __new__ of type object>
     |      T.__new__(S, ...) -> a new object with type S, a subtype of T
     |  
     |  ----------------------------------------------------------------------
     |  Methods inherited from exceptions.EnvironmentError:
     |  
     |  __reduce__(...)
     |  
     |  __str__(...)
     |      x.__str__() <==> str(x)
     |  
     |  ----------------------------------------------------------------------
     |  Data descriptors inherited from exceptions.EnvironmentError:
     |  
     |  errno
     |      exception errno
     |  
     |  filename
     |      exception filename
     |  
     |  strerror
     |      exception strerror
     |  
     |  ----------------------------------------------------------------------
     |  Methods inherited from exceptions.BaseException:
     |  
     |  __delattr__(...)
     |      x.__delattr__('name') <==> del x.name
     |  
     |  __getattribute__(...)
     |      x.__getattribute__('name') <==> x.name
     |  
     |  __getitem__(...)
     |      x.__getitem__(y) <==> x[y]
     |  
     |  __getslice__(...)
     |      x.__getslice__(i, j) <==> x[i:j]
     |      
     |      Use of negative indices is not supported.
     |  
     |  __repr__(...)
     |      x.__repr__() <==> repr(x)
     |  
     |  __setattr__(...)
     |      x.__setattr__('name', value) <==> x.name = value
     |  
     |  __setstate__(...)
     |  
     |  __unicode__(...)
     |  
     |  ----------------------------------------------------------------------
     |  Data descriptors inherited from exceptions.BaseException:
     |  
     |  __dict__
     |  
     |  args
     |  
     |  message
    
    class herror(error)
     |  Method resolution order:
     |      herror
     |      error
     |      exceptions.IOError
     |      exceptions.EnvironmentError
     |      exceptions.StandardError
     |      exceptions.Exception
     |      exceptions.BaseException
     |      __builtin__.object
     |  
     |  Data descriptors inherited from error:
     |  
     |  __weakref__
     |      list of weak references to the object (if defined)
     |  
     |  ----------------------------------------------------------------------
     |  Methods inherited from exceptions.IOError:
     |  
     |  __init__(...)
     |      x.__init__(...) initializes x; see help(type(x)) for signature
     |  
     |  ----------------------------------------------------------------------
     |  Data and other attributes inherited from exceptions.IOError:
     |  
     |  __new__ = <built-in method __new__ of type object>
     |      T.__new__(S, ...) -> a new object with type S, a subtype of T
     |  
     |  ----------------------------------------------------------------------
     |  Methods inherited from exceptions.EnvironmentError:
     |  
     |  __reduce__(...)
     |  
     |  __str__(...)
     |      x.__str__() <==> str(x)
     |  
     |  ----------------------------------------------------------------------
     |  Data descriptors inherited from exceptions.EnvironmentError:
     |  
     |  errno
     |      exception errno
     |  
     |  filename
     |      exception filename
     |  
     |  strerror
     |      exception strerror
     |  
     |  ----------------------------------------------------------------------
     |  Methods inherited from exceptions.BaseException:
     |  
     |  __delattr__(...)
     |      x.__delattr__('name') <==> del x.name
     |  
     |  __getattribute__(...)
     |      x.__getattribute__('name') <==> x.name
     |  
     |  __getitem__(...)
     |      x.__getitem__(y) <==> x[y]
     |  
     |  __getslice__(...)
     |      x.__getslice__(i, j) <==> x[i:j]
     |      
     |      Use of negative indices is not supported.
     |  
     |  __repr__(...)
     |      x.__repr__() <==> repr(x)
     |  
     |  __setattr__(...)
     |      x.__setattr__('name', value) <==> x.name = value
     |  
     |  __setstate__(...)
     |  
     |  __unicode__(...)
     |  
     |  ----------------------------------------------------------------------
     |  Data descriptors inherited from exceptions.BaseException:
     |  
     |  __dict__
     |  
     |  args
     |  
     |  message
    
    socket = class _socketobject(__builtin__.object)
     |  socket([family[, type[, proto]]]) -> socket object
     |  
     |  Open a socket of the given type.  The family argument specifies the
     |  address family; it defaults to AF_INET.  The type argument specifies
     |  whether this is a stream (SOCK_STREAM, this is the default)
     |  or datagram (SOCK_DGRAM) socket.  The protocol argument defaults to 0,
     |  specifying the default protocol.  Keyword arguments are accepted.
     |  
     |  A socket object represents one endpoint of a network connection.
     |  
     |  Methods of socket objects (keyword arguments not allowed):
     |  
     |  accept() -- accept a connection, returning new socket and client address
     |  bind(addr) -- bind the socket to a local address
     |  close() -- close the socket
     |  connect(addr) -- connect the socket to a remote address
     |  connect_ex(addr) -- connect, return an error code instead of an exception
     |  dup() -- return a new socket object identical to the current one [*]
     |  fileno() -- return underlying file descriptor
     |  getpeername() -- return remote address [*]
     |  getsockname() -- return local address
     |  getsockopt(level, optname[, buflen]) -- get socket options
     |  gettimeout() -- return timeout or None
     |  listen(n) -- start listening for incoming connections
     |  makefile([mode, [bufsize]]) -- return a file object for the socket [*]
     |  recv(buflen[, flags]) -- receive data
     |  recv_into(buffer[, nbytes[, flags]]) -- receive data (into a buffer)
     |  recvfrom(buflen[, flags]) -- receive data and sender's address
     |  recvfrom_into(buffer[, nbytes, [, flags])
     |    -- receive data and sender's address (into a buffer)
     |  sendall(data[, flags]) -- send all data
     |  send(data[, flags]) -- send data, may not send all of it
     |  sendto(data[, flags], addr) -- send data to a given address
     |  setblocking(0 | 1) -- set or clear the blocking I/O flag
     |  setsockopt(level, optname, value) -- set socket options
     |  settimeout(None | float) -- set or clear the timeout
     |  shutdown(how) -- shut down traffic in one or both directions
     |  
     |   [*] not available on all platforms!
     |  
     |  Methods defined here:
     |  
     |  __init__(self, family=2, type=1, proto=0, _sock=None)
     |  
     |  accept(self)
     |      accept() -> (socket object, address info)
     |      
     |      Wait for an incoming connection.  Return a new socket representing the
     |      connection, and the address of the client.  For IP sockets, the address
     |      info is a pair (hostaddr, port).
     |  
     |  bind(...)
     |      bind(address)
     |      
     |      Bind the socket to a local address.  For IP sockets, the address is a
     |      pair (host, port); the host must refer to the local host. For raw packet
     |      sockets the address is a tuple (ifname, proto [,pkttype [,hatype]])
     |  
     |  close(self, _closedsocket=<class 'socket._closedsocket'>, _delegate_methods=('recv', 'recvfrom', 'recv_into', 'recvfrom_into', 'send', 'sendto'), setattr=<built-in function setattr>)
     |      close()
     |      
     |      Close the socket.  It cannot be used after this call.
     |  
     |  connect(...)
     |      connect(address)
     |      
     |      Connect the socket to a remote address.  For IP sockets, the address
     |      is a pair (host, port).
     |  
     |  connect_ex(...)
     |      connect_ex(address) -> errno
     |      
     |      This is like connect(address), but returns an error code (the errno value)
     |      instead of raising an exception when an error occurs.
     |  
     |  dup(self)
     |      dup() -> socket object
     |      
     |      Return a new socket object connected to the same system resource.
     |  
     |  fileno(...)
     |      fileno() -> integer
     |      
     |      Return the integer file descriptor of the socket.
     |  
     |  getpeername(...)
     |      getpeername() -> address info
     |      
     |      Return the address of the remote endpoint.  For IP sockets, the address
     |      info is a pair (hostaddr, port).
     |  
     |  getsockname(...)
     |      getsockname() -> address info
     |      
     |      Return the address of the local endpoint.  For IP sockets, the address
     |      info is a pair (hostaddr, port).
     |  
     |  getsockopt(...)
     |      getsockopt(level, option[, buffersize]) -> value
     |      
     |      Get a socket option.  See the Unix manual for level and option.
     |      If a nonzero buffersize argument is given, the return value is a
     |      string of that length; otherwise it is an integer.
     |  
     |  gettimeout(...)
     |      gettimeout() -> timeout
     |      
     |      Returns the timeout in seconds (float) associated with socket 
     |      operations. A timeout of None indicates that timeouts on socket 
     |      operations are disabled.
     |  
     |  listen(...)
     |      listen(backlog)
     |      
     |      Enable a server to accept connections.  The backlog argument must be at
     |      least 0 (if it is lower, it is set to 0); it specifies the number of
     |      unaccepted connections that the system will allow before refusing new
     |      connections.
     |  
     |  makefile(self, mode='r', bufsize=-1)
     |      makefile([mode[, bufsize]]) -> file object
     |      
     |      Return a regular file object corresponding to the socket.  The mode
     |      and bufsize arguments are as for the built-in open() function.
     |  
     |  sendall(...)
     |      sendall(data[, flags])
     |      
     |      Send a data string to the socket.  For the optional flags
     |      argument, see the Unix manual.  This calls send() repeatedly
     |      until all data is sent.  If an error occurs, it's impossible
     |      to tell how much data has been sent.
     |  
     |  setblocking(...)
     |      setblocking(flag)
     |      
     |      Set the socket to blocking (flag is true) or non-blocking (false).
     |      setblocking(True) is equivalent to settimeout(None);
     |      setblocking(False) is equivalent to settimeout(0.0).
     |  
     |  setsockopt(...)
     |      setsockopt(level, option, value)
     |      
     |      Set a socket option.  See the Unix manual for level and option.
     |      The value argument can either be an integer or a string.
     |  
     |  settimeout(...)
     |      settimeout(timeout)
     |      
     |      Set a timeout on socket operations.  'timeout' can be a float,
     |      giving in seconds, or None.  Setting a timeout of None disables
     |      the timeout feature and is equivalent to setblocking(1).
     |      Setting a timeout of zero is the same as setblocking(0).
     |  
     |  shutdown(...)
     |      shutdown(flag)
     |      
     |      Shut down the reading side of the socket (flag == SHUT_RD), the writing side
     |      of the socket (flag == SHUT_WR), or both ends (flag == SHUT_RDWR).
     |  
     |  ----------------------------------------------------------------------
     |  Data descriptors defined here:
     |  
     |  __weakref__
     |      list of weak references to the object (if defined)
     |  
     |  family
     |      the socket family
     |  
     |  proto
     |      the socket protocol
     |  
     |  recv
     |  
     |  recv_into
     |  
     |  recvfrom
     |  
     |  recvfrom_into
     |  
     |  send
     |  
     |  sendto
     |  
     |  type
     |      the socket type
    
    class timeout(error)
     |  Method resolution order:
     |      timeout
     |      error
     |      exceptions.IOError
     |      exceptions.EnvironmentError
     |      exceptions.StandardError
     |      exceptions.Exception
     |      exceptions.BaseException
     |      __builtin__.object
     |  
     |  Data descriptors inherited from error:
     |  
     |  __weakref__
     |      list of weak references to the object (if defined)
     |  
     |  ----------------------------------------------------------------------
     |  Methods inherited from exceptions.IOError:
     |  
     |  __init__(...)
     |      x.__init__(...) initializes x; see help(type(x)) for signature
     |  
     |  ----------------------------------------------------------------------
     |  Data and other attributes inherited from exceptions.IOError:
     |  
     |  __new__ = <built-in method __new__ of type object>
     |      T.__new__(S, ...) -> a new object with type S, a subtype of T
     |  
     |  ----------------------------------------------------------------------
     |  Methods inherited from exceptions.EnvironmentError:
     |  
     |  __reduce__(...)
     |  
     |  __str__(...)
     |      x.__str__() <==> str(x)
     |  
     |  ----------------------------------------------------------------------
     |  Data descriptors inherited from exceptions.EnvironmentError:
     |  
     |  errno
     |      exception errno
     |  
     |  filename
     |      exception filename
     |  
     |  strerror
     |      exception strerror
     |  
     |  ----------------------------------------------------------------------
     |  Methods inherited from exceptions.BaseException:
     |  
     |  __delattr__(...)
     |      x.__delattr__('name') <==> del x.name
     |  
     |  __getattribute__(...)
     |      x.__getattribute__('name') <==> x.name
     |  
     |  __getitem__(...)
     |      x.__getitem__(y) <==> x[y]
     |  
     |  __getslice__(...)
     |      x.__getslice__(i, j) <==> x[i:j]
     |      
     |      Use of negative indices is not supported.
     |  
     |  __repr__(...)
     |      x.__repr__() <==> repr(x)
     |  
     |  __setattr__(...)
     |      x.__setattr__('name', value) <==> x.name = value
     |  
     |  __setstate__(...)
     |  
     |  __unicode__(...)
     |  
     |  ----------------------------------------------------------------------
     |  Data descriptors inherited from exceptions.BaseException:
     |  
     |  __dict__
     |  
     |  args
     |  
     |  message

FUNCTIONS
    create_connection(address, timeout=<object object>, source_address=None)
        Connect to *address* and return the socket object.
        
        Convenience function.  Connect to *address* (a 2-tuple ``(host,
        port)``) and return the socket object.  Passing the optional
        *timeout* parameter will set the timeout on the socket instance
        before attempting to connect.  If no *timeout* is supplied, the
        global default timeout setting returned by :func:`getdefaulttimeout`
        is used.  If *source_address* is set it must be a tuple of (host, port)
        for the socket to bind as a source address before making the connection.
        An host of '' or port 0 tells the OS to use the default.
    
    fromfd(...)
        fromfd(fd, family, type[, proto]) -> socket object
        
        Create a socket object from a duplicate of the given
        file descriptor.
        The remaining arguments are the same as for socket().
    
    getaddrinfo(...)
        getaddrinfo(host, port [, family, socktype, proto, flags])
            -> list of (family, socktype, proto, canonname, sockaddr)
        
        Resolve host and port into addrinfo struct.
    
    getdefaulttimeout(...)
        getdefaulttimeout() -> timeout
        
        Returns the default timeout in seconds (float) for new socket objects.
        A value of None indicates that new socket objects have no timeout.
        When the socket module is first imported, the default is None.
    
    getfqdn(name='')
        Get fully qualified domain name from name.
        
        An empty argument is interpreted as meaning the local host.
        
        First the hostname returned by gethostbyaddr() is checked, then
        possibly existing aliases. In case no FQDN is available, hostname
        from gethostname() is returned.
    
    gethostbyaddr(...)
        gethostbyaddr(host) -> (name, aliaslist, addresslist)
        
        Return the true host name, a list of aliases, and a list of IP addresses,
        for a host.  The host argument is a string giving a host name or IP number.
    
    gethostbyname(...)
        gethostbyname(host) -> address
        
        Return the IP address (a string of the form '255.255.255.255') for a host.
    
    gethostbyname_ex(...)
        gethostbyname_ex(host) -> (name, aliaslist, addresslist)
        
        Return the true host name, a list of aliases, and a list of IP addresses,
        for a host.  The host argument is a string giving a host name or IP number.
    
    gethostname(...)
        gethostname() -> string
        
        Return the current host name.
    
    getnameinfo(...)
        getnameinfo(sockaddr, flags) --> (host, port)
        
        Get host and port for a sockaddr.
    
    getprotobyname(...)
        getprotobyname(name) -> integer
        
        Return the protocol number for the named protocol.  (Rarely used.)
    
    getservbyname(...)
        getservbyname(servicename[, protocolname]) -> integer
        
        Return a port number from a service name and protocol name.
        The optional protocol name, if given, should be 'tcp' or 'udp',
        otherwise any protocol will match.
    
    getservbyport(...)
        getservbyport(port[, protocolname]) -> string
        
        Return the service name from a port number and protocol name.
        The optional protocol name, if given, should be 'tcp' or 'udp',
        otherwise any protocol will match.
    
    htonl(...)
        htonl(integer) -> integer
        
        Convert a 32-bit integer from host to network byte order.
    
    htons(...)
        htons(integer) -> integer
        
        Convert a 16-bit integer from host to network byte order.
    
    inet_aton(...)
        inet_aton(string) -> packed 32-bit IP representation
        
        Convert an IP address in string format (123.45.67.89) to the 32-bit packed
        binary format used in low-level network functions.
    
    inet_ntoa(...)
        inet_ntoa(packed_ip) -> ip_address_string
        
        Convert an IP address from 32-bit packed binary format to string format
    
    inet_ntop(...)
        inet_ntop(af, packed_ip) -> string formatted IP address
        
        Convert a packed IP address of the given family to string format.
    
    inet_pton(...)
        inet_pton(af, ip) -> packed IP address string
        
        Convert an IP address from string format to a packed string suitable
        for use with low-level network functions.
    
    ntohl(...)
        ntohl(integer) -> integer
        
        Convert a 32-bit integer from network to host byte order.
    
    ntohs(...)
        ntohs(integer) -> integer
        
        Convert a 16-bit integer from network to host byte order.
    
    setdefaulttimeout(...)
        setdefaulttimeout(timeout)
        
        Set the default timeout in seconds (float) for new socket objects.
        A value of None indicates that new socket objects have no timeout.
        When the socket module is first imported, the default is None.
    
    socketpair(...)
        socketpair([family[, type[, proto]]]) -> (socket object, socket object)
        
        Create a pair of socket objects from the sockets returned by the platform
        socketpair() function.
        The arguments are the same as for socket() except the default family is
        AF_UNIX if defined on the platform; otherwise, the default is AF_INET.

DATA
    AF_APPLETALK = 5
    AF_ASH = 18
    AF_ATMPVC = 8
    AF_ATMSVC = 20
    AF_AX25 = 3
    AF_BLUETOOTH = 31
    AF_BRIDGE = 7
    AF_DECnet = 12
    AF_ECONET = 19
    AF_INET = 2
    AF_INET6 = 10
    AF_IPX = 4
    AF_IRDA = 23
    AF_KEY = 15
    AF_LLC = 26
    AF_NETBEUI = 13
    AF_NETLINK = 16
    AF_NETROM = 6
    AF_PACKET = 17
    AF_PPPOX = 24
    AF_ROSE = 11
    AF_ROUTE = 16
    AF_SECURITY = 14
    AF_SNA = 22
    AF_TIPC = 30
    AF_UNIX = 1
    AF_UNSPEC = 0
    AF_WANPIPE = 25
    AF_X25 = 9
    AI_ADDRCONFIG = 32
    AI_ALL = 16
    AI_CANONNAME = 2
    AI_NUMERICHOST = 4
    AI_NUMERICSERV = 1024
    AI_PASSIVE = 1
    AI_V4MAPPED = 8
    BDADDR_ANY = '00:00:00:00:00:00'
    BDADDR_LOCAL = '00:00:00:FF:FF:FF'
    BTPROTO_HCI = 1
    BTPROTO_L2CAP = 0
    BTPROTO_RFCOMM = 3
    BTPROTO_SCO = 2
    CAPI = <capsule object "_socket.CAPI">
    EAI_ADDRFAMILY = -9
    EAI_AGAIN = -3
    EAI_BADFLAGS = -1
    EAI_FAIL = -4
    EAI_FAMILY = -6
    EAI_MEMORY = -10
    EAI_NODATA = -5
    EAI_NONAME = -2
    EAI_OVERFLOW = -12
    EAI_SERVICE = -8
    EAI_SOCKTYPE = -7
    EAI_SYSTEM = -11
    HCI_DATA_DIR = 1
    HCI_FILTER = 2
    HCI_TIME_STAMP = 3
    INADDR_ALLHOSTS_GROUP = -536870911
    INADDR_ANY = 0
    INADDR_BROADCAST = -1
    INADDR_LOOPBACK = 2130706433
    INADDR_MAX_LOCAL_GROUP = -536870657
    INADDR_NONE = -1
    INADDR_UNSPEC_GROUP = -536870912
    IPPORT_RESERVED = 1024
    IPPORT_USERRESERVED = 5000
    IPPROTO_AH = 51
    IPPROTO_DSTOPTS = 60
    IPPROTO_EGP = 8
    IPPROTO_ESP = 50
    IPPROTO_FRAGMENT = 44
    IPPROTO_GRE = 47
    IPPROTO_HOPOPTS = 0
    IPPROTO_ICMP = 1
    IPPROTO_ICMPV6 = 58
    IPPROTO_IDP = 22
    IPPROTO_IGMP = 2
    IPPROTO_IP = 0
    IPPROTO_IPIP = 4
    IPPROTO_IPV6 = 41
    IPPROTO_NONE = 59
    IPPROTO_PIM = 103
    IPPROTO_PUP = 12
    IPPROTO_RAW = 255
    IPPROTO_ROUTING = 43
    IPPROTO_RSVP = 46
    IPPROTO_TCP = 6
    IPPROTO_TP = 29
    IPPROTO_UDP = 17
    IPV6_CHECKSUM = 7
    IPV6_DSTOPTS = 59
    IPV6_HOPLIMIT = 52
    IPV6_HOPOPTS = 54
    IPV6_JOIN_GROUP = 20
    IPV6_LEAVE_GROUP = 21
    IPV6_MULTICAST_HOPS = 18
    IPV6_MULTICAST_IF = 17
    IPV6_MULTICAST_LOOP = 19
    IPV6_NEXTHOP = 9
    IPV6_PKTINFO = 50
    IPV6_RECVDSTOPTS = 58
    IPV6_RECVHOPLIMIT = 51
    IPV6_RECVHOPOPTS = 53
    IPV6_RECVPKTINFO = 49
    IPV6_RECVRTHDR = 56
    IPV6_RECVTCLASS = 66
    IPV6_RTHDR = 57
    IPV6_RTHDRDSTOPTS = 55
    IPV6_RTHDR_TYPE_0 = 0
    IPV6_TCLASS = 67
    IPV6_UNICAST_HOPS = 16
    IPV6_V6ONLY = 26
    IP_ADD_MEMBERSHIP = 35
    IP_DEFAULT_MULTICAST_LOOP = 1
    IP_DEFAULT_MULTICAST_TTL = 1
    IP_DROP_MEMBERSHIP = 36
    IP_HDRINCL = 3
    IP_MAX_MEMBERSHIPS = 20
    IP_MULTICAST_IF = 32
    IP_MULTICAST_LOOP = 34
    IP_MULTICAST_TTL = 33
    IP_OPTIONS = 4
    IP_RECVOPTS = 6
    IP_RECVRETOPTS = 7
    IP_RETOPTS = 7
    IP_TOS = 1
    IP_TTL = 2
    MSG_CTRUNC = 8
    MSG_DONTROUTE = 4
    MSG_DONTWAIT = 64
    MSG_EOR = 128
    MSG_OOB = 1
    MSG_PEEK = 2
    MSG_TRUNC = 32
    MSG_WAITALL = 256
    NETLINK_DNRTMSG = 14
    NETLINK_FIREWALL = 3
    NETLINK_IP6_FW = 13
    NETLINK_NFLOG = 5
    NETLINK_ROUTE = 0
    NETLINK_USERSOCK = 2
    NETLINK_XFRM = 6
    NI_DGRAM = 16
    NI_MAXHOST = 1025
    NI_MAXSERV = 32
    NI_NAMEREQD = 8
    NI_NOFQDN = 4
    NI_NUMERICHOST = 1
    NI_NUMERICSERV = 2
    PACKET_BROADCAST = 1
    PACKET_FASTROUTE = 6
    PACKET_HOST = 0
    PACKET_LOOPBACK = 5
    PACKET_MULTICAST = 2
    PACKET_OTHERHOST = 3
    PACKET_OUTGOING = 4
    PF_PACKET = 17
    SHUT_RD = 0
    SHUT_RDWR = 2
    SHUT_WR = 1
    SOCK_DGRAM = 2
    SOCK_RAW = 3
    SOCK_RDM = 4
    SOCK_SEQPACKET = 5
    SOCK_STREAM = 1
    SOL_HCI = 0
    SOL_IP = 0
    SOL_SOCKET = 1
    SOL_TCP = 6
    SOL_TIPC = 271
    SOL_UDP = 17
    SOMAXCONN = 128
    SO_ACCEPTCONN = 30
    SO_BROADCAST = 6
    SO_DEBUG = 1
    SO_DONTROUTE = 5
    SO_ERROR = 4
    SO_KEEPALIVE = 9
    SO_LINGER = 13
    SO_OOBINLINE = 10
    SO_RCVBUF = 8
    SO_RCVLOWAT = 18
    SO_RCVTIMEO = 20
    SO_REUSEADDR = 2
    SO_SNDBUF = 7
    SO_SNDLOWAT = 19
    SO_SNDTIMEO = 21
    SO_TYPE = 3
    TCP_CORK = 3
    TCP_DEFER_ACCEPT = 9
    TCP_INFO = 11
    TCP_KEEPCNT = 6
    TCP_KEEPIDLE = 4
    TCP_KEEPINTVL = 5
    TCP_LINGER2 = 8
    TCP_MAXSEG = 2
    TCP_NODELAY = 1
    TCP_QUICKACK = 12
    TCP_SYNCNT = 7
    TCP_WINDOW_CLAMP = 10
    TIPC_ADDR_ID = 3
    TIPC_ADDR_NAME = 2
    TIPC_ADDR_NAMESEQ = 1
    TIPC_CFG_SRV = 0
    TIPC_CLUSTER_SCOPE = 2
    TIPC_CONN_TIMEOUT = 130
    TIPC_CRITICAL_IMPORTANCE = 3
    TIPC_DEST_DROPPABLE = 129
    TIPC_HIGH_IMPORTANCE = 2
    TIPC_IMPORTANCE = 127
    TIPC_LOW_IMPORTANCE = 0
    TIPC_MEDIUM_IMPORTANCE = 1
    TIPC_NODE_SCOPE = 3
    TIPC_PUBLISHED = 1
    TIPC_SRC_DROPPABLE = 128
    TIPC_SUBSCR_TIMEOUT = 3
    TIPC_SUB_CANCEL = 4
    TIPC_SUB_PORTS = 1
    TIPC_SUB_SERVICE = 2
    TIPC_TOP_SRV = 1
    TIPC_WAIT_FOREVER = -1
    TIPC_WITHDRAWN = 2
    TIPC_ZONE_SCOPE = 1
    __all__ = ['getfqdn', 'create_connection', 'AF_APPLETALK', 'AF_ASH', '...
    has_ipv6 = True



In [7]:
%load http://socksipy.sourceforge.net/readme.txt
In []:
SocksiPy version 1.00
A Python SOCKS module.
(C) 2006 Dan-Haim. All rights reserved.
See LICENSE file for details.


WHAT IS A SOCKS PROXY?
A SOCKS proxy is a proxy server at the TCP level. In other words, it acts as
a tunnel, relaying all traffic going through it without modifying it.
SOCKS proxies can be used to relay traffic using any network protocol that
uses TCP.

WHAT IS SOCKSIPY?
This Python module allows you to create TCP connections through a SOCKS
proxy without any special effort.

PROXY COMPATIBILITY
SocksiPy is compatible with three different types of proxies:
1. SOCKS Version 4 (Socks4), including the Socks4a extension.
2. SOCKS Version 5 (Socks5).
3. HTTP Proxies which support tunneling using the CONNECT method.

SYSTEM REQUIREMENTS
Being written in Python, SocksiPy can run on any platform that has a Python
interpreter and TCP/IP support.
This module has been tested with Python 2.3 and should work with greater versions
just as well.


INSTALLATION
-------------

Simply copy the file "socks.py" to your Python's lib/site-packages directory,
and you're ready to go.


USAGE
------

First load the socks module with the command:

>>> import socks
>>>

The socks module provides a class called "socksocket", which is the base to
all of the module's functionality.
The socksocket object has the same initialization parameters as the normal socket
object to ensure maximal compatibility, however it should be noted that socksocket
will only function with family being AF_INET and type being SOCK_STREAM.
Generally, it is best to initialize the socksocket object with no parameters

>>> s = socks.socksocket()
>>>

The socksocket object has an interface which is very similiar to socket's (in fact
the socksocket class is derived from socket) with a few extra methods.
To select the proxy server you would like to use, use the setproxy method, whose
syntax is:

setproxy(proxytype, addr[, port[, rdns[, username[, password]]]])

Explaination of the parameters:

proxytype - The type of the proxy server. This can be one of three possible
choices: PROXY_TYPE_SOCKS4, PROXY_TYPE_SOCKS5 and PROXY_TYPE_HTTP for Socks4,
Socks5 and HTTP servers respectively.

addr - The IP address or DNS name of the proxy server.

port - The port of the proxy server. Defaults to 1080 for socks and 8080 for http.

rdns - This is a boolean flag than modifies the behavior regarding DNS resolving.
If it is set to True, DNS resolving will be preformed remotely, on the server.
If it is set to False, DNS resolving will be preformed locally. Please note that
setting this to True with Socks4 servers actually use an extension to the protocol,
called Socks4a, which may not be supported on all servers (Socks5 and http servers
always support DNS). The default is True.

username - For Socks5 servers, this allows simple username / password authentication
with the server. For Socks4 servers, this parameter will be sent as the userid.
This parameter is ignored if an HTTP server is being used. If it is not provided,
authentication will not be used (servers may accept unauthentication requests).

password - This parameter is valid only for Socks5 servers and specifies the
respective password for the username provided.

Example of usage:

>>> s.setproxy(socks.PROXY_TYPE_SOCKS5,"socks.example.com")
>>>

After the setproxy method has been called, simply call the connect method with the
traditional parameters to establish a connection through the proxy:

>>> s.connect(("www.sourceforge.net",80))
>>>

Connection will take a bit longer to allow negotiation with the proxy server.
Please note that calling connect without calling setproxy earlier will connect
without a proxy (just like a regular socket).

Errors: Any errors in the connection process will trigger exceptions. The exception
may either be generated by the underlying socket layer or may be custom module
exceptions, whose details follow:

class ProxyError - This is a base exception class. It is not raised directly but
rather all other exception classes raised by this module are derived from it.
This allows an easy way to catch all proxy-related errors.

class GeneralProxyError - When thrown, it indicates a problem which does not fall
into another category. The parameter is a tuple containing an error code and a
description of the error, from the following list:
1 - invalid data - This error means that unexpected data has been received from
the server. The most common reason is that the server specified as the proxy is
not really a Socks4/Socks5/HTTP proxy, or maybe the proxy type specified is wrong.
4 - bad proxy type - This will be raised if the type of the proxy supplied to the
setproxy function was not PROXY_TYPE_SOCKS4/PROXY_TYPE_SOCKS5/PROXY_TYPE_HTTP.
5 - bad input - This will be raised if the connect method is called with bad input
parameters.

class Socks5AuthError - This indicates that the connection through a Socks5 server
failed due to an authentication problem. The parameter is a tuple containing a
code and a description message according to the following list:

1 - authentication is required - This will happen if you use a Socks5 server which
requires authentication without providing a username / password at all.
2 - all offered authentication methods were rejected - This will happen if the proxy
requires a special authentication method which is not supported by this module.
3 - unknown username or invalid password - Self descriptive.

class Socks5Error - This will be raised for Socks5 errors which are not related to
authentication. The parameter is a tuple containing a code and a description of the
error, as given by the server. The possible errors, according to the RFC are:

1 - General SOCKS server failure - If for any reason the proxy server is unable to
fulfill your request (internal server error).
2 - connection not allowed by ruleset - If the address you're trying to connect to
is blacklisted on the server or requires authentication.
3 - Network unreachable - The target could not be contacted. A router on the network
had replied with a destination net unreachable error.
4 - Host unreachable - The target could not be contacted. A router on the network
had replied with a destination host unreachable error.
5 - Connection refused - The target server has actively refused the connection
(the requested port is closed).
6 - TTL expired - The TTL value of the SYN packet from the proxy to the target server
has expired. This usually means that there are network problems causing the packet
to be caught in a router-to-router "ping-pong".
7 - Command not supported - The client has issued an invalid command. When using this
module, this error should not occur.
8 - Address type not supported - The client has provided an invalid address type.
When using this module, this error should not occur.

class Socks4Error - This will be raised for Socks4 errors. The parameter is a tuple
containing a code and a description of the error, as given by the server. The
possible error, according to the specification are:

1 - Request rejected or failed - Will be raised in the event of an failure for any
reason other then the two mentioned next.
2 - request rejected because SOCKS server cannot connect to identd on the client -
The Socks server had tried an ident lookup on your computer and has failed. In this
case you should run an identd server and/or configure your firewall to allow incoming
connections to local port 113 from the remote server.
3 - request rejected because the client program and identd report different user-ids - 
The Socks server had performed an ident lookup on your computer and has received a
different userid than the one you have provided. Change your userid (through the
username parameter of the setproxy method) to match and try again.

class HTTPError - This will be raised for HTTP errors. The parameter is a tuple
containing the HTTP status code and the description of the server.


After establishing the connection, the object behaves like a standard socket.
Call the close method to close the connection.

In addition to the socksocket class, an additional function worth mentioning is the
setdefaultproxy function. The parameters are the same as the setproxy method.
This function will set default proxy settings for newly created socksocket objects,
in which the proxy settings haven't been changed via the setproxy method.
This is quite useful if you wish to force 3rd party modules to use a socks proxy,
by overriding the socket object.
For example:

>>> socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5,"socks.example.com")
>>> socket.socket = socks.socksocket
>>> urllib.urlopen("http://www.sourceforge.net/")


PROBLEMS
---------

If you have any problems using this module, please first refer to the BUGS file
(containing current bugs and issues). If your problem is not mentioned you may
contact the author at the following E-Mail address:

negativeiq@users.sourceforge.net

Please allow some time for your question to be received and handled.


Dan-Haim,
Author.


Посты чуть ниже также могут вас заинтересовать

Комментариев нет:

Отправить комментарий