[issue20658] os.environ.clear() fails with empty keys (posix.unsetenv)

2021-09-04 Thread STINNER Victor
STINNER Victor added the comment: POSIX says: (1) "The setenv() function shall fail if: [EINVAL] The name argument is a null pointer, points to an empty string, or points to a string containing an '=' character." https://pubs.opengroup.org/onlinepubs/009604499/functions/setenv.html (2)

[issue20658] os.environ.clear() fails with empty keys (posix.unsetenv)

2021-09-04 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: > For the very specific case of os.environ.clear(), the C function clearenv() > could be used if available. It is bad in any way. The supposed example of using clear(): old_environ = dict(os.environ) os.environ.clear()

[issue20658] os.environ.clear() fails with empty keys (posix.unsetenv)

2021-09-03 Thread Terry J. Reedy
Change by Terry J. Reedy : -- versions: +Python 3.11 -Python 2.7, Python 3.3, Python 3.4 ___ Python tracker ___ ___

[issue20658] os.environ.clear() fails with empty keys (posix.unsetenv)

2021-08-30 Thread STINNER Victor
STINNER Victor added the comment: For the very specific case of os.environ.clear(), the C function clearenv() could be used if available. While clearenv() is available in the glibc, it's not a POSIX function. -- ___ Python tracker

[issue20658] os.environ.clear() fails with empty keys (posix.unsetenv)

2021-08-30 Thread STINNER Victor
STINNER Victor added the comment: Attached set_unset_env.c program calls putenv("=hello world") and then unsetenv(""). On my Fedora 34 with glibc-2.33-20.fc34.x86_64, putenv() succeed, but unsetenv() fails. --- $ gcc set_unset_env.c -g -o set_unset_env && ./set_unset_env putenv("=hello

[issue20658] os.environ.clear() fails with empty keys (posix.unsetenv)

2021-08-30 Thread Irit Katriel
Irit Katriel added the comment: I see, so intercepting the assignment is not enough. Reopening. -- resolution: out of date -> status: closed -> open ___ Python tracker ___

[issue20658] os.environ.clear() fails with empty keys (posix.unsetenv)

2021-08-30 Thread STINNER Victor
STINNER Victor added the comment: By the way: --- The env command from GNU coreutils supports setting the environment variable with an empty name but not unsetting it. That's a bug. $ env '=wibble' env |grep wibble =wibble $ env '=wibble' env -u '' env env:

[issue20658] os.environ.clear() fails with empty keys (posix.unsetenv)

2021-08-30 Thread STINNER Victor
STINNER Victor added the comment: The following command still fails on the Python main branch on Linux: --- $ env -i =value ./python -c 'import pprint, os; pprint.pprint(os.environ); del os.environ[""]' environ({'': 'value', 'LC_CTYPE': 'C.UTF-8'}) Traceback (most recent call last): File

[issue20658] os.environ.clear() fails with empty keys (posix.unsetenv)

2021-08-30 Thread Irit Katriel
Change by Irit Katriel : -- stage: test needed -> resolved status: pending -> closed ___ Python tracker ___ ___ Python-bugs-list

[issue20658] os.environ.clear() fails with empty keys (posix.unsetenv)

2021-08-28 Thread Irit Katriel
Irit Katriel added the comment: They keys are checked now, so I think this is resolved. (Tested on windows and Mac). >>> os.environ[''] = 'X' Traceback (most recent call last): File "", line 1, in File "/Users/iritkatriel/src/cpython/Lib/os.py", line 684, in __setitem__ putenv(key,

[issue20658] os.environ.clear() fails with empty keys (posix.unsetenv)

2015-10-05 Thread Peter Funk
Changes by Peter Funk : -- nosy: +pefu ___ Python tracker ___ ___

[issue20658] os.environ.clear() fails with empty keys (posix.unsetenv)

2014-02-27 Thread akira
akira added the comment: Related: issue4926 putenv() accepts names containing '=', return value of unsetenv() not checked `os.environ.clear()` also fails if the environment contains names with `=`: import os os.environ['a=b'] = 'c' os.environ.clear() Traceback (most recent call

[issue20658] os.environ.clear() fails with empty keys (posix.unsetenv)

2014-02-19 Thread daniel hahler
daniel hahler added the comment: Please note that I have noticed this not because of setting it via `os.environ`, but because a program using `os.environ.clear()` crashed: https://bugs.launchpad.net/ubuntu/+source/apport/+bug/1281086 I cannot say how this unusual entry was added to the

[issue20658] os.environ.clear() fails with empty keys (posix.unsetenv)

2014-02-19 Thread STINNER Victor
STINNER Victor added the comment: Please note that I have noticed this not because of setting it via `os.environ`, but because a program using `os.environ.clear()` crashed: https://bugs.launchpad.net/ubuntu/+source/apport/+bug/1281086; The bug is not os.environ.clear(), but that os.environ

[issue20658] os.environ.clear() fails with empty keys (posix.unsetenv)

2014-02-19 Thread daniel hahler
daniel hahler added the comment: It would help to know if the key was set manually by apport, or if it comes from the real environment. The environment looks correct: It comes from the real environment. I wanted to use apport, but could not from the current shell, because of this bug. I

[issue20658] os.environ.clear() fails with empty keys (posix.unsetenv)

2014-02-19 Thread STINNER Victor
STINNER Victor added the comment: It comes from the real environment. Oh. It looks possible to define an environment variable with an empty key, but not to remove it: $ env -i =value python -c 'import pprint, os; pprint.pprint(os.environ); del os.environ[]' environ({'': 'value'}) Traceback

[issue20658] os.environ.clear() fails with empty keys (posix.unsetenv)

2014-02-19 Thread STINNER Victor
STINNER Victor added the comment: By the way, Python allows also to set an environment with a name containing =, whereas getenv/setenv/unsetenv doesn't. $ env -i python -c 'import pprint, posix, os; os.environ[a=]=1; print(os.environ); posix.unsetenv(a=)' environ({'a=': '1'}) Traceback (most

[issue20658] os.environ.clear() fails with empty keys (posix.unsetenv)

2014-02-19 Thread Serhiy Storchaka
Changes by Serhiy Storchaka storch...@gmail.com: -- Removed message: http://bugs.python.org/msg211621 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20658 ___

[issue20658] os.environ.clear() fails with empty keys (posix.unsetenv)

2014-02-19 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Are there supported platforms on which setenv() is not supported? When we will migrate to setenv(), an argument check will be not needed. In any case I think we should wrap unsetenv() in os.environ.clear() so that it should try to remove all environment

[issue20658] os.environ.clear() fails with empty keys (posix.unsetenv)

2014-02-19 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Are there supported platforms on which setenv() is not supported. -- nosy: +serhiy.storchaka ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20658 ___

[issue20658] os.environ.clear() fails with empty keys (posix.unsetenv)

2014-02-19 Thread STINNER Victor
STINNER Victor added the comment: In fact, there is also a clearenv() function which could be used by os.environ.clear(). The clearenv() function clears the environment of all name-value pairs and sets the value of the external variable environ to NULL. It looks like supported names depends

[issue20658] os.environ.clear() fails with empty keys (posix.unsetenv)

2014-02-19 Thread Arfrever Frehtes Taifersar Arahesis
Changes by Arfrever Frehtes Taifersar Arahesis arfrever@gmail.com: -- nosy: +Arfrever ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20658 ___

[issue20658] os.environ.clear() fails with empty keys (posix.unsetenv)

2014-02-18 Thread STINNER Victor
STINNER Victor added the comment: putenv(=value) does nothing: it doesn't create a variable with an empty name. You can test with the attach test_empty_env_var.py script (written for Linux). Attached reject_empty_env_var.patch patch modifies posix.putenv() to raise a ValueError if the name is

[issue20658] os.environ.clear() fails with empty keys (posix.unsetenv)

2014-02-18 Thread STINNER Victor
Changes by STINNER Victor victor.stin...@gmail.com: -- keywords: +patch Added file: http://bugs.python.org/file34133/reject_empty_env_var.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20658

[issue20658] os.environ.clear() fails with empty keys (posix.unsetenv)

2014-02-18 Thread STINNER Victor
STINNER Victor added the comment: The workaround of this bug is to avoid os.environ['']=value. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20658 ___

[issue20658] os.environ.clear() fails with empty keys (posix.unsetenv)

2014-02-17 Thread daniel hahler
New submission from daniel hahler: posix.unsetenv fails to clear the environment if there's an entry with an empty key. TEST CASE: Python 2.7.6 (default, Jan 6 2014, 17:05:19) [GCC 4.8.1] on linux2 Type help, copyright, credits or license for more information. import os

[issue20658] os.environ.clear() fails with empty keys (posix.unsetenv)

2014-02-17 Thread Ned Deily
Ned Deily added the comment: According to the Open Group Base Specification (Issue 7 2013 Issue): The setenv() function shall fail if: [EINVAL] The envname argument points to an empty string or points to a string containing an '=' character. So it seems to me that the issue here is that

[issue20658] os.environ.clear() fails with empty keys (posix.unsetenv)

2014-02-17 Thread Ned Deily
Ned Deily added the comment: OTOH, the specification for putenv, which is what is actually used by posixmodule.c, does not contain that requirement. http://pubs.opengroup.org/onlinepubs/9699919799/functions/putenv.html http://pubs.opengroup.org/onlinepubs/9699919799/functions/setenv.html