
    ,h:                     p   U d Z ddlZddlZddlZddlmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZ ddlmZ dd	lmZ d
dlmZ d
dlmZ d
dlmZ d
dlmZ  ej0                  dej2                  dej4                  f         ZdZ e       Zej>                  e    e!d<    e       Z"ej>                  e    e!d<   ddhZ#ddhZ$ddhZ%ejL                   e'g d      fejP                   e'g d      fejR                   e'g d      fe	 e'g d      ffZ*ejV                  ejV                  ejX                  ej4                     ejZ                  e    f   df   e!d<   d e.d!e/fd"Z0d#ed!efd$Z1d%ej4                  d&e d!e2fd'Z3d%ej4                  d&e d!e2fd(Z4 G d) d*e      Z5 G d+ d,e5      Z6 G d- d.e      Z7 G d/ d0e7e      Z8y)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                  `    t        |  }t        |      t        kD  rt        dt         d      |S )zWA 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     P/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/jinja2/sandbox.py
safe_ranger6   W   s>     ,C
3x)$+R)
 	

 J    fc                     d| _         | S )zMarks 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                 t   t        | t        j                        r
|t        v ryt        | t        j                        r|t        v s|t
        v ryt        | t              r|dk(  ryt        | t        j                  t        j                  t        j                  f      ryt        | t        j                        r	|t        v rgyt        t        d      r#t        | t        j                        r	|t        v r4yt        t        d      r#t        | t        j                        r	|t         v ry|j#                  d      S )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	C	5=	C%..%*=*=uO	P	C,,	-..		(ZU=P=P-Q..	,	-*U%%3 44??4  r7   c                 D    t         D ]  \  }}t        | |      s||v c S  y)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      s1    & * "&c8$6>!" r7   c            
       \    e Zd ZU dZdZej                  ej                  ej                  ej                  ej                  ej                  ej                  dZej                  eej"                  ej$                  ej$                  gej$                  f   f   ed<   ej(                  ej*                  dZej                  eej"                  ej$                  gej$                  f   f   ed<    e       Zej2                  e   ed<    e       Zej2                  e   ed<   d	ej$                  d
ej$                  ddf fdZdej$                  dedej$                  defdZdej$                  defdZdededej$                  dej$                  dej$                  f
dZ dededej$                  dej$                  fdZ!dej$                  dejD                  eej$                  f   dejD                  ej$                  e#f   fdZ$dej$                  dedejD                  ej$                  e#f   fdZ%dej$                  dede#fdZ&dej$                  dejN                  ej"                  def      fd Z(d!ed"ej$                  d	ej$                  d
ej$                  dej$                  f
d#Z) xZ*S )$SandboxedEnvironmenta  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)rW   rX   default_unop_tableintercepted_binopsintercepted_unopsr-   kwargsr.   Nc                     t        |   |i | t        | j                  d<   | j                  j                         | _        | j                  j                         | _        y )Nr0   )	super__init__r6   globalsr\   copybinop_tabler]   
unop_table)selfr-   r`   	__class__s      r5   rc   zSandboxedEnvironment.__init__   sP    $)&) *W3388:11668r7   r<   r=   valuec                 B    |j                  d      xs t        ||       S )aY  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   )rh   r<   r=   rj   s       r5   is_safe_attributez&SandboxedEnvironment.is_safe_attribute   s#     OOC(L,A#t,LMMr7   c                 <    t        |dd      xs t        |dd       S )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)rh   r<   s     r5   is_safe_callablez%SandboxedEnvironment.is_safe_callable  s*     C*E2Xgc=RW6X
 	
r7   contextoperatorleftrightc                 .     | j                   |   ||      S )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
        )rf   )rh   rr   rs   rt   ru   s        r5   
call_binopzSandboxedEnvironment.call_binop  s     *t)$66r7   argc                 ,     | j                   |   |      S )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
        )rg   )rh   rr   rs   rx   s       r5   	call_unopzSandboxedEnvironment.call_unop  s     )tx(--r7   argumentc                 p   	 ||   S # t         t        f$ r t        |t              ry	 t        |      }	 t	        ||      }| j                  |      }||cY S | j                  |||      r|cY S | j                  ||      cY S # t        $ r Y nw xY w# t        $ r Y nw xY wY nw xY w| j                  ||      S )z(Subscribe an object from sandboxed code.r<   name)	TypeErrorLookupErrorrC   strrp   wrap_str_formatrm   unsafe_undefinedAttributeError	Exception	undefined)rh   r<   r{   r=   rj   fmts         r5   getitemzSandboxedEnvironment.getitem   s    	Dx= ;' 	D(C(Dx=D
D 'T 2 #2259?#&J11#xG#(L#44S(CC *  ! 		D$ ~~#H~55sZ    B"BBB"B"-B"	B
B"BB"	BB"BB"!B"	attributec                    	 t        ||      }| j                  |      }||S | j                  |||      r|S | j                  ||      S # t        $ r  	 ||   cY S # t
        t        f$ r Y nw xY wY nw xY w| j                  ||      S )zSubscribe an object from sandboxed code and prefer the
        attribute.  The attribute passed *must* be a bytestring.
        r}   )rp   r   rm   r   r   r   r   r   )rh   r<   r   rj   r   s        r5   rp   zSandboxedEnvironment.getattr:  s    	9C+E &&u-C
%%c9e<((i88  	9~%{+ 		 ~~#I~66s5   A
 
	A3AA3A-*A3,A--A32A3c                 h    | j                  d|dt        |      j                  d||t              S )z1Return an undefined object for unsafe attributes.zaccess to attribute z of z object is unsafe.)r~   r<   exc)r   rG   __name__r   )rh   r<   r   s      r5   r   z%SandboxedEnvironment.unsafe_undefinedN  sE    ~~"9- 0S	""%%79  
 	
r7   .c                    t        |t        j                  t        j                  f      r|j                  dvry|j
                  t        t              syt              |j                  dk(  t        t              rt        | j                        }nt        |       }|j                  dt        j                  dt        j                  dt        ffd}t        ||      S )	a   If 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-   r`   r.   c                      r:|rt        d      t        |       dk7  rt        dt        |        d      | d   }d}   | |            S )Nz'format_map() takes no keyword argumentsr
   z)format_map() takes exactly one argument (z given)r    )r   r1   )r-   r`   f_selfis_format_mapstr_typevformats     r5   wrapperz5SandboxedEnvironment.wrap_str_format.<locals>.wrappers  sa    #$MNNt9>#CCI;gV  aGFD&9::r7   )rC   rD   rF   BuiltinMethodTyper   __self__r   rG   r	   SandboxedEscapeFormatterr   SandboxedFormatterr   tAnyr   )rh   rj   	formatterr   r   r   r   r   s       @@@@r5   r   z$SandboxedEnvironment.wrap_str_formatX  s     E$$e&=&=>
^^#;;&#& $V,6 ff%0fmmLI*40I##	;155 	;AEE 	;c 	; 	; gu--r7   _SandboxedEnvironment__context_SandboxedEnvironment__objc                 l    | j                  |      st        |d       |j                  |g|i |S )z#Call an object from sandboxed code.z is not safely callable)rq   r   call)_SandboxedEnvironment__selfr   r   r-   r`   s        r5   r   zSandboxedEnvironment.call  s@     &&u-5)+B CDDy~~e5d5f55r7   )+r   
__module____qualname____doc__	sandboxedrs   r   submultruedivfloordivpowmodr\   r   Dictr   Callabler   __annotations__posnegr]   	frozensetr^   	FrozenSetr_   rc   boolrm   rq   r   rw   rz   Unionr   r   rp   r   Optionalr   r   __classcell__ri   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 
6r7   rV   c                   \     e Zd ZdZdej
                  dedej
                  def fdZ xZ	S )ImmutableSandboxedEnvironmentzWorks 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=   rj   r.   c                 B    t         |   |||      syt        ||       S )NF)rb   rm   rT   )rh   r<   r=   rj   ri   s       r5   rm   z/ImmutableSandboxedEnvironment.is_safe_attribute  s'    w(dE:)#t444r7   )
