Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
19e4acfa
Commit
19e4acfa
authored
Feb 22, 2010
by
Ezio Melotti
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#7310: fix the repr() of os.environ
parent
5961b0e3
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
20 additions
and
0 deletions
+20
-0
Lib/os.py
Lib/os.py
+10
-0
Lib/test/test_os.py
Lib/test/test_os.py
+8
-0
Misc/NEWS
Misc/NEWS
+2
-0
No files found.
Lib/os.py
View file @
19e4acfa
...
...
@@ -387,22 +387,32 @@ class _Environ(MutableMapping):
self
.
data
=
data
=
{}
for
key
,
value
in
environ
.
items
():
data
[
keymap
(
key
)]
=
str
(
value
)
def
__getitem__
(
self
,
key
):
return
self
.
data
[
self
.
keymap
(
key
)]
def
__setitem__
(
self
,
key
,
value
):
value
=
str
(
value
)
self
.
putenv
(
key
,
value
)
self
.
data
[
self
.
keymap
(
key
)]
=
value
def
__delitem__
(
self
,
key
):
self
.
unsetenv
(
key
)
del
self
.
data
[
self
.
keymap
(
key
)]
def
__iter__
(
self
):
for
key
in
self
.
data
:
yield
key
def
__len__
(
self
):
return
len
(
self
.
data
)
def
__repr__
(
self
):
return
'environ({!r})'
.
format
(
self
.
data
)
def
copy
(
self
):
return
dict
(
self
)
def
setdefault
(
self
,
key
,
value
):
if
key
not
in
self
:
self
[
key
]
=
value
...
...
Lib/test/test_os.py
View file @
19e4acfa
...
...
@@ -400,6 +400,14 @@ class EnvironTests(mapping_tests.BasicTestMappingProtocol):
for
key
,
value
in
self
.
_reference
().
items
():
self
.
assertEqual
(
os
.
environ
.
get
(
key
),
value
)
# Issue 7310
def
test___repr__
(
self
):
"""Check that the repr() of os.environ looks like environ({...})."""
env
=
os
.
environ
self
.
assertTrue
(
isinstance
(
env
.
data
,
dict
))
self
.
assertEqual
(
repr
(
env
),
'environ({!r})'
.
format
(
env
.
data
))
class
WalkTests
(
unittest
.
TestCase
):
"""Tests for os.walk()."""
...
...
Misc/NEWS
View file @
19e4acfa
...
...
@@ -247,6 +247,8 @@ C-API
Library
-------
- Issue #7310: fix the __repr__ of os.environ to show the environment variables.
- Issue #7970: email.Generator.flatten now correctly flattens message/rfc822
messages parsed by email.Parser.HeaderParser.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment