Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
13833560
Kaydet (Commit)
13833560
authored
Agu 07, 1995
tarafından
Guido van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
added sys.std files, read-only open, reload
üst
221df249
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
104 additions
and
3 deletions
+104
-3
rexec.py
Lib/rexec.py
+104
-3
No files found.
Lib/rexec.py
Dosyayı görüntüle @
13833560
...
@@ -11,6 +11,11 @@ available; this module provides a reasonable default, but derived
...
@@ -11,6 +11,11 @@ available; this module provides a reasonable default, but derived
classes can change the policies e.g. by overriding or extending class
classes can change the policies e.g. by overriding or extending class
variables like ok_builtin_modules or methods like make_sys().
variables like ok_builtin_modules or methods like make_sys().
XXX To do:
- r_open should allow writing tmp dir
- r_exec etc. with explicit globals/locals? (Use rexec("exec ... in ...")?)
- r_reload should reload from same location (that's one for ihooks?)
"""
"""
...
@@ -21,6 +26,39 @@ import marshal
...
@@ -21,6 +26,39 @@ import marshal
import
ihooks
import
ihooks
class
FileBase
:
ok_file_methods
=
(
'fileno'
,
'flush'
,
'isatty'
,
'read'
,
'readline'
,
'readlines'
,
'seek'
,
'tell'
,
'write'
,
'writelines'
)
class
FileWrapper
(
FileBase
):
def
__init__
(
self
,
f
):
self
.
f
=
f
for
m
in
self
.
ok_file_methods
:
if
not
hasattr
(
self
,
m
):
setattr
(
self
,
m
,
getattr
(
f
,
m
))
def
close
(
f
):
self
.
flush
()
TEMPLATE
=
"""
def
%
s(self, *args):
return apply(getattr(self.mod, self.name).
%
s, args)
"""
class
FileDelegate
(
FileBase
):
def
__init__
(
self
,
mod
,
name
):
self
.
mod
=
mod
self
.
name
=
name
for
m
in
FileBase
.
ok_file_methods
+
(
'close'
,):
exec
TEMPLATE
%
(
m
,
m
)
class
RHooks
(
ihooks
.
Hooks
):
class
RHooks
(
ihooks
.
Hooks
):
def
__init__
(
self
,
rexec
,
verbose
=
0
):
def
__init__
(
self
,
rexec
,
verbose
=
0
):
...
@@ -53,12 +91,19 @@ class RHooks(ihooks.Hooks):
...
@@ -53,12 +91,19 @@ class RHooks(ihooks.Hooks):
class
RModuleLoader
(
ihooks
.
FancyModuleLoader
):
class
RModuleLoader
(
ihooks
.
FancyModuleLoader
):
pass
def
load_module
(
self
,
name
,
stuff
):
file
,
filename
,
info
=
stuff
m
=
ihooks
.
FancyModuleLoader
.
load_module
(
self
,
name
,
stuff
)
m
.
__filename__
=
filename
return
m
class
RModuleImporter
(
ihooks
.
ModuleImporter
):
class
RModuleImporter
(
ihooks
.
ModuleImporter
):
pass
def
reload
(
self
,
module
,
path
=
None
):
if
path
is
None
and
hasattr
(
module
,
'__filename__'
):
path
=
[
module
.
__filename__
]
return
ihooks
.
ModuleImporter
.
reload
(
self
,
module
,
path
)
class
RExec
(
ihooks
.
_Verbose
):
class
RExec
(
ihooks
.
_Verbose
):
...
@@ -78,7 +123,7 @@ class RExec(ihooks._Verbose):
...
@@ -78,7 +123,7 @@ class RExec(ihooks._Verbose):
ok_sys_names
=
(
'ps1'
,
'ps2'
,
'copyright'
,
'version'
,
ok_sys_names
=
(
'ps1'
,
'ps2'
,
'copyright'
,
'version'
,
'platform'
,
'exit'
,
'maxint'
)
'platform'
,
'exit'
,
'maxint'
)
nok_builtin_names
=
(
'open'
,
'reload'
,
'__import__'
,
'raw_input'
,
'input'
)
nok_builtin_names
=
(
'open'
,
'reload'
,
'__import__'
)
def
__init__
(
self
,
hooks
=
None
,
verbose
=
0
):
def
__init__
(
self
,
hooks
=
None
,
verbose
=
0
):
ihooks
.
_Verbose
.
__init__
(
self
,
verbose
)
ihooks
.
_Verbose
.
__init__
(
self
,
verbose
)
...
@@ -110,6 +155,8 @@ class RExec(ihooks._Verbose):
...
@@ -110,6 +155,8 @@ class RExec(ihooks._Verbose):
def
make_builtin
(
self
):
def
make_builtin
(
self
):
m
=
self
.
copy_except
(
__builtin__
,
self
.
nok_builtin_names
)
m
=
self
.
copy_except
(
__builtin__
,
self
.
nok_builtin_names
)
m
.
__import__
=
self
.
r_import
m
.
__import__
=
self
.
r_import
m
.
reload
=
self
.
r_reload
m
.
open
=
self
.
r_open
def
make_main
(
self
):
def
make_main
(
self
):
m
=
self
.
add_module
(
'__main__'
)
m
=
self
.
add_module
(
'__main__'
)
...
@@ -180,6 +227,60 @@ class RExec(ihooks._Verbose):
...
@@ -180,6 +227,60 @@ class RExec(ihooks._Verbose):
def
r_import
(
self
,
mname
,
globals
=
{},
locals
=
{},
fromlist
=
[]):
def
r_import
(
self
,
mname
,
globals
=
{},
locals
=
{},
fromlist
=
[]):
return
self
.
importer
.
import_module
(
mname
,
globals
,
locals
,
fromlist
)
return
self
.
importer
.
import_module
(
mname
,
globals
,
locals
,
fromlist
)
def
r_reload
(
self
,
m
):
return
self
.
importer
.
reload
(
m
)
# The s_* methods are similar but also swap std{in,out,err}
def
set_files
(
self
):
s
=
self
.
modules
[
'sys'
]
s
.
stdin
=
FileWrapper
(
sys
.
stdin
)
s
.
stdout
=
FileWrapper
(
sys
.
stdout
)
s
.
stderr
=
FileWrapper
(
sys
.
stderr
)
sys
.
stdin
=
FileDelegate
(
s
,
'stdin'
)
sys
.
stdout
=
FileDelegate
(
s
,
'stdout'
)
sys
.
stderr
=
FileDelegate
(
s
,
'stderr'
)
def
save_files
(
self
):
self
.
save_stdin
=
sys
.
stdin
self
.
save_stdout
=
sys
.
stdout
self
.
save_stderr
=
sys
.
stderr
def
restore_files
(
files
):
sys
.
stdin
=
self
.
save_sydin
sys
.
stdout
=
self
.
save_stdout
sys
.
stderr
=
self
.
save_stderr
def
s_apply
(
self
,
func
,
*
args
,
**
kw
):
self
.
save_files
()
try
:
self
.
set_files
()
r
=
apply
(
func
,
args
,
kw
)
finally
:
self
.
restore_files
()
def
s_exec
(
self
,
*
args
):
self
.
s_apply
(
self
.
r_exec
,
args
)
def
s_eval
(
self
,
*
args
):
self
.
s_apply
(
self
.
r_eval
,
args
)
def
s_execfile
(
self
,
*
args
):
self
.
s_apply
(
self
.
r_execfile
,
args
)
def
s_import
(
self
,
*
args
):
self
.
s_apply
(
self
.
r_import
,
args
)
def
s_reload
(
self
,
*
args
):
self
.
s_apply
(
self
.
r_reload
,
args
)
# Restricted open(...)
def
r_open
(
self
,
file
,
mode
=
'r'
,
buf
=-
1
):
if
mode
not
in
(
'r'
,
'rb'
):
raise
IOError
,
"can't open files for writing in restricted mode"
return
open
(
file
,
'r'
,
buf
)
def
test
():
def
test
():
import
traceback
import
traceback
...
...
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