Mercurial > cpython-lru_cache-weakref
view Modules/syslogmodule.c @ 58664:993f703a61ba
Merged revisions 77484,77487,77561,77570,77593,77603,77608,77667,77702-77703,77739,77858,77887,77889 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r77484 | skip.montanaro | 2010-01-13 19:12:34 -0600 (Wed, 13 Jan 2010) | 4 lines
Update PyEval_EvalFrame to PyEval_EvalFrameEx. This looks to have been done
partially before. Also add a comment describing how this might have to work
with different versions of the interpreter.
........
r77487 | ezio.melotti | 2010-01-14 05:34:10 -0600 (Thu, 14 Jan 2010) | 1 line
Fixed typo
........
r77561 | georg.brandl | 2010-01-17 02:42:30 -0600 (Sun, 17 Jan 2010) | 1 line
#7699: improve datetime docs: straightforward linking to strftime/strptime section, mark classmethods as such.
........
r77570 | georg.brandl | 2010-01-17 06:14:42 -0600 (Sun, 17 Jan 2010) | 1 line
Add note about usage of STRINGLIB_EMPTY.
........
r77593 | georg.brandl | 2010-01-17 17:33:53 -0600 (Sun, 17 Jan 2010) | 1 line
Fix internal reference.
........
r77603 | benjamin.peterson | 2010-01-18 17:07:56 -0600 (Mon, 18 Jan 2010) | 8 lines
data descriptors do not override the class dictionary if __get__ is not defined
Adjust documentation and add a test to verify this behavior.
See http://mail.python.org/pipermail/python-dev/2010-January/095637.html for
discussion.
........
r77608 | gregory.p.smith | 2010-01-19 02:19:03 -0600 (Tue, 19 Jan 2010) | 6 lines
Do not compile stubs for the sha2 series hashes in the openssl hashlib
module when the openssl version is too old to support them. That
leads both compiled code bloat and to unittests attempting to test
implementations that don't exist for comparison purposes on such
platforms.
........
r77667 | mark.dickinson | 2010-01-21 12:32:27 -0600 (Thu, 21 Jan 2010) | 1 line
Add two more test_strtod test values.
........
r77702 | georg.brandl | 2010-01-23 02:43:31 -0600 (Sat, 23 Jan 2010) | 1 line
#7762: fix refcount annotation of PyUnicode_Tailmatch().
........
r77703 | georg.brandl | 2010-01-23 02:47:54 -0600 (Sat, 23 Jan 2010) | 1 line
#7725: fix referencing issue.
........
r77739 | benjamin.peterson | 2010-01-24 21:52:52 -0600 (Sun, 24 Jan 2010) | 1 line
mention from_float() in error message
........
r77858 | georg.brandl | 2010-01-30 11:57:48 -0600 (Sat, 30 Jan 2010) | 1 line
#7802: fix invalid example (heh).
........
r77887 | georg.brandl | 2010-01-31 12:51:49 -0600 (Sun, 31 Jan 2010) | 5 lines
Fix-up ftplib documentation:
move exception descriptions to toplevel, not inside a class
remove attribution in "versionadded"
spell and grammar check docstring of FTP_TLS
........
r77889 | michael.foord | 2010-01-31 13:59:26 -0600 (Sun, 31 Jan 2010) | 1 line
Minor modification to unittest documentation.
........
| author | Benjamin Peterson <benjamin@python.org> |
|---|---|
| date | Wed, 03 Feb 2010 02:35:45 +0000 |
| parents | 85b67fb5672b |
| children | f197407bdba2 562967881dc5 |
line wrap: on
line source
/*********************************************************** Copyright 1994 by Lance Ellinghouse, Cathedral City, California Republic, United States of America. All Rights Reserved Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of Lance Ellinghouse not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. LANCE ELLINGHOUSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL LANCE ELLINGHOUSE BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************/ /****************************************************************** Revision history: 1998/04/28 (Sean Reifschneider) - When facility not specified to syslog() method, use default from openlog() (This is how it was claimed to work in the documentation) - Potential resource leak of o_ident, now cleaned up in closelog() - Minor comment accuracy fix. 95/06/29 (Steve Clift) - Changed arg parsing to use PyArg_ParseTuple. - Added PyErr_Clear() call(s) where needed. - Fix core dumps if user message contains format specifiers. - Change openlog arg defaults to match normal syslog behavior. - Plug memory leak in openlog(). - Fix setlogmask() to return previous mask value. ******************************************************************/ /* syslog module */ #include "Python.h" #include <syslog.h> /* only one instance, only one syslog, so globals should be ok */ static PyObject *S_ident_o = NULL; /* identifier, held by openlog() */ static PyObject * syslog_openlog(PyObject * self, PyObject * args) { long logopt = 0; long facility = LOG_USER; PyObject *new_S_ident_o; const char *ident; if (!PyArg_ParseTuple(args, "U|ll;ident string [, logoption [, facility]]", &new_S_ident_o, &logopt, &facility)) return NULL; /* This is needed because openlog() does NOT make a copy * and syslog() later uses it.. cannot trash it. */ Py_XDECREF(S_ident_o); S_ident_o = new_S_ident_o; Py_INCREF(S_ident_o); ident = _PyUnicode_AsString(S_ident_o); if (ident == NULL) return NULL; openlog(ident, logopt, facility); Py_INCREF(Py_None); return Py_None; } static PyObject * syslog_syslog(PyObject * self, PyObject * args) { PyObject *message_object; const char *message; int priority = LOG_INFO; if (!PyArg_ParseTuple(args, "iU;[priority,] message string", &priority, &message_object)) { PyErr_Clear(); if (!PyArg_ParseTuple(args, "U;[priority,] message string", &message_object)) return NULL; } message = _PyUnicode_AsString(message_object); if (message == NULL) return NULL; Py_BEGIN_ALLOW_THREADS; syslog(priority, "%s", message); Py_END_ALLOW_THREADS; Py_RETURN_NONE; } static PyObject * syslog_closelog(PyObject *self, PyObject *unused) { closelog(); Py_XDECREF(S_ident_o); S_ident_o = NULL; Py_INCREF(Py_None); return Py_None; } static PyObject * syslog_setlogmask(PyObject *self, PyObject *args) { long maskpri, omaskpri; if (!PyArg_ParseTuple(args, "l;mask for priority", &maskpri)) return NULL; omaskpri = setlogmask(maskpri); return PyLong_FromLong(omaskpri); } static PyObject * syslog_log_mask(PyObject *self, PyObject *args) { long mask; long pri; if (!PyArg_ParseTuple(args, "l:LOG_MASK", &pri)) return NULL; mask = LOG_MASK(pri); return PyLong_FromLong(mask); } static PyObject * syslog_log_upto(PyObject *self, PyObject *args) { long mask; long pri; if (!PyArg_ParseTuple(args, "l:LOG_UPTO", &pri)) return NULL; mask = LOG_UPTO(pri); return PyLong_FromLong(mask); } /* List of functions defined in the module */ static PyMethodDef syslog_methods[] = { {"openlog", syslog_openlog, METH_VARARGS}, {"closelog", syslog_closelog, METH_NOARGS}, {"syslog", syslog_syslog, METH_VARARGS}, {"setlogmask", syslog_setlogmask, METH_VARARGS}, {"LOG_MASK", syslog_log_mask, METH_VARARGS}, {"LOG_UPTO", syslog_log_upto, METH_VARARGS}, {NULL, NULL, 0} }; /* Initialization function for the module */ static struct PyModuleDef syslogmodule = { PyModuleDef_HEAD_INIT, "syslog", NULL, -1, syslog_methods, NULL, NULL, NULL, NULL }; PyMODINIT_FUNC PyInit_syslog(void) { PyObject *m; /* Create the module and add the functions */ m = PyModule_Create(&syslogmodule); if (m == NULL) return NULL; /* Add some symbolic constants to the module */ /* Priorities */ PyModule_AddIntConstant(m, "LOG_EMERG", LOG_EMERG); PyModule_AddIntConstant(m, "LOG_ALERT", LOG_ALERT); PyModule_AddIntConstant(m, "LOG_CRIT", LOG_CRIT); PyModule_AddIntConstant(m, "LOG_ERR", LOG_ERR); PyModule_AddIntConstant(m, "LOG_WARNING", LOG_WARNING); PyModule_AddIntConstant(m, "LOG_NOTICE", LOG_NOTICE); PyModule_AddIntConstant(m, "LOG_INFO", LOG_INFO); PyModule_AddIntConstant(m, "LOG_DEBUG", LOG_DEBUG); /* openlog() option flags */ PyModule_AddIntConstant(m, "LOG_PID", LOG_PID); PyModule_AddIntConstant(m, "LOG_CONS", LOG_CONS); PyModule_AddIntConstant(m, "LOG_NDELAY", LOG_NDELAY); #ifdef LOG_NOWAIT PyModule_AddIntConstant(m, "LOG_NOWAIT", LOG_NOWAIT); #endif #ifdef LOG_PERROR PyModule_AddIntConstant(m, "LOG_PERROR", LOG_PERROR); #endif /* Facilities */ PyModule_AddIntConstant(m, "LOG_KERN", LOG_KERN); PyModule_AddIntConstant(m, "LOG_USER", LOG_USER); PyModule_AddIntConstant(m, "LOG_MAIL", LOG_MAIL); PyModule_AddIntConstant(m, "LOG_DAEMON", LOG_DAEMON); PyModule_AddIntConstant(m, "LOG_AUTH", LOG_AUTH); PyModule_AddIntConstant(m, "LOG_LPR", LOG_LPR); PyModule_AddIntConstant(m, "LOG_LOCAL0", LOG_LOCAL0); PyModule_AddIntConstant(m, "LOG_LOCAL1", LOG_LOCAL1); PyModule_AddIntConstant(m, "LOG_LOCAL2", LOG_LOCAL2); PyModule_AddIntConstant(m, "LOG_LOCAL3", LOG_LOCAL3); PyModule_AddIntConstant(m, "LOG_LOCAL4", LOG_LOCAL4); PyModule_AddIntConstant(m, "LOG_LOCAL5", LOG_LOCAL5); PyModule_AddIntConstant(m, "LOG_LOCAL6", LOG_LOCAL6); PyModule_AddIntConstant(m, "LOG_LOCAL7", LOG_LOCAL7); #ifndef LOG_SYSLOG #define LOG_SYSLOG LOG_DAEMON #endif #ifndef LOG_NEWS #define LOG_NEWS LOG_MAIL #endif #ifndef LOG_UUCP #define LOG_UUCP LOG_MAIL #endif #ifndef LOG_CRON #define LOG_CRON LOG_DAEMON #endif PyModule_AddIntConstant(m, "LOG_SYSLOG", LOG_SYSLOG); PyModule_AddIntConstant(m, "LOG_CRON", LOG_CRON); PyModule_AddIntConstant(m, "LOG_UUCP", LOG_UUCP); PyModule_AddIntConstant(m, "LOG_NEWS", LOG_NEWS); return m; }
