gevent._socket2 – Python 2 socket module

class socket(family=<AddressFamily.AF_INET: 2>, type=<SocketKind.SOCK_STREAM: 1>, proto=0, _sock=None)

Bases: object

gevent socket.socket for Python 2.

This object should have the same API as the standard library socket linked to above. Not all methods are specifically documented here; when they are they may point out a difference to be aware of or may document a method the standard library does not.

dup() → socket object

Return a new socket object connected to the same system resource. Note, that the new socket does not inherit the timeout.

SocketType

alias of socket

getaddrinfo(host, port, family=0, type=0, proto=0, flags=0)

Resolve host and port into list of address info entries.

Translate the host/port argument into a sequence of 5-tuples that contain all the necessary arguments for creating a socket connected to that service. host is a domain name, a string representation of an IPv4/v6 address or None. port is a string service name such as ‘http’, a numeric port number or None. By passing None as the value of host and port, you can pass NULL to the underlying C API.

The family, type and proto arguments can be optionally specified in order to narrow the list of addresses returned. Passing zero as a value for each of these arguments selects the full range of results.

gethostbyname(host) → address

Return the IP address (a string of the form ‘255.255.255.255’) for a host.

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. Resolve host and port into list of address info entries.

gethostbyaddr(ip_address) -> (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.

getnameinfo(sockaddr, flags) -> (host, port)

Get host and port for a sockaddr.

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.

error

alias of OSError

htonl(integer) → integer

Convert a 32-bit integer from host to network byte order.

htons(integer) → integer

Convert a 16-bit integer from host to network byte order.

ntohl(integer) → integer

Convert a 32-bit integer from network to host byte order.

ntohs(integer) → integer

Convert a 16-bit integer from network to host byte order.

inet_aton(string) → bytes giving 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(packed_ip) → ip_address_string

Convert an IP address from 32-bit packed binary format to string format

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.

inet_ntop(af, packed_ip) → string formatted IP address

Convert a packed IP address of the given family to string format.

gethostname() → string

Return the current host name.

getprotobyname(name) → integer

Return the protocol number for the named protocol. (Rarely used.)

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(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.

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.

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.

Next page: gevent.ssl – Secure Sockets Layer (SSL/TLS) module