Back to index

python3.2  3.2.2
Classes | Functions | Variables
socket Namespace Reference

Classes

class  socket
class  SocketIO

Functions

def fromfd
def socketpair
def getfqdn
def create_connection

Variables

 errno = None
tuple EBADF = getattr(errno, 'EBADF', 9)
tuple EINTR = getattr(errno, 'EINTR', 4)
tuple EAGAIN = getattr(errno, 'EAGAIN', 11)
tuple EWOULDBLOCK = getattr(errno, 'EWOULDBLOCK', 11)
list __all__ = ["getfqdn", "create_connection"]
 _realsocket = socket
dictionary errorTab = {}
dictionary _blocking_errnos = { EAGAIN, EWOULDBLOCK }
tuple _GLOBAL_DEFAULT_TIMEOUT = object()

Function Documentation

def socket.create_connection (   address,
  timeout = _GLOBAL_DEFAULT_TIMEOUT,
  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.

Definition at line 371 of file socket.py.

00371 
00372                       source_address=None):
00373     """Connect to *address* and return the socket object.
00374 
00375     Convenience function.  Connect to *address* (a 2-tuple ``(host,
00376     port)``) and return the socket object.  Passing the optional
00377     *timeout* parameter will set the timeout on the socket instance
00378     before attempting to connect.  If no *timeout* is supplied, the
00379     global default timeout setting returned by :func:`getdefaulttimeout`
00380     is used.  If *source_address* is set it must be a tuple of (host, port)
00381     for the socket to bind as a source address before making the connection.
00382     An host of '' or port 0 tells the OS to use the default.
00383     """
00384 
00385     host, port = address
00386     err = None
00387     for res in getaddrinfo(host, port, 0, SOCK_STREAM):
00388         af, socktype, proto, canonname, sa = res
00389         sock = None
00390         try:
00391             sock = socket(af, socktype, proto)
00392             if timeout is not _GLOBAL_DEFAULT_TIMEOUT:
00393                 sock.settimeout(timeout)
00394             if source_address:
00395                 sock.bind(source_address)
00396             sock.connect(sa)
00397             return sock
00398 
00399         except error as _:
00400             err = _
00401             if sock is not None:
00402                 sock.close()
00403 
00404     if err is not None:
00405         raise err
00406     else:
00407         raise error("getaddrinfo returns an empty list")

Here is the call graph for this function:

Here is the caller graph for this function:

def socket.fromfd (   fd,
  family,
  type,
  proto = 0 
)
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().

Definition at line 200 of file socket.py.

00200 
00201 def fromfd(fd, family, type, proto=0):
00202     """ fromfd(fd, family, type[, proto]) -> socket object
00203 
00204     Create a socket object from a duplicate of the given file
00205     descriptor.  The remaining arguments are the same as for socket().
00206     """
00207     nfd = dup(fd)
00208     return socket(family, type, proto, nfd)
00209 

Here is the caller graph for this function:

def socket.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.

Definition at line 342 of file socket.py.

00342 
00343 def getfqdn(name=''):
00344     """Get fully qualified domain name from name.
00345 
00346     An empty argument is interpreted as meaning the local host.
00347 
00348     First the hostname returned by gethostbyaddr() is checked, then
00349     possibly existing aliases. In case no FQDN is available, hostname
00350     from gethostname() is returned.
00351     """
00352     name = name.strip()
00353     if not name or name == '0.0.0.0':
00354         name = gethostname()
00355     try:
00356         hostname, aliases, ipaddrs = gethostbyaddr(name)
00357     except error:
00358         pass
00359     else:
00360         aliases.insert(0, hostname)
00361         for name in aliases:
00362             if '.' in name:
00363                 break
00364         else:
00365             name = hostname
00366     return name
00367 

Here is the call graph for this function:

Here is the caller graph for this function:

def socket.socketpair (   family = None,
  type = SOCK_STREAM,
  proto = 0 
)
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.

Definition at line 212 of file socket.py.

00212 
00213     def socketpair(family=None, type=SOCK_STREAM, proto=0):
00214         """socketpair([family[, type[, proto]]]) -> (socket object, socket object)
00215 
00216         Create a pair of socket objects from the sockets returned by the platform
00217         socketpair() function.
00218         The arguments are the same as for socket() except the default family is
00219         AF_UNIX if defined on the platform; otherwise, the default is AF_INET.
00220         """
00221         if family is None:
00222             try:
00223                 family = AF_UNIX
00224             except NameError:
00225                 family = AF_INET
00226         a, b = _socket.socketpair(family, type, proto)
00227         a = socket(family, type, proto, a.detach())
00228         b = socket(family, type, proto, b.detach())
00229         return a, b
00230 

Here is the caller graph for this function:


Variable Documentation

list socket.__all__ = ["getfqdn", "create_connection"]

Definition at line 60 of file socket.py.

Definition at line 231 of file socket.py.

Definition at line 368 of file socket.py.

Definition at line 64 of file socket.py.

tuple socket.EAGAIN = getattr(errno, 'EAGAIN', 11)

Definition at line 57 of file socket.py.

tuple socket.EBADF = getattr(errno, 'EBADF', 9)

Definition at line 55 of file socket.py.

tuple socket.EINTR = getattr(errno, 'EINTR', 4)

Definition at line 56 of file socket.py.

socket.errno = None

Definition at line 54 of file socket.py.

Definition at line 68 of file socket.py.

Definition at line 58 of file socket.py.