Index: Doc/library/msvcrt.rst =================================================================== --- Doc/library/msvcrt.rst (revision 77150) +++ Doc/library/msvcrt.rst (working copy) @@ -90,12 +90,12 @@ .. function:: getch() - Read a keypress and return the resulting character. Nothing is echoed to the - console. This call will block if a keypress is not already available, but will - not wait for :kbd:`Enter` to be pressed. If the pressed key was a special - function key, this will return ``'\000'`` or ``'\xe0'``; the next call will - return the keycode. The :kbd:`Control-C` keypress cannot be read with this - function. + Read a keypress and return the resulting character as a byte string. + Nothing is echoed to the console. This call will block if a keypress is not + already available, but will not wait for :kbd:`Enter` to be pressed. If the + pressed key was a special function key, this will return ``'\000'`` or + ``'\xe0'``; the next call will return the keycode. The :kbd:`Control-C` + keypress cannot be read with this function. .. function:: getwch() @@ -116,7 +116,8 @@ .. function:: putch(char) - Print the character *char* to the console without buffering. + Print the character *char* represented by the byte string to the console + without buffering. .. function:: putwch(unicode_char) @@ -126,8 +127,9 @@ .. function:: ungetch(char) - Cause the character *char* to be "pushed back" into the console buffer; it will - be the next character read by :func:`getch` or :func:`getche`. + Cause the character *char* represented by the byte string to be + "pushed back" into the console buffer; it will be the next character read + by :func:`getch` or :func:`getche`. .. function:: ungetwch(unicode_char) @@ -147,3 +149,30 @@ the operating system. This only works on Windows NT. On failure, this raises :exc:`IOError`. +.. function:: SetErrorMode(mode) + + Control whether the system will handle the specified mode(s) of serious + errors or whether the process will handle them. Returns the previous mode(s). + +.. data::SEM_FAILCRITICALERRORS + + The system does not display the critical-error-handler message box. Instead, + the system sends the error to the calling process. + +.. data::SEM_NOALIGNMENTFAULTEXCEPT + + The system automatically fixes memory alignment faults and makes them + invisible to the application. It does this for the calling process and any + descendant processes. This feature is only supported by certain processor + architectures. + +.. data::SEM_NOGPFAULTERRORBOX + + The system does not display the general-protection-fault message box. This + flag should be set only by debugging applications that handle general + protection (GP) faults themselves with an exception handler. + +.. data::SEM_NOOPENFILEERRORBOX + + The system does not display a message box when it fails to find a file. + Instead, the error is returned to the calling process. Index: PC/msvcrtmodule.c =================================================================== --- PC/msvcrtmodule.c (revision 77150) +++ PC/msvcrtmodule.c (working copy) @@ -45,6 +45,13 @@ return Py_None; } +PyDoc_STRVAR(heapmin_doc, +"heapmin() -> None\n\ +\n\ +Force the malloc() heap to clean itself up and return unused blocks\n\ +to the operating system. This only works on Windows NT. On failure,\n\ +this raises IOError."); + // Perform locking operations on a C runtime file descriptor. static PyObject * msvcrt_locking(PyObject *self, PyObject *args) @@ -67,6 +74,17 @@ return Py_None; } +PyDoc_STRVAR(locking_doc, +"locking(fd, mode, nbytes) -> None\n\ +\n\ +Lock part of a file based on file descriptor fd from the C runtime.\n\ +Raises IOError on failure. The locked region of the file extends from\n\ +the current file position for nbytes bytes, and may continue beyond\n\ +the end of the file. mode must be one of the LK_* constants listed\n\ +below. Multiple regions in a file may be locked at the same time, but\n\ +may not overlap. Adjacent regions are not merged; they must be unlocked\n\ +individually."); + // Set the file translation mode for a C runtime file descriptor. static PyObject * msvcrt_setmode(PyObject *self, PyObject *args) @@ -83,6 +101,13 @@ return PyLong_FromLong(flags); } +PyDoc_STRVAR(setmode_doc, +"setmode(fd, mode) -> Previous mode\n\ +\n\ +Set the line-end translation mode for the file descriptor fd. To set\n\ +it to text mode, flags should be os.O_TEXT; for binary, it should be\n\ +os.O_BINARY."); + // Convert an OS file handle to a C runtime file descriptor. static PyObject * msvcrt_open_osfhandle(PyObject *self, PyObject *args) @@ -101,6 +126,14 @@ return PyLong_FromLong(fd); } +PyDoc_STRVAR(open_osfhandle_doc, +"open_osfhandle(handle, flags) -> file descriptor\n\ +\n\ +Create a C runtime file descriptor from the file handle handle. The\n\ +flags parameter should be a bitwise OR of os.O_APPEND, os.O_RDONLY,\n\ +and os.O_TEXT. The returned file descriptor may be used as a parameter\n\ +to os.fdopen() to create a file object."); + // Convert a C runtime file descriptor to an OS file handle. static PyObject * msvcrt_get_osfhandle(PyObject *self, PyObject *args) @@ -121,6 +154,12 @@ return PyLong_FromVoidPtr((void*)handle); } +PyDoc_STRVAR(get_osfhandle_doc, +"get_osfhandle(fd) -> file handle\n\ +\n\ +Return the file handle for the file descriptor fd. Raises IOError\n\ +if fd is not recognized."); + /* Console I/O */ static PyObject * @@ -135,6 +174,11 @@ return PyLong_FromLong(ok); } +PyDoc_STRVAR(kbhit_doc, +"kbhit() -> bool\n\ +\n\ +Return true if a keypress is waiting to be read."); + static PyObject * msvcrt_getch(PyObject *self, PyObject *args) { @@ -151,6 +195,16 @@ return PyBytes_FromStringAndSize(s, 1); } +PyDoc_STRVAR(getch_doc, +"getch() -> key character\n\ +\n\ +Read a keypress and return the resulting character as a byte string. \n\ +Nothing is echoed to the console. This call will block if a keypress \n\ +is not already available, but will not wait for Enter to be pressed. \n\ +If the pressed key was a special function key, this will return \n\ +'\\000' or '\\xe0'; the next call will return the keycode. The \n\ +Control-C keypress cannot be read with this function."); + #ifdef _WCONIO_DEFINED static PyObject * msvcrt_getwch(PyObject *self, PyObject *args) @@ -167,6 +221,11 @@ u[0] = ch; return PyUnicode_FromUnicode(u, 1); } + +PyDoc_STRVAR(getwch_doc, +"getwch() -> Unicode key character\n\ +\n\ +Wide char variant of getch(), returning a Unicode value."); #endif static PyObject * @@ -185,6 +244,12 @@ return PyBytes_FromStringAndSize(s, 1); } +PyDoc_STRVAR(getche_doc, +"getche() -> key character\n\ +\n\ +Similar to getch(), but the keypress will be echoed if it represents\n\ +a printable character."); + #ifdef _WCONIO_DEFINED static PyObject * msvcrt_getwche(PyObject *self, PyObject *args) @@ -201,6 +266,11 @@ s[0] = ch; return PyUnicode_FromUnicode(s, 1); } + +PyDoc_STRVAR(getwche_doc, +"getwche() -> Unicode key character\n\ +\n\ +Wide char variant of getche(), returning a Unicode value."); #endif static PyObject * @@ -216,6 +286,12 @@ return Py_None; } +PyDoc_STRVAR(putch_doc, +"putch(char) -> None\n\ +\n\ +Print the character represented by the byte string to the \n\ +console without buffering."); + #ifdef _WCONIO_DEFINED static PyObject * msvcrt_putwch(PyObject *self, PyObject *args) @@ -229,6 +305,11 @@ Py_RETURN_NONE; } + +PyDoc_STRVAR(putwch_doc, +"putwch(unicode_char) -> None\n\ +\n\ +Wide char variant of putch(), accepting a Unicode value."); #endif static PyObject * @@ -245,6 +326,13 @@ return Py_None; } +PyDoc_STRVAR(ungetch_doc, +"ungetch(char) -> None\n\ +\n\ +Cause the character represented by the byte string to be \n\ +\"pushed back\" into the console buffer; it will be the \n\ +next character read by getch() or getche()."); + #ifdef _WCONIO_DEFINED static PyObject * msvcrt_ungetwch(PyObject *self, PyObject *args) @@ -259,6 +347,11 @@ Py_INCREF(Py_None); return Py_None; } + +PyDoc_STRVAR(ungetwch_doc, +"ungetwch(unicode_char) -> None\n\ +\n\ +Wide char variant of ungetch(), accepting a Unicode value."); #endif static void @@ -291,6 +384,13 @@ return Py_None; } +PyDoc_STRVAR(setreportfile_doc, +"CrtSetReportFile(type, file) -> Previous file\n\ +\n\ +After specifying CRTDBG_MODE_FILE with CrtSetReportMode, \n\ +you can specify the file handle to receive the message text \n\ +for the given type."); + static PyObject* msvcrt_setreportmode(PyObject *self, PyObject *args) { @@ -305,6 +405,12 @@ return PyLong_FromLong(res); } +PyDoc_STRVAR(setreportmode_doc, +"CrtSetReportMode(type, mode) -> Previous mode\n\ +\n\ +Specify the destination mode(s) for a specific report type \n\ +generated by _CrtDbgReport."); + static PyObject* msvcrt_seterrormode(PyObject *self, PyObject *args) { @@ -316,6 +422,13 @@ return PyLong_FromLong(res); } +PyDoc_STRVAR(set_error_mode_doc, +"set_error_mode(mode) -> Previous mode\n\ +\n\ +Modifies __error_mode to determine a non-default location \n\ +where the C run time writes an error message for an error \n\ +that will possibly end the program."); + #endif static PyObject* @@ -329,30 +442,36 @@ return PyLong_FromUnsignedLong(res); } +PyDoc_STRVAR(seterrormode_doc, +"SetErrorMode(mode) -> Previous mode\n\ +\n\ +Control whether the system will handle the specified \n\ +modes of serious errors or whether the process will handle them."); + /* List of functions exported by this module */ static struct PyMethodDef msvcrt_functions[] = { - {"heapmin", msvcrt_heapmin, METH_VARARGS}, - {"locking", msvcrt_locking, METH_VARARGS}, - {"setmode", msvcrt_setmode, METH_VARARGS}, - {"open_osfhandle", msvcrt_open_osfhandle, METH_VARARGS}, - {"get_osfhandle", msvcrt_get_osfhandle, METH_VARARGS}, - {"kbhit", msvcrt_kbhit, METH_VARARGS}, - {"getch", msvcrt_getch, METH_VARARGS}, - {"getche", msvcrt_getche, METH_VARARGS}, - {"putch", msvcrt_putch, METH_VARARGS}, - {"ungetch", msvcrt_ungetch, METH_VARARGS}, - {"SetErrorMode", seterrormode, METH_VARARGS}, + {"heapmin", msvcrt_heapmin, METH_VARARGS, heapmin_doc}, + {"locking", msvcrt_locking, METH_VARARGS, locking_doc}, + {"setmode", msvcrt_setmode, METH_VARARGS, setmode_doc}, + {"open_osfhandle", msvcrt_open_osfhandle, METH_VARARGS, open_osfhandle_doc}, + {"get_osfhandle", msvcrt_get_osfhandle, METH_VARARGS, get_osfhandle_doc}, + {"kbhit", msvcrt_kbhit, METH_VARARGS, kbhit_doc}, + {"getch", msvcrt_getch, METH_VARARGS, getch_doc}, + {"getche", msvcrt_getche, METH_VARARGS, getche_doc}, + {"putch", msvcrt_putch, METH_VARARGS, putch_doc}, + {"ungetch", msvcrt_ungetch, METH_VARARGS, ungetch_doc}, + {"SetErrorMode", seterrormode, METH_VARARGS, seterrormode_doc}, #ifdef _DEBUG - {"CrtSetReportFile", msvcrt_setreportfile, METH_VARARGS}, - {"CrtSetReportMode", msvcrt_setreportmode, METH_VARARGS}, - {"set_error_mode", msvcrt_seterrormode, METH_VARARGS}, + {"CrtSetReportFile", msvcrt_setreportfile, METH_VARARGS, setreportfile_doc}, + {"CrtSetReportMode", msvcrt_setreportmode, METH_VARARGS, setreportmode_doc}, + {"set_error_mode", msvcrt_seterrormode, METH_VARARGS, set_error_mode_doc}, #endif #ifdef _WCONIO_DEFINED - {"getwch", msvcrt_getwch, METH_VARARGS}, - {"getwche", msvcrt_getwche, METH_VARARGS}, - {"putwch", msvcrt_putwch, METH_VARARGS}, - {"ungetwch", msvcrt_ungetwch, METH_VARARGS}, + {"getwch", msvcrt_getwch, METH_VARARGS, getwch_doc}, + {"getwche", msvcrt_getwche, METH_VARARGS, getwche_doc}, + {"putwch", msvcrt_putwch, METH_VARARGS, putwch_doc}, + {"ungetwch", msvcrt_ungetwch, METH_VARARGS, ungetwch_doc}, #endif {NULL, NULL} };