mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Issue #8603: Create a bytes version of os.environ for Unix
Create os.environb mapping and os.getenvb() function, os.unsetenv() encodes str argument to the file system encoding with the surrogateescape error handler (instead of utf8/strict) and accepts bytes, and posix.environ keys and values are bytes.
This commit is contained in:
parent
d930b63583
commit
84ae118006
7 changed files with 190 additions and 54 deletions
|
@ -69,17 +69,22 @@ In addition to many functions described in the :mod:`os` module documentation,
|
|||
.. data:: environ
|
||||
|
||||
A dictionary representing the string environment at the time the interpreter
|
||||
was started. For example, ``environ['HOME']`` is the pathname of your home
|
||||
directory, equivalent to ``getenv("HOME")`` in C.
|
||||
was started. Keys and values are bytes on Unix and str on Windows. For
|
||||
example, ``environ[b'HOME']`` (``environ['HOME']`` on Windows) is the
|
||||
pathname of your home directory, equivalent to ``getenv("HOME")`` in C.
|
||||
|
||||
Modifying this dictionary does not affect the string environment passed on by
|
||||
:func:`execv`, :func:`popen` or :func:`system`; if you need to change the
|
||||
environment, pass ``environ`` to :func:`execve` or add variable assignments and
|
||||
export statements to the command string for :func:`system` or :func:`popen`.
|
||||
|
||||
.. versionchanged:: 3.2
|
||||
On Unix, keys and values are bytes.
|
||||
|
||||
.. note::
|
||||
|
||||
The :mod:`os` module provides an alternate implementation of ``environ`` which
|
||||
updates the environment on modification. Note also that updating ``os.environ``
|
||||
will render this dictionary obsolete. Use of the :mod:`os` module version of
|
||||
this is recommended over direct access to the :mod:`posix` module.
|
||||
The :mod:`os` module provides an alternate implementation of ``environ``
|
||||
which updates the environment on modification. Note also that updating
|
||||
:data:`os.environ` will render this dictionary obsolete. Use of the
|
||||
:mod:`os` module version of this is recommended over direct access to the
|
||||
:mod:`posix` module.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue