forked from python/cpython
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsys.py
More file actions
51 lines (35 loc) · 1.15 KB
/
sys.py
File metadata and controls
51 lines (35 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"""This module provides access to some objects used or maintained by the
interpreter and to functions that interact strongly with the interpreter.
This is a wrapper around the low-level _sys module.
"""
import _sys
MODULE_ATTRS = [
"__name__",
"__doc__",
"__loader__",
"__spec__",
"__package__",
# not in _sys:
"__file__",
"__cached__",
"__builtins__",
]
# For now we strictly proxy _sys.
class SysModule(type(_sys)):
# XXX What about cases of "moduletype = type(sys)"?
def __init__(self, name, *, _ns=None):
super().__init__(name)
if _ns is not None:
for attr in MODULE_ATTRS:
object.__setattr__(self, name, _ns[attr])
def __dir__(self):
return sorted(dir(_sys) + MODULE_ATTRS)
def __getattr__(self, name):
return getattr(_sys, name)
def __setattr__(self, name, value):
# XXX Only wrap existing attrs?
setattr(_sys, name, value)
def __delattr__(self, name):
# XXX Only wrap existing attrs?
delattr(_sys, name)
_sys.modules[__name__] = SysModule(__name__, _ns=vars())