Files
cms-website/.deps_siteforge_v812/bleach/__pycache__/sanitizer.cpython-312.pyc
T

196 lines
18 KiB
Plaintext
Raw Normal View History

Ë
îÅÙjsUã
ó”—ddlmZddlZddlZddlmZddlmZddlm Z ddl
m Z gd¢Z dd gd gd gd
œZ
gZgd ¢Zd j!eedd
«edd«edd««D�cgc]
}e|«‘Œ c}«Zej(dezdzej*«ZdZGd„d«Zd„ZGd„de j4«Zycc}w)é)ÚchainN)Úurlparse)Úunescape)Ú
html5lib_shim)Úalphabetize_attributes) ÚaÚabbrÚacronymÚbÚ
blockquoteÚcodeÚemÚiÚliÚolÚstrongÚulÚhrefÚtitle)rr r
)ÚhttpÚhttpsÚmailtoÚé é é
éé Ú[Ú]Ú?có,—eZdZdZeeeedddfd„Zd„Z y)ÚCleanera¨Cleaner for cleaning HTML fragments of malicious content
This cleaner is a security-focused function whose sole purpose is to remove
malicious content from a string such that it can be displayed as content in
a web page.
To use::
from bleach.sanitizer import Cleaner
cleaner = Cleaner()
for text in all_the_yucky_things:
sanitized = cleaner.clean(text)
.. Note::
This cleaner is not designed to use to transform content to be used in
non-web-page contexts.
.. Warning::
This cleaner is not thread-safe--the html parser has internal state.
Create a separate cleaner per thread!
FTNcóF—||_||_||_||_||_||_|xsg|_tj|j|jdd¬«|_ tjd«|_ tjdddddd¬«|_
y)a Initializes a Cleaner
:arg list tags: allowed list of tags; defaults to
``bleach.sanitizer.ALLOWED_TAGS``
:arg dict attributes: allowed attributes; can be a callable, list or dict;
defaults to ``bleach.sanitizer.ALLOWED_ATTRIBUTES``
:arg list styles: allowed list of css styles; defaults to
``bleach.sanitizer.ALLOWED_STYLES``
:arg list protocols: allowed list of protocols for links; defaults
to ``bleach.sanitizer.ALLOWED_PROTOCOLS``
:arg bool strip: whether or not to strip disallowed elements
:arg bool strip_comments: whether or not to strip HTML comments
:arg list filters: list of html5lib Filter classes to pass streamed content through
.. seealso:: http://html5lib.readthedocs.io/en/latest/movingparts.html#filters
.. Warning::
Using filters changes the output of ``bleach.Cleaner.clean``.
Make sure the way the filters change the output are secure.
F)ÚtagsÚstripÚconsume_entitiesÚnamespaceHTMLElementsÚetreeÚalwaysT)Úquote_attr_valuesÚomit_optional_tagsÚescape_lt_in_attrsÚresolve_entitiesÚsanitizeÚalphabetical_attributesN)r%Ú
attributesÚstylesÚ protocolsr&Ústrip_commentsÚfiltersrÚBleachHTMLParserÚparserÚ
getTreeWalkerÚwalkerÚBleachHTMLSerializerÚ
serializer)Úselfr%r1r2r3r&r4r5s úTC:\Users\30997\AppData\Local\Temp\pip-target-6g32zz5s\lib\python\bleach/sanitizer.pyÚ__init__zCleaner.__init__Ts›€ðLˆŒ Ø$ˆŒØˆŒ Ø"ˆŒØˆŒ
Ø,ˆÔØ’} "ˆŒ ä#×4Ñ4Ø—‘Ø—*‘*Ø"Ø"'ô 
ˆŒ ô $×1Ñ1°'Ó:ˆŒ Ü'×<Ñ<Ø&Ø$Ø#ð#àà$)ô 
ˆ�óc
óæ—t|t«s1dj|jj¬«}t |«‚|sy|j j|«}t|j|«|j|j|j|j|j|jg¬«}|j D] }||¬«}Œ
|j"j%|«S)zÐCleans text and returns sanitized result as unicode
:arg str text: text to be cleaned
:returns: sanitized text as unicode
:raises TypeError: if ``text`` is not a text type
z9argument cannot be of '{name}' type, must be of text type)Únamer)Úsourcer1Ústrip_disallowed_elementsÚstrip_html_commentsÚallowed_elementsÚallowed_css_propertiesÚallowed_protocolsÚallowed_svg_properties)rB)Ú
isinstanceÚstrÚformatÚ __class__Ú__name__Ú TypeErrorr7Ú
parseFragmentÚBleachSanitizerFilterr9r1r&r4r%r2r3r5r;Úrender)r<ÚtextÚmessageÚdomÚfilteredÚ filter_classs r=Úcleanz
Cleaner.clean–sÑ€ô˜$¤Ô$àK×RÑRØŸ™×0Ñ0ðSóð
ô
˜GÓ$Ð $áØà�k‰k×'Ñ'¨Ó-ˆÜ(Ø—;‘;˜sÓ#à—‘Ø&*§j¡jØ $× 3Ñ 3à!ŸY™YØ#'§;¡;Ø"Ÿn™nØ#%ô 
ˆð!ŸLœLˆLÙ#¨8Ô4‰Hð)ð�‰×%Ñ% hÓ/Ð/r?)
rMÚ
__module__Ú __qualname__Ú__doc__Ú ALLOWED_TAGSÚALLOWED_ATTRIBUTESÚALLOWED_STYLESÚALLOWED_PROTOCOLSr>rW©r?r=r#r#7s*„ñð<Ø%ØØ#ØØØó@
óD'0r?r#có�‡—t‰«r‰St‰t«rˆfd„}|St‰t«rˆfd„}|St d«‚)a0Generates attribute filter function for the given attributes value
The attributes value can take one of several shapes. This returns a filter
function appropriate to the attributes value. One nice thing about this is
that there's less if/then shenanigans in the ``allow_token`` method.
có�•—|‰vr‰|}t|«r
||||«S||vryd‰vr‰d}t|«r
||||«S||vSy)NTÚ*F)Úcallable)ÚtagÚattrÚvalueÚattr_valr1s €r=Ú _attr_filterz.attribute_filter_factory.<locals>._attr_filterÍslø€Ø�jÑ Ø% c™?�ܘHÔ%Ù# C¨¨uÓ5Ð5à˜8Ñ#Øà�jÑ Ø% c™?�ܘHÔ%Ù# C¨¨uÓ5Ð5à˜xÐ'Ð'àr?có •—|‰vS©Nr_)rdrerfr1s €r=rhz.attribute_filter_factory.<locals>._attr_filterãsø€Ø˜:Ð%Ð %r?z3attributes needs to be a callable, a list or a dict)rcrIÚdictÚlistÚ
ValueError)r1rhs` r=Úattribute_filter_factoryrnÀsMø€ô�
ÔØÐä�*œdÔ#ô ð$Ðä�*œdÔ#ô &ðÐä
ÐJÓ
KÐKr?có`‡—eZdZdZeddfˆfd„ Zd„Zd„Zd„Zd„Z d „Z
d
„Z d „Z d „Z
d
„ZˆxZS)rPzmhtml5lib Filter that sanitizes text
This filter can be used anywhere html5lib filters can be used.
FTc 󢕗t|«|_||_||_t j
ddt d¬«tt|�&|fi|¤ŽS)aCreates a BleachSanitizerFilter instance
:arg Treewalker source: stream
:arg list tags: allowed list of tags; defaults to
``bleach.sanitizer.ALLOWED_TAGS``
:arg dict attributes: allowed attributes; can be a callable, list or dict;
defaults to ``bleach.sanitizer.ALLOWED_ATTRIBUTES``
:arg list styles: allowed list of css styles; defaults to
``bleach.sanitizer.ALLOWED_STYLES``
:arg list protocols: allowed list of protocols for links; defaults
to ``bleach.sanitizer.ALLOWED_PROTOCOLS``
:arg bool strip_disallowed_elements: whether or not to strip disallowed
elements
:arg bool strip_html_comments: whether or not to strip HTML comments
Úignorez"html5lib's sanitizer is deprecatedzbleach._vendor.html5lib)rSÚcategoryÚmodule)
rnÚ attr_filterrCrDÚwarningsÚfilterwarningsÚDeprecationWarningÚsuperrPr>)r<rBr1rCrDÚkwargsrLs €r=r>zBleachSanitizerFilter.__init__òsXø€ô<4°JÓ?ˆÔØ)BˆÔ&Ø#6ˆÔ ô ×ÑØ Ø8Ü'Ø,õ 
ô Ô*¨DÑ:¸6ÑLÀVÑLÐLr?c#ó‚K—|D]6}|j|«}|sŒt|t«r |D]}|–—ŒŒ3|–—Œ8y­wrj)Úsanitize_tokenrIrl)r<Útoken_iteratorÚtokenÚretÚsubtokens r=Úsanitize_streamz%BleachSanitizerFilter.sanitize_streamsFèø€Û#ˆEØ×%Ñ% eÓ,ˆCáØä˜#œtÔ$Û #�HØ"“Nñ!$ð“ ñ$ùs‚=?c#óPK—g}|D]h}|rF|ddk(r|j|«Œdj|D�cgc]}|d‘Œ c}«ddœ}g}|–—n|ddk(r|j|«Œe|–—Œjdj|D�cgc]}|d‘Œ c}«ddœ}|–—ycc}wcc}w­w)z/Merge consecutive Characters tokens in a streamÚtypeÚ
CharactersrÚdata)r„r‚N)ÚappendÚjoin)r<r|Úcharacters_bufferr}Ú
char_tokenÚ new_tokens r=Úmerge_charactersz&BleachSanitizerFilter.merge_characters*sÚèø€àÐã#ˆE٠ؘ‘= LÒ0Ø%×,Ñ,¨UÔ3Øð
!#§¡ÙBSÓTÑBS°J˜Z¨Ó/ÐBSÑTó!ð!-ñ !�Ið )+Ð%Ø#“Oà�v‘ ,Ò.Ø!×(Ñ(¨Ô/Øà‹Kð+$ð0—G‘GÑBSÓTÑBS°J˜Z¨Ó/ÐBSÑTÓUØ ñ
ˆ ð‹ùò#UùòUùs‚3B&µ B
ÁAB&Â B!Â
B&có|—|j|jtjj |«««Srj)rŠr€rÚFilterÚ__iter__)r<s r=r�zBleachSanitizerFilter.__iter__Ks4€Ø×$Ñ$Ø × Ñ ¤×!5Ñ!5×!>Ñ!>¸tÓ!DÓ Eó
ð
r?cóV—|d}|dvrU|d|jvr|j|«S|jryd|vrt|d«|d<|j |«S|dk(r/|j
s"t
j|dddd œ¬
«|d<|Sy|d k(r|j|«S|S) aÕSanitize a token either by HTML-encoding or dropping.
Unlike sanitizer.Filter, allowed_attributes can be a dict of {'tag':
['attribute', 'pairs'], 'tag': callable}.
Here callable is a function with two arguments of attribute name and
value. It should return true of false.
Also gives the option to strip tags instead of encoding.
:arg dict token: token to sanitize
:returns: token or list of tokens
r‚)ÚStartTagÚEndTagÚEmptyTagrANr„ÚCommentz&quot;z&#x27;)Ú"Ú')Úentitiesrƒ) rEÚ allow_tokenrCrÚdisallowed_tokenrDrÚescapeÚsanitize_characters)r<r}Ú
token_types r=r{z$BleachSanitizerFilter.sanitize_tokenPsЀð ˜6‘]ˆ
Ø Ð;Ñ ;Ø�V‰} × 5Ñ 5Ñ5Ø×'Ñ'¨Ó.Ð.à×/Ò/Øð˜U‘?ô%;¸5À¹=Ó$I�E˜&‘MØ×,Ñ,¨UÓ3Ð3à
˜9Ò
$Ø×+Ò+ä -× 4Ñ 4ؘ&‘M°(ÀÑ,Jô!��f‘
ð� àà
˜<Ò
'Ø×+Ñ+¨EÓ2Ð 2ðˆLr?cóÞ—|jdd«}|s|Stjt|«}||d<d|vr|Sg}t j
|«D]—}|sŒ|j
d«rmt j|«}|�V|dk(r|jdddœ«n|jd|d œ«|t|«d
zd}|r|jd|dœ«Œ„|jd|dœ«Œ™|S) a½Handles Characters tokens
Our overridden tokenizer doesn't do anything with entities. However,
that means that the serializer will convert all ``&`` in Characters
tokens to ``&amp;``.
Since we don't want that, we extract entities here and convert them to
Entity tokens so the serializer will let them be.
:arg token: the Characters token to work on
:returns: a list of tokens
r„rÚ&NÚamprƒ)r‚r„ÚEntity)r‚rAé)
ÚgetÚINVISIBLE_CHARACTERS_REÚsubÚINVISIBLE_REPLACEMENT_CHARrÚnext_possible_entityÚ
startswithÚ match_entityr…Úlen)r<r}r„Ú
new_tokensÚpartÚentityÚ remainders r=r™z)BleachSanitizerFilter.sanitize_characterss€ð�y‰y˜ Ó$ˆá؈Lä&×*Ñ*Ô+EÀtÓLˆØˆˆf‰
ð �d‰?؈Làˆ
ô"×6Ñ6°tÖ<ˆDÙØà�‰˜sÔ#Ü&×3Ñ3°DÓ9�ØÐ%Ø ’ð#×)Ñ)°<ÈÑ*MÕNà"×)Ñ)°8ÀVÑ*LÔMð!%¤S¨£[°1¡_Ð%6Ð 7�IÙ Ø"×)Ñ)°<ÈÑ*SÔTØà × Ñ  |¸TÑBÕ Cð5=ð8Ðr?cóz—tj|«}tjdd|«}|j dd«}|j «} t
|«}|jr|j|vr|Sy|jd«r|Sd|vr|jd«d|vr|Sd|vr|Sy#t$rYywxYw) zÅChecks a uri value to see if it's allowed
:arg value: the uri value to sanitize
:arg allowed_protocols: list of allowed protocols
:returns: allowed value or None
z[`\000-\040\177-\240\s]+ru�NÚ#Ú:rr) rÚconvert_entitiesÚrer¢ÚreplaceÚlowerrrmÚschemer¥Úsplit)r<rfrGÚ new_valueÚparseds r=Úsanitize_uri_valuez(BleachSanitizerFilter.sanitize_uri_value¼sÝ€ô"×2Ñ2°5Ó9ˆ ô—F‘FÐ6¸¸IÓFˆ ð×%Ñ% h°Ó3ˆ ð—O‘OÓ%ˆ ð ô˜iÓ(ˆFð