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
a8912306
Kaydet (Commit)
a8912306
authored
Mar 14, 1998
tarafından
Fred Drake
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Logical markup, using {classdesc} as appropriate.
üst
f9e1f658
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
50 deletions
+50
-50
librexec.tex
Doc/lib/librexec.tex
+25
-25
librexec.tex
Doc/librexec.tex
+25
-25
No files found.
Doc/lib/librexec.tex
Dosyayı görüntüle @
a8912306
\section
{
Standard Module
\sectcode
{
rexec
}}
\label
{
module-rexec
}
\stmodindex
{
rexec
}
\setindexsubitem
{
(in module rexec)
}
This module contains the
\class
{
RExec
}
class, which supports
\
code
{
r
_
exec()
}
,
\code
{
r
_
eval()
}
,
\code
{
r
_
execfile()
}
, and
\
code
{
r
_
import()
}
methods, which are restricted versions of the standard
Python functions
\
code
{
exec()
}
,
\code
{
eval()
}
,
\code
{
execfile()
}
, and
the
\
code
{
import
}
statement.
\
method
{
r
_
exec()
}
,
\method
{
r
_
eval()
}
,
\method
{
r
_
execfile()
}
, and
\
method
{
r
_
import()
}
methods, which are restricted versions of the standard
Python functions
\
method
{
exec()
}
,
\method
{
eval()
}
,
\method
{
execfile()
}
, and
the
\
keyword
{
import
}
statement.
Code executed in this restricted environment will
only have access to modules and functions that are deemed safe; you
can subclass
\class
{
RExec
}
to add or remove capabilities as desired.
...
...
@@ -17,11 +17,11 @@ unsafe operations like reading or writing disk files, or using TCP/IP
sockets. However, it does not protect against code using extremely
large amounts of memory or CPU time.
\begin{
funcdesc}
{
RExec
}{
\optional
{
hooks
\optional
{
\
,
verbose
}}}
\begin{
classdesc}
{
RExec
}{
\optional
{
hooks
\optional
{
, verbose
}}}
Returns an instance of the
\class
{
RExec
}
class.
\var
{
hooks
}
is an instance of the
\c
ode
{
RHooks
}
class or a subclass of it.
If it is omitted or
\code
{
None
}
, the default
\c
ode
{
RHooks
}
class is
\var
{
hooks
}
is an instance of the
\c
lass
{
RHooks
}
class or a subclass of it.
If it is omitted or
\code
{
None
}
, the default
\c
lass
{
RHooks
}
class is
instantiated.
Whenever the
\module
{
RExec
}
module searches for a module (even a
built-in one) or reads a module's code, it doesn't actually go out to
...
...
@@ -41,10 +41,10 @@ importing applets from a URL for a directory.
If
\var
{
verbose
}
is true, additional debugging output may be sent to
standard output.
\end{
func
desc}
\end{
class
desc}
The
\class
{
RExec
}
class has the following class attributes, which are
used by the
\
code
{__
init
__
()
}
method. Changing them on an existing
used by the
\
method
{__
init
__
()
}
method. Changing them on an existing
instance won't have any effect; instead, create a subclass of
\class
{
RExec
}
and assign them new values in the class definition.
Instances of the new class will then use those new values. All these
...
...
@@ -75,7 +75,7 @@ class as a starting point.
\end{datadesc}
\begin{datadesc}
{
ok
_
path
}
Contains the directories which will be searched when an
\
code
{
import
}
Contains the directories which will be searched when an
\
keyword
{
import
}
is performed in the restricted environment.
The value for
\class
{
RExec
}
is the same as
\code
{
sys.path
}
(at the time
the module is loaded) for unrestricted code.
...
...
@@ -83,7 +83,7 @@ the module is loaded) for unrestricted code.
\begin{datadesc}
{
ok
_
posix
_
names
}
% Should this be called ok_os_names?
Contains the names of the functions in the
\
cod
e
{
os
}
module which will be
Contains the names of the functions in the
\
modul
e
{
os
}
module which will be
available to programs running in the restricted environment. The
value for
\class
{
RExec
}
is
\code
{
('error',
}
\code
{
'fstat',
}
\code
{
'listdir',
}
\code
{
'lstat',
}
\code
{
'readlink',
}
\code
{
'stat',
}
...
...
@@ -93,7 +93,7 @@ value for \class{RExec} is \code{('error',} \code{'fstat',}
\end{datadesc}
\begin{datadesc}
{
ok
_
sys
_
names
}
Contains the names of the functions and variables in the
\
cod
e
{
sys
}
Contains the names of the functions and variables in the
\
modul
e
{
sys
}
module which will be available to programs running in the restricted
environment. The value for
\class
{
RExec
}
is
\code
{
('ps1',
}
\code
{
'ps2',
}
\code
{
'copyright',
}
\code
{
'version',
}
\code
{
'platform',
}
...
...
@@ -106,25 +106,25 @@ environment. The value for \class{RExec} is \code{('ps1',}
\begin{funcdesc}
{
r
_
eval
}{
code
}
\var
{
code
}
must either be a string containing a Python expression, or
a compiled code object, which will be evaluated in the restricted
environment's
\
cod
e
{__
main
__}
module. The value of the expression or
environment's
\
modul
e
{__
main
__}
module. The value of the expression or
code object will be returned.
\end{funcdesc}
\begin{funcdesc}
{
r
_
exec
}{
code
}
\var
{
code
}
must either be a string containing one or more lines of
Python code, or a compiled code object, which will be executed in the
restricted environment's
\
cod
e
{__
main
__}
module.
restricted environment's
\
modul
e
{__
main
__}
module.
\end{funcdesc}
\begin{funcdesc}
{
r
_
execfile
}{
filename
}
Execute the Python code contained in the file
\var
{
filename
}
in the
restricted environment's
\
cod
e
{__
main
__}
module.
restricted environment's
\
modul
e
{__
main
__}
module.
\end{funcdesc}
Methods whose names begin with
\
code
{
s
_}
are similar to the functions
beginning with
\
code
{
r
_}
, but the code will be granted access to
Methods whose names begin with
\
samp
{
s
_}
are similar to the functions
beginning with
\
samp
{
r
_}
, but the code will be granted access to
restricted versions of the standard I/O streams
\code
{
sys.stdin
}
,
\code
{
sys.stderr
}
, and
\code
{
sys.stdout
}
.
\code
{
sys.stderr
}
, and
\code
{
sys.stdout
}
.
\begin{funcdesc}
{
s
_
eval
}{
code
}
\var
{
code
}
must be a string containing a Python expression, which will
...
...
@@ -146,19 +146,19 @@ implicitly called by code executing in the restricted environment.
Overriding these methods in a subclass is used to change the policies
enforced by a restricted environment.
\begin{funcdesc}
{
r
_
import
}{
modulename
\optional
{
\,
globals
\,
locals
\
,
fromlist
}}
Import the module
\var
{
modulename
}
, raising an
\
code
{
ImportError
}
\begin{funcdesc}
{
r
_
import
}{
modulename
\optional
{
, globals, locals
, fromlist
}}
Import the module
\var
{
modulename
}
, raising an
\
exception
{
ImportError
}
exception if the module is considered unsafe.
\end{funcdesc}
\begin{funcdesc}
{
r
_
open
}{
filename
\optional
{
\,
mode
\optional
{
\,
bufsize
}}}
Method called when
\
code
{
open()
}
is called in the restricted
environment. The arguments are identical to those of
\
code
{
open()
}
,
Method called when
\
function
{
open()
}
is called in the restricted
environment. The arguments are identical to those of
\
function
{
open()
}
,
and a file object (or a class instance compatible with file objects)
should be returned.
\class
{
RExec
}
's default behaviour is allow opening
any file for reading, but forbidding any attempt to write a file. See
the example below for an implementation of a less restrictive
\
code
{
r
_
open()
}
.
\
method
{
r
_
open()
}
.
\end{funcdesc}
\begin{funcdesc}
{
r
_
reload
}{
module
}
...
...
@@ -212,7 +212,7 @@ class TmpWriterRExec(rexec.RExec):
Notice that the above code will occasionally forbid a perfectly valid
filename; for example, code in the restricted environment won't be
able to open a file called
\file
{
/tmp/foo/../bar
}
. To fix this, the
\
code
{
r
_
open
}
method would have to simplify the filename to
\
method
{
r
_
open()
}
method would have to simplify the filename to
\file
{
/tmp/bar
}
, which would require splitting apart the filename and
performing various operations on it. In cases where security is at
stake, it may be preferable to write simple code which is sometimes
...
...
Doc/librexec.tex
Dosyayı görüntüle @
a8912306
\section
{
Standard Module
\sectcode
{
rexec
}}
\label
{
module-rexec
}
\stmodindex
{
rexec
}
\setindexsubitem
{
(in module rexec)
}
This module contains the
\class
{
RExec
}
class, which supports
\
code
{
r
_
exec()
}
,
\code
{
r
_
eval()
}
,
\code
{
r
_
execfile()
}
, and
\
code
{
r
_
import()
}
methods, which are restricted versions of the standard
Python functions
\
code
{
exec()
}
,
\code
{
eval()
}
,
\code
{
execfile()
}
, and
the
\
code
{
import
}
statement.
\
method
{
r
_
exec()
}
,
\method
{
r
_
eval()
}
,
\method
{
r
_
execfile()
}
, and
\
method
{
r
_
import()
}
methods, which are restricted versions of the standard
Python functions
\
method
{
exec()
}
,
\method
{
eval()
}
,
\method
{
execfile()
}
, and
the
\
keyword
{
import
}
statement.
Code executed in this restricted environment will
only have access to modules and functions that are deemed safe; you
can subclass
\class
{
RExec
}
to add or remove capabilities as desired.
...
...
@@ -17,11 +17,11 @@ unsafe operations like reading or writing disk files, or using TCP/IP
sockets. However, it does not protect against code using extremely
large amounts of memory or CPU time.
\begin{
funcdesc}
{
RExec
}{
\optional
{
hooks
\optional
{
\
,
verbose
}}}
\begin{
classdesc}
{
RExec
}{
\optional
{
hooks
\optional
{
, verbose
}}}
Returns an instance of the
\class
{
RExec
}
class.
\var
{
hooks
}
is an instance of the
\c
ode
{
RHooks
}
class or a subclass of it.
If it is omitted or
\code
{
None
}
, the default
\c
ode
{
RHooks
}
class is
\var
{
hooks
}
is an instance of the
\c
lass
{
RHooks
}
class or a subclass of it.
If it is omitted or
\code
{
None
}
, the default
\c
lass
{
RHooks
}
class is
instantiated.
Whenever the
\module
{
RExec
}
module searches for a module (even a
built-in one) or reads a module's code, it doesn't actually go out to
...
...
@@ -41,10 +41,10 @@ importing applets from a URL for a directory.
If
\var
{
verbose
}
is true, additional debugging output may be sent to
standard output.
\end{
func
desc}
\end{
class
desc}
The
\class
{
RExec
}
class has the following class attributes, which are
used by the
\
code
{__
init
__
()
}
method. Changing them on an existing
used by the
\
method
{__
init
__
()
}
method. Changing them on an existing
instance won't have any effect; instead, create a subclass of
\class
{
RExec
}
and assign them new values in the class definition.
Instances of the new class will then use those new values. All these
...
...
@@ -75,7 +75,7 @@ class as a starting point.
\end{datadesc}
\begin{datadesc}
{
ok
_
path
}
Contains the directories which will be searched when an
\
code
{
import
}
Contains the directories which will be searched when an
\
keyword
{
import
}
is performed in the restricted environment.
The value for
\class
{
RExec
}
is the same as
\code
{
sys.path
}
(at the time
the module is loaded) for unrestricted code.
...
...
@@ -83,7 +83,7 @@ the module is loaded) for unrestricted code.
\begin{datadesc}
{
ok
_
posix
_
names
}
% Should this be called ok_os_names?
Contains the names of the functions in the
\
cod
e
{
os
}
module which will be
Contains the names of the functions in the
\
modul
e
{
os
}
module which will be
available to programs running in the restricted environment. The
value for
\class
{
RExec
}
is
\code
{
('error',
}
\code
{
'fstat',
}
\code
{
'listdir',
}
\code
{
'lstat',
}
\code
{
'readlink',
}
\code
{
'stat',
}
...
...
@@ -93,7 +93,7 @@ value for \class{RExec} is \code{('error',} \code{'fstat',}
\end{datadesc}
\begin{datadesc}
{
ok
_
sys
_
names
}
Contains the names of the functions and variables in the
\
cod
e
{
sys
}
Contains the names of the functions and variables in the
\
modul
e
{
sys
}
module which will be available to programs running in the restricted
environment. The value for
\class
{
RExec
}
is
\code
{
('ps1',
}
\code
{
'ps2',
}
\code
{
'copyright',
}
\code
{
'version',
}
\code
{
'platform',
}
...
...
@@ -106,25 +106,25 @@ environment. The value for \class{RExec} is \code{('ps1',}
\begin{funcdesc}
{
r
_
eval
}{
code
}
\var
{
code
}
must either be a string containing a Python expression, or
a compiled code object, which will be evaluated in the restricted
environment's
\
cod
e
{__
main
__}
module. The value of the expression or
environment's
\
modul
e
{__
main
__}
module. The value of the expression or
code object will be returned.
\end{funcdesc}
\begin{funcdesc}
{
r
_
exec
}{
code
}
\var
{
code
}
must either be a string containing one or more lines of
Python code, or a compiled code object, which will be executed in the
restricted environment's
\
cod
e
{__
main
__}
module.
restricted environment's
\
modul
e
{__
main
__}
module.
\end{funcdesc}
\begin{funcdesc}
{
r
_
execfile
}{
filename
}
Execute the Python code contained in the file
\var
{
filename
}
in the
restricted environment's
\
cod
e
{__
main
__}
module.
restricted environment's
\
modul
e
{__
main
__}
module.
\end{funcdesc}
Methods whose names begin with
\
code
{
s
_}
are similar to the functions
beginning with
\
code
{
r
_}
, but the code will be granted access to
Methods whose names begin with
\
samp
{
s
_}
are similar to the functions
beginning with
\
samp
{
r
_}
, but the code will be granted access to
restricted versions of the standard I/O streams
\code
{
sys.stdin
}
,
\code
{
sys.stderr
}
, and
\code
{
sys.stdout
}
.
\code
{
sys.stderr
}
, and
\code
{
sys.stdout
}
.
\begin{funcdesc}
{
s
_
eval
}{
code
}
\var
{
code
}
must be a string containing a Python expression, which will
...
...
@@ -146,19 +146,19 @@ implicitly called by code executing in the restricted environment.
Overriding these methods in a subclass is used to change the policies
enforced by a restricted environment.
\begin{funcdesc}
{
r
_
import
}{
modulename
\optional
{
\,
globals
\,
locals
\
,
fromlist
}}
Import the module
\var
{
modulename
}
, raising an
\
code
{
ImportError
}
\begin{funcdesc}
{
r
_
import
}{
modulename
\optional
{
, globals, locals
, fromlist
}}
Import the module
\var
{
modulename
}
, raising an
\
exception
{
ImportError
}
exception if the module is considered unsafe.
\end{funcdesc}
\begin{funcdesc}
{
r
_
open
}{
filename
\optional
{
\,
mode
\optional
{
\,
bufsize
}}}
Method called when
\
code
{
open()
}
is called in the restricted
environment. The arguments are identical to those of
\
code
{
open()
}
,
Method called when
\
function
{
open()
}
is called in the restricted
environment. The arguments are identical to those of
\
function
{
open()
}
,
and a file object (or a class instance compatible with file objects)
should be returned.
\class
{
RExec
}
's default behaviour is allow opening
any file for reading, but forbidding any attempt to write a file. See
the example below for an implementation of a less restrictive
\
code
{
r
_
open()
}
.
\
method
{
r
_
open()
}
.
\end{funcdesc}
\begin{funcdesc}
{
r
_
reload
}{
module
}
...
...
@@ -212,7 +212,7 @@ class TmpWriterRExec(rexec.RExec):
Notice that the above code will occasionally forbid a perfectly valid
filename; for example, code in the restricted environment won't be
able to open a file called
\file
{
/tmp/foo/../bar
}
. To fix this, the
\
code
{
r
_
open
}
method would have to simplify the filename to
\
method
{
r
_
open()
}
method would have to simplify the filename to
\file
{
/tmp/bar
}
, which would require splitting apart the filename and
performing various operations on it. In cases where security is at
stake, it may be preferable to write simple code which is sometimes
...
...
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