Expose C library's gettext. Fixes #516412.

This commit is contained in:
Martin v. Löwis 2002-03-27 18:49:02 +00:00
parent 4208d4f757
commit 2e64c34850
6 changed files with 448 additions and 342 deletions

View File

@ -467,3 +467,21 @@ application doesn't want this to happen, it should remove the
\module{_locale} extension module (which does all the work) from the
table of built-in modules in the \file{config.c} file, and make sure
that the \module{_locale} module is not accessible as a shared library.
\subsection{Access to message catalogs}
The locale module exposes the C library's gettext interface on systems
that provide this interface. It consists of the functions
\function{gettext}, \function{dgettext}, \function{dcgettext},
\function{textdomain}, and \function{bindtextdomain}. These are
similar to the same functions in the \module{gettext} module, but use
the C library's binary format for message catalogs, and the C
library's search algorithms for locating message catalogs.
Python applications should normally find no need to invoke these
functions, and should use \module{gettext} instead. A known exception
to this rule are applications that link use additional C libraries
which internally invoke \function{gettext} or \function{dgettext}. For
these applications, it may be necessary to bind the text domain, so
that the libraries can properly locate their message catalogs.

View File

@ -31,6 +31,8 @@ Core and builtins
Extension modules
- The locale module now exposes the C library's gettext interface.
- A security hole ("double free") was found in zlib-1.1.3, a popular
third party compression library used by some Python modules. The
hole was quickly plugged in zlib-1.1.4, and the Windows build of

View File

@ -21,6 +21,10 @@ This software comes with no warranty. Use at your own risk.
#include <langinfo.h>
#endif
#ifdef HAVE_LIBINTL_H
#include <libintl.h>
#endif
#if defined(MS_WIN32)
#define WINDOWS_LEAN_AND_MEAN
#include <windows.h>
@ -521,7 +525,86 @@ PyLocale_nl_langinfo(PyObject* self, PyObject* args)
return NULL;
}
#endif /* HAVE_LANGINFO_H */
#ifdef HAVE_LIBINTL_H
static char gettext__doc__[]=
"gettext(msg) -> string\n"
"Return translation of msg.";
static PyObject*
PyIntl_gettext(PyObject* self, PyObject *args)
{
char *in;
if (!PyArg_ParseTuple(args, "z", &in))
return 0;
return PyString_FromString(gettext(in));
}
static char dgettext__doc__[]=
"dgettext(domain, msg) -> string\n"
"Return translation of msg in domain.";
static PyObject*
PyIntl_dgettext(PyObject* self, PyObject *args)
{
char *domain, *in;
if (!PyArg_ParseTuple(args, "zz", &domain, &in))
return 0;
return PyString_FromString(dgettext(domain, in));
}
static char dcgettext__doc__[]=
"dcgettext(domain, msg, category) -> string\n"
"Return translation of msg in domain and category.";
static PyObject*
PyIntl_dcgettext(PyObject *self, PyObject *args)
{
char *domain, *msgid;
int category;
if (!PyArg_ParseTuple(args, "zzi", &domain, &msgid, &category))
return 0;
return PyString_FromString(dcgettext(domain,msgid,category));
}
static char textdomain__doc__[]=
"textdomain(domain) -> string\n"
"Set the C library's textdmain to domain, returning the new domain.";
static PyObject*
PyIntl_textdomain(PyObject* self, PyObject* args)
{
char *domain;
if (!PyArg_ParseTuple(args, "z", &domain))
return 0;
domain = textdomain(domain);
if (!domain) {
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
}
return PyString_FromString(domain);
}
static char bindtextdomain__doc__[]=
"bindtextdomain(domain, dir) -> string\n"
"Bind the C library's domain to dir.";
static PyObject*
PyIntl_bindtextdomain(PyObject* self,PyObject*args)
{
char *domain,*dirname;
if (!PyArg_ParseTuple(args, "zz", &domain, &dirname))
return 0;
dirname = bindtextdomain(domain, dirname);
if (!dirname) {
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
}
return PyString_FromString(dirname);
}
#endif
static struct PyMethodDef PyLocale_Methods[] = {
{"setlocale", (PyCFunction) PyLocale_setlocale,
@ -539,7 +622,18 @@ static struct PyMethodDef PyLocale_Methods[] = {
{"nl_langinfo", (PyCFunction) PyLocale_nl_langinfo,
METH_VARARGS, nl_langinfo__doc__},
#endif
#ifdef HAVE_LANGINFO_H
{"gettext",(PyCFunction)PyIntl_gettext,METH_VARARGS,
gettext__doc__},
{"dgettext",(PyCFunction)PyIntl_dgettext,METH_VARARGS,
dgettext__doc__},
{"dcgettext",(PyCFunction)PyIntl_dcgettext,METH_VARARGS,
dcgettext__doc__},
{"textdomain",(PyCFunction)PyIntl_textdomain,METH_VARARGS,
textdomain__doc__},
{"bindtextdomain",(PyCFunction)PyIntl_bindtextdomain,METH_VARARGS,
bindtextdomain__doc__},
#endif
{NULL, NULL}
};

665
configure vendored

File diff suppressed because it is too large Load Diff

View File

@ -520,8 +520,8 @@ dnl AC_MSG_RESULT($cpp_type)
# checks for header files
AC_HEADER_STDC
AC_CHECK_HEADERS(dlfcn.h fcntl.h grp.h limits.h langinfo.h locale.h \
ncurses.h poll.h pthread.h \
AC_CHECK_HEADERS(dlfcn.h fcntl.h grp.h limits.h langinfo.h \
libintl.h locale.h ncurses.h poll.h pthread.h \
signal.h stdarg.h stddef.h stdlib.h thread.h unistd.h utime.h termios.h \
sys/audioio.h sys/file.h sys/lock.h sys/modem.h db_185.h db.h \
sys/param.h sys/poll.h sys/select.h sys/socket.h sys/time.h sys/times.h \

View File

@ -645,6 +645,9 @@
/* Define if you have the <langinfo.h> header file. */
#undef HAVE_LANGINFO_H
/* Define if you have the <libintl.h> header file. */
#undef HAVE_LIBINTL_H
/* Define if you have the <libutil.h> header file. */
#undef HAVE_LIBUTIL_H