
    h:                     r   % S r SSKrSSKrSSKrSSKJr  SSKJr  SSKJ	r	  SSK
Jr  SSKJr  SSKJr  SS	KJr  S
SKJr  S
SKJr  S
SKJr  S
SKJr  \R0                  " S\R2                  S\R4                  4   S9rSr\" 5       r\R>                  \    \!S'   \" 5       r"\R>                  \    \!S'   SS1r#SS1r$SS1r%\RL                  \'" / SQ5      4\RP                  \'" / SQ5      4\RR                  \'" / SQ5      4\	\'" / SQ5      44r*\RV                  \RV                  \RX                  \R4                     \RZ                  \    4   S4   \!S'   S \.S!\/4S" jr0S#\S!\4S$ jr1S%\R4                  S&\ S!\24S' jr3S%\R4                  S&\ S!\24S( jr4 " S) S*\5      r5 " S+ S,\55      r6 " S- S.\5      r7 " S/ S0\7\5      r8g)1zA sandbox layer that ensures unsafe operations cannot be performed.
Useful when the template itself comes from an untrusted source.
    N)formatter_field_name_split)abc)deque)update_wrapper)	Formatter)EscapeFormatter)Markup   )Environment)SecurityError)Context)	UndefinedF.)boundi UNSAFE_FUNCTION_ATTRIBUTESUNSAFE_METHOD_ATTRIBUTESgi_framegi_codecr_framecr_codeag_codeag_frame)addcleardifference_updatediscardpopremovesymmetric_difference_updateupdate)r   r   popitem
setdefaultr    )appendr   r   reverseinsertsortextendr   )	r#   
appendleftr   r'   
extendleftr   popleftr   rotate_mutable_specargsreturnc                  b    [        U 6 n[        U5      [        :  a  [        S[         S35      eU$ )zOA range that can't generate ranges with a length of more than
MAX_RANGE items.
z@Range too big. The sandbox blocks ranges larger than MAX_RANGE (z).)rangelen	MAX_RANGEOverflowError)r-   rngs     F/var/www/auris/envauris/lib/python3.13/site-packages/jinja2/sandbox.py
safe_ranger6   W   s>     ,C
3x)$+R)
 	

 J    fc                     SU l         U $ )zmMarks a function or method as unsafe.

.. code-block: python

    @unsafe
    def delete(self):
        pass
T)unsafe_callable)r8   s    r5   unsafer;   f   s     AHr7   objattrc                    [        U [        R                  5      (       a  U[        ;   a  gGO<[        U [        R                  5      (       a  U[        ;   d
  U[
        ;   a  gGO[        U [        5      (       a  US:X  a  gO[        U [        R                  [        R                  [        R                  45      (       a  g[        U [        R                  5      (       a  U[        ;   a  gO[        [        S5      (       a+  [        U [        R                  5      (       a  U[        ;   a  gO?[        [        S5      (       a*  [        U [        R                  5      (       a  U[         ;   a  gUR#                  S5      $ )a  Test if the attribute given is an internal python attribute.  For
example this function returns `True` for the `func_code` attribute of
python objects.  This is useful if the environment method
:meth:`~SandboxedEnvironment.is_safe_attribute` is overridden.

>>> from jinja2.sandbox import is_internal_attribute
>>> is_internal_attribute(str, "mro")
True
>>> is_internal_attribute(str, "upper")
False
TmroCoroutineTypeAsyncGeneratorType__)
isinstancetypesFunctionTyper   
MethodTyper   typeCodeTypeTracebackType	FrameTypeGeneratorTypeUNSAFE_GENERATOR_ATTRIBUTEShasattrr@   UNSAFE_COROUTINE_ATTRIBUTESrA   !UNSAFE_ASYNC_GENERATOR_ATTRIBUTES
startswith)r<   r=   s     r5   is_internal_attributerQ   s   s,    #u))**-- .	C))	*	*--9Q1Q 2R	C		5= 	C%..%*=*=uO	P	P	C,,	-	-.. /		(	(ZU=P=P-Q-Q.. /	,	-	-*U%%3 3 44??4  r7   c                 N    [          H  u  p#[        X5      (       d  M  X;   s  $    g)a  This function checks if an attribute on a builtin mutable object
(list, dict, set or deque) or the corresponding ABCs would modify it
if called.

>>> modifies_known_mutable({}, "clear")
True
>>> modifies_known_mutable({}, "keys")
False
>>> modifies_known_mutable([], "append")
True
>>> modifies_known_mutable([], "index")
False

If called with an unsupported object, ``False`` is returned.

>>> modifies_known_mutable("foo", "upper")
False
F)r,   rC   )r<   r=   typespecr;   s       r5   modifies_known_mutablerT      s)    & *c$$>! * r7   c            
       z  ^  \ rS rSr% SrSr\R                  \R                  \R                  \R                  \R                  \R                  \R                  S.r\R                   \\R$                  \R&                  \R&                  /\R&                  4   4   \S'   \R*                  \R,                  S.r\R                   \\R$                  \R&                  /\R&                  4   4   \S'   \" 5       r\R4                  \   \S'   \" 5       r\R4                  \   \S	'   S
\R&                  S\R&                  SS4U 4S jjrS\R&                  S\S\R&                  S\4S jrS\R&                  S\4S jrS\ S\S\R&                  S\R&                  S\R&                  4
S jr!S\ S\S\R&                  S\R&                  4S jr"S\R&                  S\RF                  \\R&                  4   S\RF                  \R&                  \$4   4S jr%S\R&                  S\S\RF                  \R&                  \$4   4S jr&S\R&                  S\S\$4S jr'S\R&                  S\RP                  \R$                  S \4      4S! jr)S"\ S#\R&                  S
\R&                  S\R&                  S\R&                  4
S$ jr*S%r+U =r,$ )&SandboxedEnvironment   a  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.
T)+-*/z//z**%default_binop_table)rX   rY   default_unop_tableintercepted_binopsintercepted_unopsr-   kwargsr.   Nc                    > [         TU ]  " U0 UD6  [        U R                  S'   U R                  R                  5       U l        U R                  R                  5       U l        g )Nr0   )	super__init__r6   globalsr]   copybinop_tabler^   
unop_table)selfr-   ra   	__class__s      r5   rd   SandboxedEnvironment.__init__   sP    $)&) *W3388:11668r7   r<   r=   valuec                 R    UR                  S5      =(       d    [        X5      (       + $ )a1  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.
_)rP   rQ   )ri   r<   r=   rl   s       r5   is_safe_attribute&SandboxedEnvironment.is_safe_attribute   s!     OOC(L,A#,LMMr7   c                 N    [        USS5      =(       d    [        USS5      (       + $ )zCheck if an object is safely callable. By default callables
are considered safe unless decorated with :func:`unsafe`.

This also recognizes the Django convention of setting
``func.alters_data = True``.
r:   Falters_data)getattr)ri   r<   s     r5   is_safe_callable%SandboxedEnvironment.is_safe_callable  s*     C*E2Xgc=RW6X
 	
r7   contextoperatorleftrightc                 ,    U R                   U   " X45      $ )zFor 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
)rg   )ri   rv   rw   rx   ry   s        r5   
call_binopSandboxedEnvironment.call_binop  s     )$66r7   argc                 ,    U R                   U   " U5      $ )zFor 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
)rh   )ri   rv   rw   r}   s       r5   	call_unopSandboxedEnvironment.call_unop  s     x(--r7   argumentc                     X   $ ! [         [        4 a    [        U[        5      (       a   [        U5      n [	        X5      nU R                  U5      nUb  Us $ U R                  XU5      (       a  Us $ U R                  X5      s $ ! [         a      Of = f! [         a      O
f = f Of = fU R                  XS9$ )z(Subscribe an object from sandboxed code.r<   name)	TypeErrorLookupErrorrC   strrs   wrap_str_formatro   unsafe_undefinedAttributeError	Exception	undefined)ri   r<   r   r=   rl   fmts         r5   getitemSandboxedEnvironment.getitem   s    	D= ;' 	D(C((Dx=D
D ' 2 #2259?#&J11#GG#(L#44SCC *  !  )	D$ ~~#~55s[    %B.BB	B.B.6B.	
BB.BB.
B($B.'B((B.-B.	attributec                     [        X5      nU R                  U5      nUb  U$ U R                  XU5      (       a  U$ U R                  X5      $ ! [         a     X   s $ ! [
        [        4 a      Of = ff = fU R                  XS9$ )zpSubscribe an object from sandboxed code and prefer the
attribute.  The attribute passed *must* be a bytestring.
r   )rs   r   ro   r   r   r   r   r   )ri   r<   r   rl   r   s        r5   rs   SandboxedEnvironment.getattr:  s    	9C+E &&u-C
%%ce<<((88  	~%{+ 	 ~~#~66s/   A 
A6AA6A2.A61A22A6c                 f    U R                  SU< S[        U5      R                  < S3UU[        S9$ )z1Return an undefined object for unsafe attributes.zaccess to attribute z of z object is unsafe.)r   r<   exc)r   rG   __name__r   )ri   r<   r   s      r5   r   %SandboxedEnvironment.unsafe_undefinedN  sE    ~~"9- 0S	""%%79  
 	
r7   .c                   ^^^^ [        U[        R                  [        R                  45      (       a  UR                  S;  a  gUR
                  m[        T[        5      (       d  g[        T5      mUR                  S:H  m[        T[        5      (       a  [        U TR                  S9nO[        U 5      nUR                  mS[        R                  S[        R                  S[        4UUUU4S jjn[        X15      $ )	zIf the given value is a ``str.format`` or ``str.format_map`` method,
return a new function than handles sandboxing. This is done at access
rather than in :meth:`call`, so that calls made without ``call`` are
also sandboxed.
)format
format_mapNr   )escaper-   ra   r.   c                     > T(       a@  U(       a  [        S5      e[        U 5      S:w  a  [        S[        U 5       S35      eU S   nSn T" T" TX5      5      $ )Nz'format_map() takes no keyword argumentsr
   z)format_map() takes exactly one argument (z given)r    )r   r1   )r-   ra   f_selfis_format_mapstr_typevformats     r5   wrapper5SandboxedEnvironment.wrap_str_format.<locals>.wrappers  s_    #$MNNt9>#CCI;gV  aGFD9::r7   )rC   rD   rF   BuiltinMethodTyper   __self__r   rG   r	   SandboxedEscapeFormatterr   SandboxedFormatterr   tAnyr   )ri   rl   	formatterr   r   r   r   r   s       @@@@r5   r   $SandboxedEnvironment.wrap_str_formatX  s     E$$e&=&=>
 
^^#;;&#&& $V,6 ff%%0fmmLI*40I##	;155 	;AEE 	;c 	; 	; g--r7   _SandboxedEnvironment__context_SandboxedEnvironment__objc                 x    U R                  U5      (       d  [        U< S35      eUR                  " U/UQ70 UD6$ )z#Call an object from sandboxed code.z is not safely callable)rt   r   call)_SandboxedEnvironment__selfr   r   r-   ra   s        r5   r   SandboxedEnvironment.call  sA     &&u--5)+B CDD~~e5d5f55r7   )rg   rh   )-r   
__module____qualname____firstlineno____doc__	sandboxedrw   r   submultruedivfloordivpowmodr]   r   Dictr   Callabler   __annotations__posnegr^   	frozensetr_   	FrozenSetr`   rd   boolro   rt   r   r{   r   Unionr   r   rs   r   Optionalr   r   __static_attributes____classcell__rj   s   @r5   rV   rV      s    I \\\\\\ll\\KQZZ0E%F FG  \\\\CsAJJw~$>>? & ,5;C(6 +4+q{{3'59aee 9quu 9 9NQUU N# Naee N N	
AEE 	
d 	
	7	7*-	756UU	7CD55	7	
	7. .C .aee . .6556$%GGCJ$76	
	!	"647155 7S 7QWWQUUI=M5N 7(
AEE 
c 
i 
*.QUU *.qzz!**S#X:N/O *.X66 uu6 uu	6
 %%6 
6 6r7   rV   c                   h   ^  \ rS rSrSrS\R                  S\S\R                  S\4U 4S jjr	Sr
U =r$ )	ImmutableSandboxedEnvironmenti  zWorks exactly like the regular `SandboxedEnvironment` but does not
permit modifications on the builtin mutable objects `list`, `set`, and
`dict` by using the :func:`modifies_known_mutable` function.
r<   r=   rl   r.   c                 P   > [         TU ]  XU5      (       d  g[        X5      (       + $ )NF)rc   ro   rT   )ri   r<   r=   rl   rj   s       r5   ro   /ImmutableSandboxedEnvironment.is_safe_attribute  s&    w(E::)#444r7   r   )r   r   r   r   r   r   r   r   r   ro   r   r   r   s   @r5   r   r     s6    
5QUU 5# 5aee 5 5 5r7   r   c            
          ^  \ rS rSrS\S\R                  SS4U 4S jjrS\S\R                  \R                     S\R                  \\R                  4   S\R                  \R                  \4   4S	 jrS
rU =r$ )r   i  envra   r.   Nc                 2   > Xl         [        TU ]  " S0 UD6  g )Nr   )_envrc   rd   )ri   r   ra   rj   s      r5   rd   SandboxedFormatter.__init__  s    	"6"r7   
field_namer-   c                     [        U5      u  pEU R                  XBU5      nU HD  u  pxU(       a  U R                  R                  Xh5      nM)  U R                  R	                  Xh5      nMF     Xd4$ )N)r   	get_valuer   rs   r   )	ri   r   r-   ra   firstrestr<   is_attris	            r5   	get_fieldSandboxedFormatter.get_field  sa     1<nnU&1JGii''/ii''/	 
 zr7   )r   )r   r   r   r   r   r   r   rd   r   SequenceMappingTupler   r   r   r   s   @r5   r   r     sz    #K #155 #T #

%&ZZ%6
@A		#quu*@U
	
	
 
r7   r   c                       \ rS rSrSrg)r   i  r   N)r   r   r   r   r   r   r7   r5   r   r     s    r7   r   )9r   rw   rD   typingr   _stringr   collectionsr   r   	functoolsr   stringr   
markupsafer   r	   environmentr   
exceptionsr   runtimer   r   TypeVarr   r   r   r2   setr   Setr   r   r   rL   rN   rO   
MutableSetr   MutableMappingMutableSequencer,   r   Typer   intr0   r6   r;   r   rQ   rT   rV   r   r   r   r   r7   r5   <module>r      s      .   $  &  $ %  IIcCJ/0 	 *- AEE#J . (+u !%%* ,  *95   *95  &/
$; ! 			
  	EF
 	W	
 	
	
5*Iqwwqwwqvvaee}akk#.>>?DE *Zc e 
a 
A 
"!quu "!C "!D "!J S T 2`6; `6F
5$8 
5 $	1? 	r7   