Author: Amaury Forgeot d'Arc <[email protected]>
Branch: 
Changeset: r60631:3b27811312df
Date: 2013-01-28 20:38 +0100
http://bitbucket.org/pypy/pypy/changeset/3b27811312df/

Log:    Add rposix.putenv() and unsetenv(), which support unicode strings.
        Python2.7 don't use them, though.

diff --git a/rpython/rlib/rposix.py b/rpython/rlib/rposix.py
--- a/rpython/rlib/rposix.py
+++ b/rpython/rlib/rposix.py
@@ -247,6 +247,20 @@
         else:
             return nt._getfullpathname(path.as_bytes())
 
[email protected](0, 1)
+def putenv(name, value):
+    if isinstance(name, str):
+        os.environ[name] = value
+    else:
+        os.environ[name.as_bytes()] = value.as_bytes()
+
[email protected](0)
+def unsetenv(name):
+    if isinstance(name, str):
+        del os.environ[name]
+    else:
+        del os.environ[name.as_bytes()]
+
 if os.name == 'nt':
     from rpython.rlib import rwin32
     os_kill = rwin32.os_kill
diff --git a/rpython/rlib/test/test_rposix.py b/rpython/rlib/test/test_rposix.py
--- a/rpython/rlib/test/test_rposix.py
+++ b/rpython/rlib/test/test_rposix.py
@@ -141,3 +141,10 @@
         assert rposix.is_valid_fd(fd) == 1
         fid.close()
         assert rposix.is_valid_fd(fd) == 0
+
+    def test_putenv(self):
+        def f():
+            rposix.putenv(self.path, self.path)
+            rposix.unsetenv(self.path)
+
+        interpret(f, []) # does not crash
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to