Whitespace normalization, folding long lines, uniform comment

delimiters.  Also repaired some docstrings and comments.
This commit is contained in:
Guido van Rossum 2002-06-07 02:08:35 +00:00
parent b9e916a0b5
commit 3eede5ad81

View file

@ -106,7 +106,8 @@ Socket methods:
# endif
#endif
#if !defined(HAVE_GETHOSTBYNAME_R) && defined(WITH_THREAD) && !defined(MS_WINDOWS)
#if !defined(HAVE_GETHOSTBYNAME_R) && defined(WITH_THREAD) && \
!defined(MS_WINDOWS)
# define USE_GETHOSTBYNAME_LOCK
#endif
@ -260,8 +261,10 @@ PySocket_Err(void)
{
#ifdef MS_WINDOWS
int err_no = WSAGetLastError();
if (err_no) {
static struct { int no; const char *msg; } *msgp, msgs[] = {
static struct {
int no;
const char *msg;
} *msgp, msgs[] = {
{WSAEINTR, "Interrupted system call"},
{WSAEBADF, "Bad file descriptor"},
{WSAEACCES, "Permission denied"},
@ -284,21 +287,17 @@ PySocket_Err(void)
{WSAEPFNOSUPPORT, "Protocol family not supported"},
{WSAEAFNOSUPPORT, "Address family not supported"},
{WSAEADDRINUSE, "Address already in use"},
{ WSAEADDRNOTAVAIL,
"Can't assign requested address" },
{WSAEADDRNOTAVAIL, "Can't assign requested address"},
{WSAENETDOWN, "Network is down"},
{WSAENETUNREACH, "Network is unreachable"},
{ WSAENETRESET,
"Network dropped connection on reset" },
{ WSAECONNABORTED,
"Software caused connection abort" },
{WSAENETRESET, "Network dropped connection on reset"},
{WSAECONNABORTED, "Software caused connection abort"},
{WSAECONNRESET, "Connection reset by peer"},
{WSAENOBUFS, "No buffer space available"},
{WSAEISCONN, "Socket is already connected"},
{WSAENOTCONN, "Socket is not connected"},
{WSAESHUTDOWN, "Can't send after socket shutdown"},
{ WSAETOOMANYREFS,
"Too many references: can't splice" },
{WSAETOOMANYREFS, "Too many references: can't splice"},
{WSAETIMEDOUT, "Operation timed out"},
{WSAECONNREFUSED, "Connection refused"},
{WSAELOOP, "Too many levels of symbolic links"},
@ -311,22 +310,20 @@ PySocket_Err(void)
{WSAEDQUOT, "Disc quota exceeded"},
{WSAESTALE, "Stale NFS file handle"},
{WSAEREMOTE, "Too many levels of remote in path"},
{ WSASYSNOTREADY,
"Network subsystem is unvailable" },
{ WSAVERNOTSUPPORTED,
"WinSock version is not supported" },
{WSASYSNOTREADY, "Network subsystem is unvailable"},
{WSAVERNOTSUPPORTED, "WinSock version is not supported"},
{WSANOTINITIALISED,
"Successful WSAStartup() not yet performed"},
{WSAEDISCON, "Graceful shutdown in progress"},
/* Resolver errors */
{WSAHOST_NOT_FOUND, "No such host is known"},
{WSATRY_AGAIN, "Host not found, or server failed"},
{ WSANO_RECOVERY,
"Unexpected server error encountered" },
{WSANO_RECOVERY, "Unexpected server error encountered"},
{WSANO_DATA, "Valid name without requested data"},
{WSANO_ADDRESS, "No address, look for MX record"},
{0, NULL}
};
if (err_no) {
PyObject *v;
const char *msg = "winsock error";
@ -354,17 +351,23 @@ PySocket_Err(void)
char outbuf[100];
int myerrorcode = sock_errno();
/* Retrieve Socket-Related Error Message from MPTN.MSG File */
/* Retrieve socket-related error message from MPTN.MSG file */
rc = DosGetMessage(NULL, 0, outbuf, sizeof(outbuf),
myerrorcode - SOCBASEERR + 26, "mptn.msg", &msglen);
myerrorcode - SOCBASEERR + 26,
"mptn.msg",
&msglen);
if (rc == NO_ERROR) {
PyObject *v;
outbuf[msglen] = '\0'; /* OS/2 Doesn't Guarantee a Terminator */
if (strlen(outbuf) > 0) { /* If Non-Empty Msg, Trim CRLF */
/* OS/2 doesn't guarantee a terminator */
outbuf[msglen] = '\0';
if (strlen(outbuf) > 0) {
/* If non-empty msg, trim CRLF */
char *lastc = &outbuf[ strlen(outbuf)-1 ];
while (lastc > outbuf && isspace(*lastc))
*lastc-- = '\0'; /* Trim Trailing Whitespace (CRLF) */
while (lastc > outbuf && isspace(*lastc)) {
/* Trim trailing whitespace (CRLF) */
*lastc-- = '\0';
}
}
v = Py_BuildValue("(is)", myerrorcode, outbuf);
if (v != NULL) {
@ -443,9 +446,8 @@ timeout_err(void)
return NULL;
}
/* Function to perfrom the setting of socket blocking mode
* internally. block = (1 | 0).
*/
/* Function to perform the setting of socket blocking mode
internally. block = (1 | 0). */
static int
internal_setblocking(PySocketSockObject *s, int block)
{
@ -487,10 +489,9 @@ internal_setblocking(PySocketSockObject *s, int block)
}
/* For access to the select module to poll the socket for timeout
* functionality. writing is 1 for writing, 0 for reading.
* Return value: -1 if error, 0 if not ready, >= 1 if ready.
* An exception is set when the return value is <= 0 (!).
*/
functionality. writing is 1 for writing, 0 for reading.
Return value: -1 if error, 0 if not ready, >= 1 if ready.
An exception is set when the return value is <= 0 (!). */
static int
internal_select(PySocketSockObject *s, int writing)
{
@ -517,8 +518,7 @@ internal_select(PySocketSockObject *s, int writing)
}
/* Set the error if the timeout has elapsed, i.e, we were not
* polled.
*/
polled. */
if (count == 0)
timeout_err();
@ -543,9 +543,8 @@ init_sockobject(PySocketSockObject *s,
s->errorhandler = &PySocket_Err;
#ifdef RISCOS
if(taskwindow) {
if (taskwindow)
socketioctl(s->sock_fd, 0x80046679, (u_long*)&block);
}
#endif
}
@ -644,8 +643,8 @@ setipaddr(char* name, struct sockaddr * addr_ret, int af)
error = getaddrinfo(name, NULL, &hints, &res);
#if defined(__digital__) && defined(__unix__)
if (error == EAI_NONAME && af == AF_UNSPEC) {
/* On Tru64 V5.1, numeric-to-addr conversion
fails if no address family is given. Assume IPv4 for now.*/
/* On Tru64 V5.1, numeric-to-addr conversion fails
if no address family is given. Assume IPv4 for now.*/
hints.ai_family = AF_INET;
error = getaddrinfo(name, NULL, &hints, &res);
}
@ -741,8 +740,11 @@ makesockaddr(int sockfd, struct sockaddr *addr, int addrlen)
PyObject *ret = NULL;
if (addrobj) {
a = (struct sockaddr_in6 *)addr;
ret = Py_BuildValue("Oiii", addrobj, ntohs(a->sin6_port),
a->sin6_flowinfo, a->sin6_scope_id);
ret = Py_BuildValue("Oiii",
addrobj,
ntohs(a->sin6_port),
a->sin6_flowinfo,
a->sin6_scope_id);
Py_DECREF(addrobj);
}
return ret;
@ -761,9 +763,13 @@ makesockaddr(int sockfd, struct sockaddr *addr, int addrlen)
if (ioctl(sockfd, SIOCGIFNAME, &ifr) == 0)
ifname = ifr.ifr_name;
}
return Py_BuildValue("shbhs#", ifname, ntohs(a->sll_protocol),
a->sll_pkttype, a->sll_hatype,
a->sll_addr, a->sll_halen);
return Py_BuildValue("shbhs#",
ifname,
ntohs(a->sll_protocol),
a->sll_pkttype,
a->sll_hatype,
a->sll_addr,
a->sll_halen);
}
#endif
@ -822,8 +828,10 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args,
int port;
addr=(struct sockaddr_in*)&(s->sock_addr).in;
if (!PyTuple_Check(args)) {
PyErr_Format(PyExc_TypeError,
"getsockaddrarg: AF_INET address must be tuple, not %.500s",
PyErr_Format(
PyExc_TypeError,
"getsockaddrarg: "
"AF_INET address must be tuple, not %.500s",
args->ob_type->tp_name);
return 0;
}
@ -1007,8 +1015,7 @@ PySocketSock_accept(PySocketSockObject *s)
}
/* At this point, we really have an error, whether using timeout
* behavior or regular socket behavior
*/
behavior or regular socket behavior */
#ifdef MS_WINDOWS
if (newfd == INVALID_SOCKET)
#else
@ -1061,8 +1068,7 @@ PySocketSock_setblocking(PySocketSockObject *s, PyObject *arg)
s->sock_blocking = block;
/* If we're not using timeouts, actually set the blocking to give
* old python behavior.
*/
old python behavior. */
if (s->sock_timeout < 0.0)
internal_setblocking(s, block);
@ -1076,10 +1082,9 @@ static char setblocking_doc[] =
Set the socket to blocking (flag is true) or non-blocking (false).\n\
This uses the FIONBIO ioctl with the O_NDELAY flag.";
/* s.settimeout(float | None) method.
* Causes an exception to be raised when the given time has
* elapsed when performing a blocking socket operation.
*/
/* s.settimeout(None | float) method.
Causes an exception to be raised when the given time has
elapsed when performing a blocking socket operation. */
static PyObject *
PySocketSock_settimeout(PySocketSockObject *s, PyObject *arg)
{
@ -1100,17 +1105,16 @@ PySocketSock_settimeout(PySocketSockObject *s, PyObject *arg)
s->sock_timeout = value;
/* The semantics of setting socket timeouts are:
* If you settimeout(!=None):
* The actual socket gets put in non-blocking mode and the select
* is used to control timeouts.
* Else if you settimeout(None) [then value is -1.0]:
* The old behavior is used AND automatically, the socket is set
* to blocking mode. That means that someone who was doing
* non-blocking stuff before, sets a timeout, and then unsets
* one, will have to call setblocking(0) again if he wants
* non-blocking stuff. This makes sense because timeout stuff is
* blocking by nature.
*/
If you settimeout(!=None):
The actual socket gets put in non-blocking mode and the select
is used to control timeouts.
Else if you settimeout(None) [then value is -1.0]:
The old behavior is used AND automatically, the socket is set
to blocking mode. That means that someone who was doing
non-blocking stuff before, sets a timeout, and then unsets
one, will have to call setblocking(0) again if he wants
non-blocking stuff. This makes sense because timeout stuff is
blocking by nature. */
internal_setblocking(s, value < 0.0);
s->sock_blocking = 1; /* Always negate setblocking() */
@ -1120,17 +1124,13 @@ PySocketSock_settimeout(PySocketSockObject *s, PyObject *arg)
}
static char settimeout_doc[] =
"settimeout(seconds)\n\
"settimeout(timeout)\n\
\n\
Set a timeout on blocking socket operations. 'seconds' can be a floating,\n\
integer, or long number of seconds, or the None value. Socket operations\n\
will raise an exception if the timeout period has elapsed before the\n\
operation has completed. Setting a timeout of None disables timeouts\n\
on socket operations.";
Set a timeout on blocking socket operations. 'timeout' can be a float,\n\
giving seconds, or None. Setting a timeout of None disables timeout.";
/* s.gettimeout() method.
* Returns the timeout associated with a socket.
*/
Returns the timeout associated with a socket. */
static PyObject *
PySocketSock_gettimeout(PySocketSockObject *s)
{
@ -1357,7 +1357,8 @@ PySocketSock_connect(PySocketSockObject *s, PyObject *addro)
/* Check if we have an error */
if (!s->sock_blocking)
return s->errorhandler();
/* Check if we have a true failure for a blocking socket */
/* Check if we have a true failure
for a blocking socket */
#ifdef MS_WINDOWS
if (errno != WSAEWOULDBLOCK)
#else
@ -1423,7 +1424,8 @@ PySocketSock_connect_ex(PySocketSockObject *s, PyObject *addro)
/* Check if we have an error */
if (!s->sock_blocking)
goto conex_finally;
/* Check if we have a true failure for a blocking socket */
/* Check if we have a true failure
for a blocking socket */
#ifdef MS_WINDOWS
if (errno != WSAEWOULDBLOCK)
#else
@ -2002,11 +2004,13 @@ PySocketSock_repr(PySocketSockObject *s)
ugly printf formatter for decimal pointer length integer
printing, only bother if necessary*/
PyErr_SetString(PyExc_OverflowError,
"no printf formatter to display the socket descriptor in decimal");
"no printf formatter to display "
"the socket descriptor in decimal");
return NULL;
}
#endif
PyOS_snprintf(buf, sizeof(buf),
PyOS_snprintf(
buf, sizeof(buf),
"<socket object, fd=%ld, family=%d, type=%d, protocol=%d>",
(long)s->sock_fd, s->sock_family,
s->sock_type,
@ -2106,6 +2110,7 @@ send() -- send data, may not send all of it\n\
sendall() -- send all data\n\
sendto() -- send data to a given address\n\
setblocking() -- set or clear the blocking I/O flag\n\
settimeout() -- set or clear the timeout\n\
setsockopt() -- set socket options\n\
shutdown() -- shut down traffic in one or both directions\n\
\n\
@ -2227,9 +2232,11 @@ gethost_common(struct hostent *h, struct sockaddr *addr, int alen, int af)
if (h->h_addrtype != af) {
#ifdef HAVE_STRERROR
/* Let's get real error message to return */
PyErr_SetString(PySocket_Error, (char *)strerror(EAFNOSUPPORT));
#else
PyErr_SetString(PySocket_Error,
(char *)strerror(EAFNOSUPPORT));
#else
PyErr_SetString(
PySocket_Error,
"Address family not supported by protocol family");
#endif
return NULL;
@ -2367,7 +2374,8 @@ PySocket_gethostbyname_ex(PyObject *self, PyObject *args)
Py_BEGIN_ALLOW_THREADS
#ifdef HAVE_GETHOSTBYNAME_R
#if defined(HAVE_GETHOSTBYNAME_R_6_ARG)
result = gethostbyname_r(name, &hp_allocated, buf, buf_len, &h, &errnop);
result = gethostbyname_r(name, &hp_allocated, buf, buf_len,
&h, &errnop);
#elif defined(HAVE_GETHOSTBYNAME_R_5_ARG)
h = gethostbyname_r(name, &hp_allocated, buf, buf_len, &errnop);
#else /* HAVE_GETHOSTBYNAME_R_3_ARG */
@ -2383,10 +2391,9 @@ PySocket_gethostbyname_ex(PyObject *self, PyObject *args)
#endif /* HAVE_GETHOSTBYNAME_R */
Py_END_ALLOW_THREADS
/* Some C libraries would require addr.__ss_family instead of
* addr.ss_family.
* Therefore, we cast the sockaddr_storage into sockaddr to
* access sa_family.
*/
addr.ss_family.
Therefore, we cast the sockaddr_storage into sockaddr to
access sa_family. */
sa = (struct sockaddr*)&addr;
ret = gethost_common(h, (struct sockaddr *)&addr, sizeof(addr),
sa->sa_family);
@ -2664,12 +2671,7 @@ static char htonl_doc[] =
\n\
Convert a 32-bit integer from host to network byte order.";
/*
* socket.inet_aton() and socket.inet_ntoa() functions
*
* written 20 Aug 1999 by Ben Gertzfield <che@debian.org> <- blame him!
*
*/
/* socket.inet_aton() and socket.inet_ntoa() functions. */
static char inet_aton_doc[] =
"inet_aton(string) -> packed 32-bit IP representation\n\
@ -2827,7 +2829,8 @@ PySocket_getnameinfo(PyObject *self, PyObject *args)
flags = flowinfo = scope_id = 0;
if (!PyArg_ParseTuple(args, "Oi:getnameinfo", &sa, &flags))
return NULL;
if (!PyArg_ParseTuple(sa, "si|ii", &hostp, &port, &flowinfo, &scope_id))
if (!PyArg_ParseTuple(sa, "si|ii",
&hostp, &port, &flowinfo, &scope_id))
return NULL;
PyOS_snprintf(pbuf, sizeof(pbuf), "%d", port);
memset(&hints, 0, sizeof(hints));
@ -2951,7 +2954,8 @@ NTinit(void)
break;
case WSAVERNOTSUPPORTED:
case WSAEINVAL:
PyErr_SetString(PyExc_ImportError,
PyErr_SetString(
PyExc_ImportError,
"WSAStartup failed: requested version not supported");
break;
default:
@ -3009,22 +3013,23 @@ PySocketModule_APIObject PySocketModuleAPI =
};
/* Initialize this module.
* This is called when the first 'import socket' is done,
* via a table in config.c, if config.c is compiled with USE_SOCKET
* defined.
*
* For MS_WINDOWS (which means any Windows variant), this module
* is actually called "_socket", and there's a wrapper "socket.py"
* which implements some missing functionality (such as makefile(),
* dup() and fromfd()). The import of "_socket" may fail with an
* ImportError exception if initialization of WINSOCK fails. When
* WINSOCK is initialized succesfully, a call to WSACleanup() is
* scheduled to be made at exit time.
*
* For OS/2, this module is also called "_socket" and uses a wrapper
* "socket.py" which implements that functionality that is missing
* when PC operating systems don't put socket descriptors in the
* operating system's filesystem layer.
This is called when the first 'import socket' is done,
via a table in config.c, if config.c is compiled with USE_SOCKET
defined.
For MS_WINDOWS (which means any Windows variant), this module
is actually called "_socket", and there's a wrapper "socket.py"
which implements some missing functionality (such as makefile(),
dup() and fromfd()). The import of "_socket" may fail with an
ImportError exception if initialization of WINSOCK fails. When
WINSOCK is initialized succesfully, a call to WSACleanup() is
scheduled to be made at exit time.
For OS/2, this module is also called "_socket" and uses a wrapper
"socket.py" which implements that functionality that is missing
when PC operating systems don't put socket descriptors in the
operating system's filesystem layer.
*/
static char module_doc[] =