[Python-3000-checkins] r57437 - in python/branches/py3k: Lib/test/test_syslog.py Modules/syslogmodule.c

neal.norwitz python-3000-checkins at python.org
Sat Aug 25 02:21:36 CEST 2007


Author: neal.norwitz
Date: Sat Aug 25 02:21:36 2007
New Revision: 57437

Added:
   python/branches/py3k/Lib/test/test_syslog.py   (contents, props changed)
Modified:
   python/branches/py3k/Modules/syslogmodule.c
Log:
Use unicode and add a "test" for syslog

Added: python/branches/py3k/Lib/test/test_syslog.py
==============================================================================
--- (empty file)
+++ python/branches/py3k/Lib/test/test_syslog.py	Sat Aug 25 02:21:36 2007
@@ -0,0 +1,37 @@
+
+import syslog
+import unittest
+from test import test_support
+
+# XXX(nnorwitz): This test sucks.  I don't know of a platform independent way
+# to verify that the messages were really logged.
+# The only purpose of this test is to verify the code doesn't crash or leak.
+
+class Test(unittest.TestCase):
+
+    def test_openlog(self):
+        syslog.openlog('python')
+
+    def test_syslog(self):
+        syslog.openlog('python')
+        syslog.syslog('test message from python test_syslog')
+        syslog.syslog(syslog.LOG_ERR, 'test error from python test_syslog')
+
+    def test_closelog(self):
+        syslog.openlog('python')
+        syslog.closelog()
+
+    def test_setlogmask(self):
+        syslog.setlogmask(syslog.LOG_DEBUG)
+
+    def test_log_mask(self):
+        syslog.LOG_MASK(syslog.LOG_INFO)
+
+    def test_log_upto(self):
+        syslog.LOG_UPTO(syslog.LOG_INFO)
+
+def test_main():
+    test_support.run_unittest(__name__)
+
+if __name__ == "__main__":
+    test_main()

Modified: python/branches/py3k/Modules/syslogmodule.c
==============================================================================
--- python/branches/py3k/Modules/syslogmodule.c	(original)
+++ python/branches/py3k/Modules/syslogmodule.c	Sat Aug 25 02:21:36 2007
@@ -58,9 +58,10 @@
 	long logopt = 0;
 	long facility = LOG_USER;
 	PyObject *new_S_ident_o;
+	const char *ident;
 
 	if (!PyArg_ParseTuple(args,
-			      "S|ll;ident string [, logoption [, facility]]",
+			      "U|ll;ident string [, logoption [, facility]]",
 			      &new_S_ident_o, &logopt, &facility))
 		return NULL;
 
@@ -71,7 +72,10 @@
 	S_ident_o = new_S_ident_o;
 	Py_INCREF(S_ident_o);
 
-	openlog(PyString_AsString(S_ident_o), logopt, facility);
+	ident = PyUnicode_AsString(S_ident_o);
+	if (ident == NULL)
+		return NULL;
+	openlog(ident, logopt, facility);
 
 	Py_INCREF(Py_None);
 	return Py_None;
@@ -81,17 +85,21 @@
 static PyObject * 
 syslog_syslog(PyObject * self, PyObject * args)
 {
-	char *message;
+	PyObject *message_object;
+	const char *message;
 	int   priority = LOG_INFO;
 
-	if (!PyArg_ParseTuple(args, "is;[priority,] message string",
-			      &priority, &message)) {
+	if (!PyArg_ParseTuple(args, "iU;[priority,] message string",
+			      &priority, &message_objecct)) {
 		PyErr_Clear();
-		if (!PyArg_ParseTuple(args, "s;[priority,] message string",
-				      &message))
+		if (!PyArg_ParseTuple(args, "U;[priority,] message string",
+				      &message_objecct))
 			return NULL;
 	}
 
+	message = PyUnicode_AsString(message_object);
+	if (message == NULL)
+		return NULL;
 	syslog(priority, "%s", message);
 	Py_INCREF(Py_None);
 	return Py_None;


More information about the Python-3000-checkins mailing list