Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1d8fb2d

Browse files
committed
Added doc strings.
1 parent a5e1b00 commit 1d8fb2d

2 files changed

Lines changed: 98 additions & 10 deletions

File tree

Modules/selectmodule.c

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,18 +314,46 @@ select_select(self, args)
314314
return ret;
315315
}
316316

317+
static char select_doc[] =
318+
"select(rlist, wlist, xlist[, timeout]) -> (rlist, wlist, xlist)\n\
319+
\n\
320+
Wait until one or more file descriptors are ready for some kind of I/O.\n\
321+
The first three arguments are lists of file descriptors to be waited for:\n\
322+
rlist -- wait until ready for reading\n\
323+
wlist -- wait until ready for writing\n\
324+
xlist -- wait for an ``exceptional condition''\n\
325+
If only one kind of condition is required, pass [] for the other lists.\n\
326+
A file descriptor is either a socket or file object, or a small integer\n\
327+
gotten from a fileno() method call on one of those.\n\
328+
\n\
329+
The optional 4th argument specifies a timeout in seconds; it may be\n\
330+
a floating point number to specify fractions of seconds. If it is absent\n\
331+
or None, the call will never time out.\n\
332+
\n\
333+
The return value is a tuple of three lists corresponding to the first three\n\
334+
arguments; each contains the subset of the corresponding file descriptors\n\
335+
that are ready.\n\
336+
\n\
337+
*** IMPORTANT NOTICE ***\n\
338+
On Windows, only sockets are supported; on Unix, all file descriptors.";
339+
317340

318341
static PyMethodDef select_methods[] = {
319-
{"select", select_select, 1},
342+
{"select", select_select, 1, select_doc},
320343
{0, 0}, /* sentinel */
321344
};
322345

346+
static char module_doc[] =
347+
"This module supports asynchronous I/O on multiple file descriptors.\n\
348+
\n\
349+
*** IMPORTANT NOTICE ***\n\
350+
On Windows, only sockets are supported; on Unix, all file descriptors.";
323351

324352
void
325353
initselect()
326354
{
327355
PyObject *m, *d;
328-
m = Py_InitModule("select", select_methods);
356+
m = Py_InitModule3("select", select_methods, module_doc);
329357
d = PyModule_GetDict(m);
330358
SelectError = PyErr_NewException("select.error", NULL, NULL);
331359
PyDict_SetItemString(d, "error", SelectError);

Modules/signalmodule.c

Lines changed: 68 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,12 @@ signal_default_int_handler(self, arg)
122122
return NULL;
123123
}
124124

125+
static char default_int_handler_doc[] =
126+
"default_int_handler(...)\n\
127+
\n\
128+
The default handler for SIGINT instated by Python.\n\
129+
It raises KeyboardInterrupt.";
130+
125131

126132
static RETSIGTYPE
127133
signal_handler(sig_num)
@@ -164,6 +170,11 @@ signal_alarm(self, args)
164170
/* alarm() returns the number of seconds remaining */
165171
return PyInt_FromLong(alarm(t));
166172
}
173+
174+
static char alarm_doc[] =
175+
"alarm(seconds)\n\
176+
\n\
177+
Arrange for SIGALRM to arrive after the given number of seconds."
167178
#endif
168179

169180
#ifdef HAVE_PAUSE
@@ -187,6 +198,11 @@ signal_pause(self, args)
187198
Py_INCREF(Py_None);
188199
return Py_None;
189200
}
201+
static char pause_doc[] =
202+
"pause()
203+
204+
Wait until a signal arrives.";
205+
190206
#endif
191207

192208

@@ -235,9 +251,20 @@ signal_signal(self, args)
235251
return old_handler;
236252
}
237253

254+
static char signal_doc[] =
255+
"signal(sig, action) -> action\n\
256+
\n\
257+
Set the action for the given signal. The action can be SIG_DFL,\n\
258+
SIG_IGN, or a callable Python object. The previous action is\n\
259+
returned. See getsignal() for possible return values.\n\
260+
\n\
261+
*** IMPORTANT NOTICE ***\n\
262+
A signal handler function is called with two arguments:\n\
263+
the first is the signal number, the second is the interrupted stack frame.";
264+
238265

239266
static PyObject *
240-
signal_get_signal(self, args)
267+
signal_getsignal(self, args)
241268
PyObject *self; /* Not used */
242269
PyObject *args;
243270
{
@@ -255,24 +282,57 @@ signal_get_signal(self, args)
255282
return old_handler;
256283
}
257284

285+
static char getsignal_doc[] =
286+
"getsignal(sig) -> action\n\
287+
\n\
288+
Return the current action for the given signal. The return value can be:\n\
289+
SIG_IGN -- if the signal is being ignored\n\
290+
SIG_DFL -- if the default action for the signal is in effect\n\
291+
None -- if an unknown handler is in effect\n\
292+
anything else -- the callable Python object used as a handler\n\
293+
";
258294

259295

260296
/* List of functions defined in the module */
261297
static PyMethodDef signal_methods[] = {
262298
#ifdef HAVE_ALARM
263-
{"alarm", signal_alarm},
299+
{"alarm", signal_alarm, 0, alarm_doc},
264300
#endif
265-
{"signal", signal_signal},
266-
{"getsignal", signal_get_signal},
301+
{"signal", signal_signal, 0, signal_doc},
302+
{"getsignal", signal_getsignal, 0, getsignal_doc},
267303
#ifdef HAVE_PAUSE
268-
{"pause", signal_pause},
304+
{"pause", signal_pause, 0, pause_doc},
269305
#endif
270-
{"default_int_handler", signal_default_int_handler},
271-
{NULL, NULL} /* sentinel */
306+
{"default_int_handler", signal_default_int_handler, 0,
307+
default_int_handler_doc},
308+
{NULL, NULL} /* sentinel */
272309
};
273310

274311

275312

313+
static char module_doc[] =
314+
"This module provides mechanisms to use signal handlers in Python.\n\
315+
\n\
316+
Functions:\n\
317+
\n\
318+
alarm() -- cause SIGALRM after a specified time [Unix only]\n\
319+
signal() -- set the action for a given signal\n\
320+
getsignal() -- get the signal action for a given signal\n\
321+
pause() -- wait until a signal arrives [Unix only]\n\
322+
default_int_handler() -- default SIGINT handler\n\
323+
\n\
324+
Constants:\n\
325+
\n\
326+
SIG_DFL -- used to refer to the system default handler\n\
327+
SIG_IGN -- used to ignore the signal\n\
328+
NSIG -- number of defined signals\n\
329+
\n\
330+
SIGINT, SIGTERM, etc. -- signal numbers\n\
331+
\n\
332+
*** IMPORTANT NOTICE ***\n\
333+
A signal handler function is called with two arguments:\n\
334+
the first is the signal number, the second is the interrupted stack frame.";
335+
276336
void
277337
initsignal()
278338
{
@@ -285,7 +345,7 @@ initsignal()
285345
#endif
286346

287347
/* Create the module and add the functions */
288-
m = Py_InitModule("signal", signal_methods);
348+
m = Py_InitModule3("signal", signal_methods, module_doc);
289349

290350
/* Add some symbolic constants to the module */
291351
d = PyModule_GetDict(m);

0 commit comments

Comments
 (0)