r   r   r   r   r   r   r   r   rm   r   r   s   @r5   r   r     s6    
5QUU 5# 5aee 5 5 5r7   r   c            
            e Zd Zdedej
                  ddf fdZdedej                  ej
                     dej                  eej
                  f   dej                  ej
                  ef   fdZ xZS )	r   envr`   r.   Nc                 2    || _         t        |   di | y )Nr   )_envrb   rc   )rh   r   r`   ri   s      r5   rc   zSandboxedFormatter.__init__  s    	"6"r7   
field_namer-   c                     t        |      \  }}| j                  |||      }|D ]@  \  }}|r| j                  j                  ||      }%| j                  j	                  ||      }B ||fS )N)r   	get_valuer   rp   r   )	rh   r   r-   r`   firstrestr<   is_attris	            r5   	get_fieldzSandboxedFormatter.get_field  sr     1<tnnUD&1 	0JGQii''Q/ii''Q/		0
 Ezr7   )r   r   r   r   r   r   rc   r   SequenceMappingTupler   r   r   s   @r5   r   r     su    #K #155 #T #

%&ZZ%6
@A		#quu*@U
	
	
r7   r   c                       e Zd Zy)r   N)r   r   r   r   r7   r5   r   r     s    r7   r   )9r   rs   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      .   $  &  $ %  AIIc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   