Files
intellecton/venv/lib/python3.12/site-packages/jinja2/__pycache__/sandbox.cpython-312.pyc
T

159 lines
18 KiB
Plaintext
Raw Normal View History

Ë
j¡:ãópUdZddlZddlZddlZddlmZddlmZddlm Z ddl
m Z ddl m
Z
ddlmZdd lmZd
d lmZd
d lmZd
d
lmZd
dlmZej0dej2dej4f¬«ZdZe«Zej>e e!d<e«Z"ej>e e!d<ddhZ#ddhZ$ddhZ%ejLe'gd¢«fejPe'gd¢«fejRe'gd¢«fe e'gd¢«ffZ*ejVejVejXej4ejZe fdfe!d<d e.d!e/fd"„Z0d#ed!efd$„Z1d%ej4d&e d!e2fd'„Z3d%ej4d&e d!e2fd(„Z4Gd)„d*e«Z5Gd+„d,e5«Z6Gd-„d.e
«Z7Gd/„d0e7e«Z8y)1z„A 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)rrÚpopitemÚ
setdefaultr )ÚappendrrÚreverseÚinsertÚsortÚextendr) r#Ú
appendleftrr'Ú
extendleftrÚpopleftrÚrotateÚ
_mutable_specÚargsÚreturncó`t|Ž}t|«tkDrtdtd«|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 úQ/home/antigravity/intellecton/venv/lib/python3.12/site-packages/jinja2/sandbox.pyÚ
safe_ranger6Ws>ô ˆ,€Cä
ˆ3ƒx”)ÒÜð
Ü$˜+ 

ð
ð
€JóÚfcód|_|S)zMarks a function or method as unsafe.
.. code-block: python
@unsafe
def delete(self):
pass
T)Úunsafe_callable)r8s r5Úunsafer;fsð€AÔØ €Hr7ÚobjÚattrcótt|tj«r
|tvryt|tj«r|tvs|t
vrÚyt|t «r|dk(rÄyt|tjtjtjf«ryt|tj«r |tvrgyttd«r#t|tj«r |tvr4yttd«r#t|tj«r |t vry|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
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_attributerQsô#”u× Ô Ü ×)Ô *Ø Ô Ô9QÑ1QØÜ Ô Ø 5Š=ØÜ Cœ%Ÿ.™.¬%×*=Ñ*=¼u¿¹ÐOÔ PØÜ ×,Ô -Ø Ô Ü ˜Ô (¬Z¸¼U×=PÑ=PÔ-QØ Ô Ü Ð,Ô -´*Ø ŒU×
3ð Ô Ø ?‰?˜4Ó Ð r7cóDtD]\}}t||«sŒ||vcSy)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ô&ˆ c˜ ˜6  r7c
ó\eZdZUdZdZej ejejejejejejdœZ
ejeej"ej$ej$gej$ffed<ej(ej*dœZejeej"ej$gej$ffed<e«Zej2eed<e«Zej2eed<d ej$d
ej$d d fˆfd
Zdej$dedej$d efdZdej$d efdZdededej$dej$d ej$f
dZ dededej$d ej$fdZ!dej$dejDeej$fd ejDej$e#ffdZ$dej$ded ejDej$e#ffdZ%dej$ded e#fdZ&dej$d ejNej"deffd „Z(d!ed"ej$d ej$d
ej$d ej$f
d#„Z)ˆxZ*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)rWrXÚdefault_unop_tableÚintercepted_binopsÚintercepted_unopsr-Úkwargsr.NcóÆt||i|¤Žt|jd<|jj «|_|jj «|_y)Nr0) ÚsuperÚ__init__r6Úglobalsr\ÚcopyÚ binop_tabler]Ú
unop_table)Úselfr-r`Ú __class__s €r5rczSandboxedEnvironment.__init__òsPø€Ü
ј) )Ü *ˆ Ø×ÔØ×8ˆr7r<r=ÚvaluecóB|jd«xs t||« S)aYThe 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.
Ú_)rPrQ)rhr<r=rjs r5Úis_safe_attributez&SandboxedEnvironment.is_safe_attributeøs#ð—OO LÔ,AÀ#ÀtÓ,LÐMr7có<t|dd«xs
t|dd« S)zêCheck 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: alters_data)Úgetattr)rhr<s r5Úis_safe_callablez%SandboxedEnvironment.is_safe_callables*ô
*¨EÓ X´g¸cÀ=ÐRWÓ6Xð
ð
r7ÚcontextÚoperatorÚleftÚrightcó.|j|||«S)z÷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
)rf)rhrrrsrtrus r5Ú
call_binopzSandboxedEnvironment.call_binop sð*ˆÑ Ñ)¨$°Ó6r7Úargcó,|j||«S)zõ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
)rg)rhrrrsrxs r5Ú call_unopzSandboxedEnvironment.call_unopsð)ˆt˜xÑÓ-r7Úargumentcóp ||S#ttf$t|t«ry t|«} t ||«}|j |«}||cYS|j
|||«r|cYS|j||«cYS#t$rYnwxYw#t$rYnwxYwYnwxYw|j||¬«S)z(Subscribe an object from sandboxed code.©r<Úname) Ú TypeErrorÚ LookupErrorrCÚstrrpÚwrap_str_formatrmÚunsafe_undefinedÚAttributeErrorÚ ExceptionÚ undefined)rhr<r{r=rjÚfmts r5ÚgetitemzSandboxedEnvironment.getitem ð DØx‘=Ð øÜœ;Ð Dܘ(¤CÔDܘx›=
DÜ '¨¨TÓ 2˜ð#×2°5Ó9˜Ø˜?Ø#&šJØ×1°#°xÀÔGØ#(šLØ4°S¸(ÓCøôÙðûô Ùðüð  Dúð$~‰~ #¨Hˆ5sZB"§ 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  ||cYS#t
t f$rYnwxYwYnwxYw|j||¬«S)z€Subscribe an object from sandboxed code and prefer the
attribute. The attribute passed *must* be a bytestring.
r})rprrmr„rr€r†)rhr<r‰rjr‡s r5rpzSandboxedEnvironment.getattr:ð
˜C Ó+ˆ×& -ˆˆØ
Ø×% c¨9°eÔ Ø×¨iÓ 8øôò ð
ؘ9‘~Ò%øÜœ{Ð
Ùð
úÙð  úð~‰~ #¨Iˆ6s5 A
Á
A3ÁAÁA3ÁA-Á*A3Á,A-Á-A3Á2A3cóh|jd|dt|«jd||t¬«S)z1Return an undefined object for unsafe attributes.zaccess to attribute z of z object is unsafe.)r~r<Úexc)r†rGÚ__name__r )rhr<r‰s r5z%SandboxedEnvironment.unsafe_undefinedNsEà~‰~Ø" 9 0ÜS“ ×%Ð%7ð
ØÜð ó
ð
r7.cóÞt|tjtjf«r|jdvry|j
Štt «syt«Š|jdk(Štt«rt|j¬«}n t|«}|jŠdtjdtjdt fˆˆˆˆfd }t||«S) aIf 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 td«t|«dk7rtdt|«d«|d}d}||««S)Nz'format_map() takes no keyword argumentsr
z)format_map() takes exactly one argument (z given)r©)rr1)r-r`Úf_selfÚ
is_format_mapÚstr_typeÚvformats €€€€r5Úwrapperz5SandboxedEnvironment.wrap_str_format.<locals>.wrapperssaø€ÙÙÜ#Ð$MÓt“9 CÄCÈÃIÀ;ÈgÐðð˜a™Øá™G F¨D°&Ó :r7)rCrDrFÚBuiltinMethodTyperÚ__self__rrGr ÚSandboxedEscapeFormatterrÚSandboxedFormatterr—ÚAnyr)rhrjÚ formatterr˜r”r•rr—s @@@@r5rz$SandboxedEnvironment.wrap_str_formatXû€ô Ø ”E×$¤e×&=Ñ&=Ð
à
^‰^Ð#;Ñ
àŸˆä˜&¤#Ôä $  ˆØŸ¨,Ñ
ô fœfÔ ¸f¿m¹mÔL‰Iä*¨4Ó0ˆIà×ð
;œ1Ÿ5™5ð
;¬A¯E©Eð
;´
˜g -r7Ú_SandboxedEnvironment__contextÚ_SandboxedEnvironment__objcól|j|«st|d«|j|g|¢­i|¤ŽS)z#Call an object from sandboxed code.z is not safely callable)rqr Úcall)Ú_SandboxedEnvironment__selfr r-r`s r5zSandboxedEnvironment.call„s@ð×&  5 )Ð+BÐ CÓ ˆy~‰~˜5 5¨fÑ5r7)+rÚ
__module__Ú __qualname__Ú__doc__Ú sandboxedrsrÚsubÚmulÚtruedivÚfloordivÚpowÚmodr\rÚDictrÚCallableržÚ__annotations__ÚposÚnegr]Ú frozensetr^Ú FrozenSetr_rcÚboolrmrqr
rwrzÚUnionrrˆrpÚOptionalrÚ
__classcell__©ris@r5rVrV±ø…ñð€Ið \‰\Ø
\‰\Ø
\‰\Ø
×
Ñ
Ø×ÑØl‰lØ
\‰\ñKИŸ  Q§Z¡Z°·±¸¿¹°ÀÇÁÐ0EÑ%FÐ FÑð\‰\Ø