Expose nl_langinfo through locale where available.
This commit is contained in:
parent
09379da7de
commit
9b75dca192
|
@ -108,6 +108,15 @@ locale.setlocale(locale.LC_ALL, '')
|
|||
\end{tableii}
|
||||
\end{funcdesc}
|
||||
|
||||
\begin{funcdesc}{nl_langinfo}{option}
|
||||
|
||||
Return some locale-specific information as a string. This function is
|
||||
not available on all systems, and the set of possible options might
|
||||
also vary across platforms. The possible argument values are numbers,
|
||||
for which symbolic constants are available in the locale module.
|
||||
|
||||
\end{funcdesc}
|
||||
|
||||
\begin{funcdesc}{getdefaultlocale}{\optional{envvars}}
|
||||
Tries to determine the default locale settings and returns
|
||||
them as a tuple of the form \code{(\var{language code},
|
||||
|
@ -259,6 +268,116 @@ locale.setlocale(locale.LC_ALL, '')
|
|||
\function{localeconv()}.
|
||||
\end{datadesc}
|
||||
|
||||
The \function{nl_langinfo} function accepts one of the following keys.
|
||||
Most descriptions are taken from the corresponding description in the
|
||||
GNU C library.
|
||||
|
||||
\begin{datadesc}{CODESET}
|
||||
Return a string with the name of the character encoding used in the
|
||||
selected locale.
|
||||
\end{datadesc}
|
||||
|
||||
\begin{datadesc}{D_T_FMT}
|
||||
Return a string that can be used as a format string for strftime(3) to
|
||||
represent time and date in a locale-specific way.
|
||||
\end{datadesc}
|
||||
|
||||
\begin{datadesc}{D_FMT}
|
||||
Return a string that can be used as a format string for strftime(3) to
|
||||
represent a date in a locale-specific way.
|
||||
\end{datadesc}
|
||||
|
||||
\begin{datadesc}{T_FMT}
|
||||
Return a string that can be used as a format string for strftime(3) to
|
||||
represent a time in a locale-specific way.
|
||||
\end{datadesc}
|
||||
|
||||
\begin{datadesc}{T_FMT_AMPM}
|
||||
The return value can be used as a format string for `strftime' to
|
||||
represent time in the am/pm format.
|
||||
\end{datadesc}
|
||||
|
||||
\begin{datadesc}{DAY_1 ... DAY_7}
|
||||
Return name of the n-th day of the week. \[Warning: this follows the US
|
||||
convention DAY_1 = Sunday, not the international convention (ISO 8601)
|
||||
that Monday is the first day of the week.\]
|
||||
\end{datadesc}
|
||||
|
||||
\begin{datadesc}{ABDAY_1 ... ABDAY_7}
|
||||
Return abbreviated name of the n-th day of the week.
|
||||
\end{datadesc}
|
||||
|
||||
\begin{datadesc}{MON_1 ... MON_12}
|
||||
Return name of the n-th month.
|
||||
\end{datadesc}
|
||||
|
||||
\begin{datadesc}{ABMON_1 ... ABMON_12}
|
||||
Return abbreviated name of the n-th month.
|
||||
\end{datadesc}
|
||||
|
||||
\begin{datadesc}{RADIXCHAR}
|
||||
Return radix character (decimal dot, decimal comma, etc.)
|
||||
\end{datadesc}
|
||||
|
||||
\begin{datadesc}{THOUSEP}
|
||||
Return separator character for thousands (groups of three digits).
|
||||
\end{datadesc}
|
||||
|
||||
\begin{datadesc}{YESEXPR}
|
||||
Return a regular expression that can be used with the regex
|
||||
function to recognize a positive response to a yes/no question.
|
||||
\[Warning: the expression is in the syntax suitable for the
|
||||
regex C library function, which might differ from the syntax
|
||||
used in \module{re}\]
|
||||
\end{datadesc}
|
||||
|
||||
\begin{datadesc}{NOEXPR}
|
||||
Return a regular expression that can be used with the regex(3)
|
||||
function to recognize a negative response to a yes/no question.
|
||||
\end{datadesc}
|
||||
|
||||
\begin{datadesc}{CRNCYSTR}
|
||||
Return the currency symbol, preceded by "-" if the symbol should
|
||||
appear before the value, "+" if the symbol should appear after the
|
||||
value, or "." if the symbol should replace the radix character.
|
||||
\end{datadesc}
|
||||
|
||||
\begin{datadesc}{ERA}
|
||||
The return value represents the era used in the current locale.
|
||||
|
||||
Most locales do not define this value. An example of a locale which
|
||||
does define this value is the Japanese one. In Japan, the traditional
|
||||
representation of dates includes the name of the era corresponding to
|
||||
the then-emperor's reign.
|
||||
|
||||
Normally it should not be necessary to use this value directly.
|
||||
Specifying the \code{E} modifier in their format strings causes the
|
||||
\function{strftime} function to use this information. The format of the
|
||||
returned string is not specified, and therefore you should not assume
|
||||
knowledge of it on different systems.
|
||||
\end{datadesc}
|
||||
|
||||
\begin{datadesc}{ERA_YEAR}
|
||||
The return value gives the year in the relevant era of the locale.
|
||||
\end{datadesc}
|
||||
|
||||
\begin{datadesc}{ERA_D_T_FMT}
|
||||
This return value can be used as a format string for
|
||||
\function{strftime} to represent dates and times in a locale-specific
|
||||
era-based way.
|
||||
\end{datadesc}
|
||||
|
||||
\begin{datadesc}{ERA_D_FMT}
|
||||
This return value can be used as a format string for
|
||||
\function{strftime} to represent time in a locale-specific era-based
|
||||
way.
|
||||
\end{datadesc}
|
||||
|
||||
\begin{datadesc}{ALT_DIGITS}
|
||||
The return value is a representation of up to 100 values used to
|
||||
represent the values 0 to 99.
|
||||
\end{datadesc}
|
||||
|
||||
Example:
|
||||
|
||||
\begin{verbatim}
|
||||
|
|
|
@ -31,6 +31,8 @@ aliases = {
|
|||
|
||||
# ASCII
|
||||
'us_ascii': 'ascii',
|
||||
'ansi_x3.4_1968': 'ascii', # used on Linux
|
||||
'646': 'ascii', # used on Solaris
|
||||
|
||||
# EBCDIC
|
||||
'ebcdic_cp_us': 'cp037',
|
||||
|
|
|
@ -17,6 +17,10 @@ This software comes with no warranty. Use at your own risk.
|
|||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#ifdef HAVE_LANGINFO_H
|
||||
#include <langinfo.h>
|
||||
#endif
|
||||
|
||||
#if defined(MS_WIN32)
|
||||
#define WINDOWS_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
@ -391,6 +395,23 @@ PyLocale_getdefaultlocale(PyObject* self, PyObject* args)
|
|||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_LANGINFO_H
|
||||
static char nl_langinfo__doc__[] =
|
||||
"nl_langinfo(key) -> string\n"
|
||||
"Return the value for the locale information associated with key."
|
||||
;
|
||||
|
||||
static PyObject*
|
||||
PyLocale_nl_langinfo(PyObject* self, PyObject* args)
|
||||
{
|
||||
int item;
|
||||
if (!PyArg_ParseTuple(args, "i:nl_langinfo", &item))
|
||||
return NULL;
|
||||
return PyString_FromString(nl_langinfo(item));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
static struct PyMethodDef PyLocale_Methods[] = {
|
||||
{"setlocale", (PyCFunction) PyLocale_setlocale,
|
||||
METH_VARARGS, setlocale__doc__},
|
||||
|
@ -403,6 +424,11 @@ static struct PyMethodDef PyLocale_Methods[] = {
|
|||
#if defined(MS_WIN32) || defined(macintosh)
|
||||
{"_getdefaultlocale", (PyCFunction) PyLocale_getdefaultlocale, 0},
|
||||
#endif
|
||||
#ifdef HAVE_LANGINFO_H
|
||||
{"nl_langinfo", (PyCFunction) PyLocale_nl_langinfo,
|
||||
METH_VARARGS, nl_langinfo__doc__},
|
||||
#endif
|
||||
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
|
@ -455,4 +481,81 @@ init_locale(void)
|
|||
x = PyString_FromString(locale__doc__);
|
||||
PyDict_SetItemString(d, "__doc__", x);
|
||||
Py_XDECREF(x);
|
||||
|
||||
#define ADDINT(X) PyModule_AddIntConstant(m, #X, X)
|
||||
#ifdef HAVE_LANGINFO_H
|
||||
/* These constants should exist on any langinfo implementation */
|
||||
ADDINT(DAY_1);
|
||||
ADDINT(DAY_2);
|
||||
ADDINT(DAY_3);
|
||||
ADDINT(DAY_4);
|
||||
ADDINT(DAY_5);
|
||||
ADDINT(DAY_6);
|
||||
ADDINT(DAY_7);
|
||||
|
||||
ADDINT(ABDAY_1);
|
||||
ADDINT(ABDAY_2);
|
||||
ADDINT(ABDAY_3);
|
||||
ADDINT(ABDAY_4);
|
||||
ADDINT(ABDAY_5);
|
||||
ADDINT(ABDAY_6);
|
||||
ADDINT(ABDAY_7);
|
||||
|
||||
ADDINT(MON_1);
|
||||
ADDINT(MON_2);
|
||||
ADDINT(MON_3);
|
||||
ADDINT(MON_4);
|
||||
ADDINT(MON_5);
|
||||
ADDINT(MON_6);
|
||||
ADDINT(MON_7);
|
||||
ADDINT(MON_8);
|
||||
ADDINT(MON_9);
|
||||
ADDINT(MON_10);
|
||||
ADDINT(MON_11);
|
||||
ADDINT(MON_12);
|
||||
|
||||
ADDINT(ABMON_1);
|
||||
ADDINT(ABMON_2);
|
||||
ADDINT(ABMON_3);
|
||||
ADDINT(ABMON_4);
|
||||
ADDINT(ABMON_5);
|
||||
ADDINT(ABMON_6);
|
||||
ADDINT(ABMON_7);
|
||||
ADDINT(ABMON_8);
|
||||
ADDINT(ABMON_9);
|
||||
ADDINT(ABMON_10);
|
||||
ADDINT(ABMON_11);
|
||||
ADDINT(ABMON_12);
|
||||
|
||||
ADDINT(RADIXCHAR);
|
||||
ADDINT(THOUSEP);
|
||||
/* YESSTR and NOSTR are deprecated in glibc, since they are
|
||||
a special case of message translation, which should be rather
|
||||
done using gettext. So we don't expose it to Python in the
|
||||
first place.
|
||||
ADDINT(YESSTR);
|
||||
ADDINT(NOSTR);
|
||||
*/
|
||||
ADDINT(CRNCYSTR);
|
||||
|
||||
ADDINT(D_T_FMT);
|
||||
ADDINT(D_FMT);
|
||||
ADDINT(T_FMT);
|
||||
ADDINT(AM_STR);
|
||||
ADDINT(PM_STR);
|
||||
|
||||
#ifdef CODESET
|
||||
/* The following constants are available only with XPG4. */
|
||||
ADDINT(CODESET);
|
||||
ADDINT(T_FMT_AMPM);
|
||||
ADDINT(ERA);
|
||||
ADDINT(ERA_D_FMT);
|
||||
ADDINT(ERA_D_T_FMT);
|
||||
ADDINT(ERA_T_FMT);
|
||||
ADDINT(ALT_DIGITS);
|
||||
ADDINT(YESEXPR);
|
||||
ADDINT(NOEXPR);
|
||||
ADDINT(_DATE_FMT);
|
||||
#endif
|
||||
#endif /* HAVE_LANGINFO_H */
|
||||
}
|
||||
|
|
|
@ -413,7 +413,8 @@ dnl AC_MSG_RESULT($cpp_type)
|
|||
|
||||
# checks for header files
|
||||
AC_HEADER_STDC
|
||||
AC_CHECK_HEADERS(dlfcn.h fcntl.h limits.h locale.h ncurses.h poll.h pthread.h \
|
||||
AC_CHECK_HEADERS(dlfcn.h fcntl.h limits.h langinfo.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 \
|
||||
|
|
|
@ -590,6 +590,9 @@
|
|||
/* Define if you have the <gdbm/ndbm.h> header file. */
|
||||
#undef HAVE_GDBM_NDBM_H
|
||||
|
||||
/* Define if you have the <langinfo.h> header file. */
|
||||
#undef HAVE_LANGINFO_H
|
||||
|
||||
/* Define if you have the <libutil.h> header file. */
|
||||
#undef HAVE_LIBUTIL_H
|
||||
|
||||
|
|
Loading…
Reference in New Issue