ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-checkins
python-checkins
[Python-checkins] r45573 - in python/trunk: Doc/lib/libos.tex Lib/test/test_posix.py Modules/posixmodule.c
by Skip.Montanaro other posts by this author
Apr 19 2006 6:30PM messages near this date
[Python-checkins] r45574 - python/trunk/Misc/NEWS | Re: [Python-checkins] r45573 - in python/trunk: Doc/lib/libos.tex Lib/test/test_posix.py Modules/posixmodule.c
Author: skip.montanaro
Date: Thu Apr 20 03:29:48 2006
New Revision: 45573

Modified:
   python/trunk/Doc/lib/libos.tex
   python/trunk/Lib/test/test_posix.py
   python/trunk/Modules/posixmodule.c
Log:
Correct implementation and documentation of os.confstr.  Add a simple test
case.  I've yet to figure out how to provoke a None return I can test.


Modified: python/trunk/Doc/lib/libos.tex
==============================================================================
--- python/trunk/Doc/lib/libos.tex	(original)
+++ python/trunk/Doc/lib/libos.tex	Thu Apr 20 03:29:48 2006
@@ -1844,14 +1844,14 @@
 string which is the name of a defined system value; these names are
 specified in a number of standards (\POSIX, \UNIX{} 95, \UNIX{} 98, and
 others).  Some platforms define additional names as well.  The names
-known to the host operating system are given in the
+known to the host operating system are given as the keys of the
 \code{confstr_names} dictionary.  For configuration variables not
 included in that mapping, passing an integer for \var{name} is also
 accepted.
 Availability: Macintosh, \UNIX.
 
-If the configuration value specified by \var{name} isn't defined, the
-empty string is returned.
+If the configuration value specified by \var{name} isn't defined,
+\code{None} is returned.
 
 If \var{name} is a string and is not known, \exception{ValueError} is
 raised.  If a specific value for \var{name} is not supported by the

Modified: python/trunk/Lib/test/test_posix.py
==============================================================================
--- python/trunk/Lib/test/test_posix.py	(original)
+++ python/trunk/Lib/test/test_posix.py	Thu Apr 20 03:29:48 2006
@@ -73,6 +73,11 @@
             finally:
                 fp.close()
 
+    def test_confstr(self):
+        if hasattr(posix, 'confstr'):
+            self.assertRaises(ValueError, posix.confstr, "CS_garbage")
+            self.assertEqual(len(posix.confstr("CS_PATH")) >  0, True)
+
     def test_dup2(self):
         if hasattr(posix, 'dup2'):
             fp1 = open(test_support.TESTFN)

Modified: python/trunk/Modules/posixmodule.c
==============================================================================
--- python/trunk/Modules/posixmodule.c	(original)
+++ python/trunk/Modules/posixmodule.c	Thu Apr 20 03:29:48 2006
@@ -6817,15 +6817,18 @@
         errno = 0;
 	len = confstr(name, buffer, sizeof(buffer));
 
-	if (len == -1) {
-	    posix_error();
-	}
-	else if (len == 0) {
-            result = PyString_FromString("");
+	if (len == 0) {
+	    if (errno) {
+		posix_error();
+	    }
+	    else {
+		result = Py_None;
+		Py_INCREF(Py_None);
+	    }
         }
         else {
 		if ((unsigned int)len > = sizeof(buffer)) {
-                result = PyString_FromStringAndSize(NULL, len);
+                result = PyString_FromStringAndSize(NULL, len+1);
                 if (result != NULL)
                     confstr(name, PyString_AS_STRING(result), len+1);
             }
_______________________________________________
Python-checkins mailing list
Python-checkins@[...].org
http://mail.python.org/mailman/listinfo/python-checkins
Thread:
Skip.Montanaro
"Martin v. Löwis"
Neal Norwitz
"Martin v. Löwis"

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved