OpenQuizz
Une application de gestion des contenus pédagogiques
SandboxedEnvironment Class Reference
Inheritance diagram for SandboxedEnvironment:
Collaboration diagram for SandboxedEnvironment:

Public Member Functions

def intercept_unop (self, operator)
 
def __init__ (self, *args, **kwargs)
 
def is_safe_attribute (self, obj, attr, value)
 
def is_safe_callable (self, obj)
 
def call_binop (self, context, operator, left, right)
 
def call_unop (self, context, operator, arg)
 
def getitem (self, obj, argument)
 
def getattr (self, obj, attribute)
 
def unsafe_undefined (self, obj, attribute)
 
def format_string (self, s, args, kwargs, format_func=None)
 
def call (__self, __context, __obj, *args, **kwargs)
 
- Public Member Functions inherited from Environment
def __init__ (self, block_start_string=BLOCK_START_STRING, block_end_string=BLOCK_END_STRING, variable_start_string=VARIABLE_START_STRING, variable_end_string=VARIABLE_END_STRING, comment_start_string=COMMENT_START_STRING, comment_end_string=COMMENT_END_STRING, line_statement_prefix=LINE_STATEMENT_PREFIX, line_comment_prefix=LINE_COMMENT_PREFIX, trim_blocks=TRIM_BLOCKS, lstrip_blocks=LSTRIP_BLOCKS, newline_sequence=NEWLINE_SEQUENCE, keep_trailing_newline=KEEP_TRAILING_NEWLINE, extensions=(), optimized=True, undefined=Undefined, finalize=None, autoescape=False, loader=None, cache_size=400, auto_reload=True, bytecode_cache=None, enable_async=False)
 
def add_extension (self, extension)
 
def extend (self, **attributes)
 
def overlay (self, block_start_string=missing, block_end_string=missing, variable_start_string=missing, variable_end_string=missing, comment_start_string=missing, comment_end_string=missing, line_statement_prefix=missing, line_comment_prefix=missing, trim_blocks=missing, lstrip_blocks=missing, extensions=missing, optimized=missing, undefined=missing, finalize=missing, autoescape=missing, loader=missing, cache_size=missing, auto_reload=missing, bytecode_cache=missing)
 
def iter_extensions (self)
 
def call_filter (self, name, value, args=None, kwargs=None, context=None, eval_ctx=None)
 
def call_test (self, name, value, args=None, kwargs=None)
 
def parse (self, source, name=None, filename=None)
 
def lex (self, source, name=None, filename=None)
 
def preprocess (self, source, name=None, filename=None)
 
def compile (self, source, name=None, filename=None, raw=False, defer_init=False)
 
def compile_expression (self, source, undefined_to_none=True)
 
def compile_templates (self, target, extensions=None, filter_func=None, zip="deflated", log_function=None, ignore_errors=True, py_compile=False)
 
def list_templates (self, extensions=None, filter_func=None)
 
def handle_exception (self, source=None)
 
def join_path (self, template, parent)
 
def get_template (self, name, parent=None, globals=None)
 
def select_template (self, names, parent=None, globals=None)
 
def get_or_select_template (self, template_name_or_list, parent=None, globals=None)
 
def from_string (self, source, globals=None, template_class=None)
 
def make_globals (self, d)
 

Data Fields

 binop_table
 
 unop_table
 
- Data Fields inherited from Environment
 block_start_string
 
 block_end_string
 
 variable_start_string
 
 variable_end_string
 
 comment_start_string
 
 comment_end_string
 
 line_statement_prefix
 
 line_comment_prefix
 
 trim_blocks
 
 lstrip_blocks
 
 newline_sequence
 
 keep_trailing_newline
 
 undefined
 
 optimized
 
 finalize
 
 autoescape
 
 filters
 
 tests
 
 globals
 
 loader
 
 cache
 
 bytecode_cache
 
 auto_reload
 
 policies
 
 extensions
 
 enable_async
 
 is_async
 

Static Public Attributes

 sandboxed
 
 default_binop_table
 
 default_unop_table
 
 intercepted_binops
 
 intercepted_unops
 
- Static Public Attributes inherited from Environment
 sandboxed
 
 overlayed
 
 linked_to
 
 shared
 
 code_generator_class
 
 context_class
 

Additional Inherited Members

- Properties inherited from Environment
 lexer = property(get_lexer, doc="The lexer for this environment.")
 

Detailed Description

The sandboxed environment.  It works like the regular environment but
tells the compiler to generate sandboxed code.  Additionally subclasses of
this environment may override the methods that tell the runtime what
attributes or functions are safe to access.

If the template tries to access insecure code a :exc:`SecurityError` is
raised.  However also other exceptions may occur during the rendering so
the caller has to ensure that all exceptions are caught.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
args,
**  kwargs 
)

Member Function Documentation

◆ call()

def call (   __self,
  __context,
  __obj,
args,
**  kwargs 
)
Call an object from sandboxed code.

◆ call_binop()

def call_binop (   self,
  context,
  operator,
  left,
  right 
)
For intercepted binary operator calls (:meth:`intercepted_binops`)
this function is executed instead of the builtin operator.  This can
be used to fine tune the behavior of certain operators.

.. versionadded:: 2.6

◆ call_unop()

def call_unop (   self,
  context,
  operator,
  arg 
)
For intercepted unary operator calls (:meth:`intercepted_unops`)
this function is executed instead of the builtin operator.  This can
be used to fine tune the behavior of certain operators.

.. versionadded:: 2.6

◆ format_string()

def format_string (   self,
  s,
  args,
  kwargs,
  format_func = None 
)
If a format call is detected, then this is routed through this
method so that our safety sandbox can be used for it.

◆ getattr()

def getattr (   self,
  obj,
  attribute 
)
Subscribe an object from sandboxed code and prefer the
attribute.  The attribute passed *must* be a bytestring.

Reimplemented from Environment.

◆ getitem()

def getitem (   self,
  obj,
  argument 
)
Subscribe an object from sandboxed code.

Reimplemented from Environment.

◆ intercept_unop()

def intercept_unop (   self,
  operator 
)
Called during template compilation with the name of a unary
operator to check if it should be intercepted at runtime.  If this
method returns `True`, :meth:`call_unop` is executed for this unary
operator.  The default implementation of :meth:`call_unop` will use
the :attr:`unop_table` dictionary to perform the operator with the
same logic as the builtin one.

The following unary operators are interceptable: ``+`` and ``-``

Intercepted calls are always slower than the native operator call,
so make sure only to intercept the ones you are interested in.

.. versionadded:: 2.6

◆ is_safe_attribute()

def is_safe_attribute (   self,
  obj,
  attr,
  value 
)
The sandboxed environment will call this method to check if the
attribute of an object is safe to access.  Per default all attributes
starting with an underscore are considered private as well as the
special attributes of internal python objects as returned by the
:func:`is_internal_attribute` function.

Reimplemented in ImmutableSandboxedEnvironment.

◆ is_safe_callable()

def is_safe_callable (   self,
  obj 
)
Check if an object is safely callable.  Per default a function is
considered safe unless the `unsafe_callable` attribute exists and is
True.  Override this method to alter the behavior, but this won't
affect the `unsafe` decorator from this module.

◆ unsafe_undefined()

def unsafe_undefined (   self,
  obj,
  attribute 
)
Return an undefined object for unsafe attributes.

Field Documentation

◆ binop_table

binop_table

◆ default_binop_table

default_binop_table
static

◆ default_unop_table

default_unop_table
static

◆ intercepted_binops

intercepted_binops
static

◆ intercepted_unops

intercepted_unops
static

◆ sandboxed

sandboxed
static

◆ unop_table

unop_table

The documentation for this class was generated from the following file: