
    hU              
          S SK J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5      r
SS/S/S/S	.r\	" S
5      rSR                  \" \" S S5      \" SS5      \" SS5      5       V s/ s H  n \" U 5      PM     sn 5      r\R"                  " S\-   S-   \R$                  5      rSr " S S\5      r " S S5      rS r " S S\R2                  5      rgs  sn f )    )chainN)unescape)html5lib_shim)
parse_shim)aabbracronymb
blockquotecodeemiliolstrongulhreftitle)r   r   r	   )httphttpsmailto 	                []?c                       \ rS rSrSrg)NoCssSanitizerWarning5    N)__name__
__module____qualname____firstlineno____static_attributes__r$       cC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\bleach/sanitizer.pyr"   r"   5   s    r*   r"   c                   6    \ rS rSrSr\\\SSSS4S jrS r	Sr
g)	Cleaner9   al  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           	      r   Xl         X l        X0l        X@l        XPl        U=(       d    / U l        Xpl        [        R                  " U R                   U R                  SSS9U l	        [        R                  " S5      U l        [        R                  " SSSSSSS9U l        Uc  / n[        U[        5      (       a  UnO\[        U[         5      (       aG  / nUR#                  5        H1  n	[        U	[        [$        45      (       d  M   UR'                  U	5        M3     SU;   a  [(        R*                  " S	[,        S
9  ggg)a  Initializes a Cleaner

:arg set tags: set of allowed 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 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.

:arg CSSSanitizer css_sanitizer: instance with a "sanitize_css" method for
    sanitizing style attribute values and style text; defaults to None

F)tagsstripconsume_entitiesnamespaceHTMLElementsetreealwaysT)quote_attr_valuesomit_optional_tagsescape_lt_in_attrsresolve_entitiessanitizealphabetical_attributesNstylez7'style' attribute specified, but css_sanitizer not set.)category)r0   
attributes	protocolsr1   strip_commentsfilterscss_sanitizerr   BleachHTMLParserparsergetTreeWalkerwalkerBleachHTMLSerializer
serializer
isinstancelistdictvaluestupleextendwarningswarnr"   )
selfr0   r>   r?   r1   r@   rA   rB   attributes_valuesrL   s
             r+   __init__Cleaner.__init__V   s   L 	$"
,}"*#44**""'	
 $11':'<<&$# #$)
   !#*d++$.!J--$&!(//1F!&4-88)008 2 ++M2 , !r*   c           
         [        U[        5      (       d)  SUR                  R                  < S3S-   n[	        U5      eU(       d  gU R
                  R                  U5      n[        U R                  U5      U R                  U R                  U R                  U R                  U R                  U R                  S9nU R                   H	  nU" US9nM     U R                   R#                  U5      $ )zCleans 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

zargument cannot be of z type, zmust be of text typer   )sourceallowed_tagsr>   strip_disallowed_tagsstrip_html_commentsrB   allowed_protocols)rV   )rI   str	__class__r%   	TypeErrorrD   parseFragmentBleachSanitizerFilterrF   r0   r>   r1   r@   rB   r?   rA   rH   render)rQ   textmessagedomfilteredfilter_classs         r+   cleanCleaner.clean   s     $$$()@)@(C7K()  G$$kk''-(;;s#"&** $ 3 3,,"nn
 !LLL#84H ) %%h//r*   )
r>   rB   rA   rD   r?   rH   r1   r@   r0   rF   )r%   r&   r'   r(   __doc__ALLOWED_TAGSALLOWED_ATTRIBUTESALLOWED_PROTOCOLSrS   rf   r)   r$   r*   r+   r-   r-   9   s*    < %#Sj#0r*   r-   c                    ^  [        T 5      (       a  T $ [        T [        5      (       a  U 4S jnU$ [        T [        5      (       a  U 4S jnU$ [	        S5      e)a   Generates 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                    > U T;   a$  TU    n[        U5      (       a	  U" XU5      $ X;   a  gST;   a"  TS   n[        U5      (       a	  U" XU5      $ X;   $ g)NT*F)callable)tagattrvalueattr_valr>   s       r+   _attr_filter.attribute_filter_factory.<locals>._attr_filter   sj    j %c?H%%#Cu55#j %c?H%%#Cu55''r*   c                    > UT;   $ Nr$   )rp   rq   rr   r>   s      r+   rt   ru      s    :%%r*   z3attributes needs to be a callable, a list or a dict)ro   rI   rK   rJ   
ValueError)r>   rt   s   ` r+   attribute_filter_factoryry      sV     
*d##	$ *d##	& 
J
KKr*   c            	           \ rS rSrSr\\\\R                  \R                  \R                  SSS4	S jrS rS rS	 rS
 rS rS rS rS rSrg)r_      zehtml5lib Filter that sanitizes text

This filter can be used anywhere html5lib filters can be used.

FTNc                     [         R                  R                  X5        [        U5      U l        [        U5      U l        [        U5      U l        Xl        Xl	        XPl
        X`l        Xl        Xpl        g)a  Creates a BleachSanitizerFilter instance

:arg source: html5lib TreeWalker stream as an html5lib TreeWalker

:arg set allowed_tags: set of allowed 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 allowed_protocols: allowed list of protocols for links; defaults
    to ``bleach.sanitizer.ALLOWED_PROTOCOLS``

:arg attr_val_is_uri: set of attributes that have URI values

:arg svg_attr_val_allows_ref: set of SVG attributes that can have
    references

:arg svg_allow_local_href: set of SVG elements that can have local
    hrefs

:arg bool strip_disallowed_tags: whether or not to strip disallowed
    tags

:arg bool strip_html_comments: whether or not to strip HTML comments

:arg CSSSanitizer css_sanitizer: instance with a "sanitize_css" method for
    sanitizing style attribute values and style text; defaults to None

N)r   FilterrS   	frozensetrW   rZ   ry   attr_filterrX   rY   attr_val_is_urisvg_attr_val_allows_refrB   svg_allow_local_href)rQ   rV   rW   r>   rZ   r   r   r   rX   rY   rB   s              r+   rS   BleachSanitizerFilter.__init__  se    ` 	%%d3%l3!*+<!=3J?%:"#6 .'>$*$8!r*   c              #      #    U HB  nU R                  U5      nU(       d  M  [        U[        5      (       a  U S h  vN   M>  Uv   MD     g  N7frw   )sanitize_tokenrI   rJ   )rQ   token_iteratortokenrets       r+   sanitize_stream%BleachSanitizerFilter.sanitize_streamA  sC     #E%%e,C#t$$	 $ s   :AAAc              #   n  #    / nU Ht  nU(       aJ  US   S:X  a  UR                  U5        M&  SR                  U Vs/ s H  oDS   PM	     sn5      SS.n/ nUv   OUS   S:X  a  UR                  U5        Mp  Uv   Mv     SR                  U Vs/ s H  oDS   PM	     sn5      SS.nUv   gs  snf s  snf 7f)z/Merge consecutive Characters tokens in a streamtype
Charactersr   data)r   r   N)appendjoin)rQ   r   characters_bufferr   
char_token	new_tokens         r+   merge_characters&BleachSanitizerFilter.merge_charactersM  s     #E =L0%,,U3
 !#BSTBSJ/BST! !-	!I )+%#Ov,.!((/K+ $0 GGBSTBSJ/BSTU 
	 # U Us   :B5B+

AB5B0B5c                 |    U R                  U R                  [        R                  R	                  U 5      5      5      $ rw   )r   r   r   r}   __iter__)rQ   s    r+   r   BleachSanitizerFilter.__iter__n  s4    $$  !5!5!>!>t!DE
 	
r*   c                 H   US   nUS;   aG  US   U R                   ;   a  U R                  U5      $ U R                  (       a  gU R                  U5      $ US:X  a2  U R                  (       d   [
        R                  " US   SSS	.S
9US'   U$ gUS:X  a  U R                  U5      $ U$ )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EmptyTagnameNCommentr   z&quot;z&#x27;)"')entitiesr   )rW   allow_tokenrX   disallowed_tokenrY   r   escapesanitize_characters)rQ   r   
token_types      r+   r   $BleachSanitizerFilter.sanitize_tokens  s      6]
;;V} 1 11''..++ ,,U339$++ - 4 4&M(,J!f <'++E22 Lr*   c                    UR                  SS5      nU(       d  U$ [        R                  [        U5      nX!S'   SU;  a  U$ / n[        R
                  " U5       H  nU(       d  M  UR                  S5      (       av  [        R                  " U5      nUb]  US:X  a  UR                  SSS.5        OUR                  SUS	.5        U[        U5      S
-   S nU(       a  UR                  SUS.5        M  UR                  SUS.5        M     U$ )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   r      )
getINVISIBLE_CHARACTERS_REsubINVISIBLE_REPLACEMENT_CHARr   next_possible_entity
startswithmatch_entityr   len)rQ   r   r   
new_tokenspartentity	remainders          r+   r   )BleachSanitizerFilter.sanitize_characters  s    yy$L&**+EtLf d?L
 "66t<Ds##&33D9% #))<*MN"))8V*LM !%S[1_%6 7I "))<*ST|TBC5 =8 r*   c                    [         R                  " U5      n[        R                  " SSU5      nUR	                  SS5      nUR                  5       n [        R                  " U5      nUR                  (       a  UR                  U;   a  U$  gUR                  S5      (       a  U$ SU;   a  UR                  S5      S   U;   a  U$ SU;   d  S	U;   a  U$ g! [         a     gf = f)
zChecks 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]+r   u   �N#:r   r   r   )r   convert_entitiesrer   replacelowerr   urlparserx   schemer   split)rQ   rr   rZ   normalized_uriparseds        r+   sanitize_uri_value(BleachSanitizerFilter.sanitize_uri_value  s     '77>  ;RP (//"= (--/	  ((8F
 ==}} 11 2(  ((-- ~%"((-a04EE **g9J.J5  		s   C 
C! C!c                    SU;   GaG  0 nUS   R                  5        GH)  u  p4Uu  pVU R                  US   Xd5      (       d  M&  X0R                  ;   a"  U R                  X@R                  5      nUc  MU  UnX0R
                  ;   a<  [        R                  " SS[        U5      5      nUR                  5       nU(       d  M  UnSUS   4U R                  ;   a9  US[        R                  S   S44;   a  [        R                  " S	U5      (       a  M  US
:X  a/  U R                  (       a  U R                  R                  U5      nOSnXBU'   GM,     X!S'   U$ )z-Handles the case where we're allowing the tagr   r   Nzurl\s*\(\s*[^#\s][^)]+?\) )Nr   xlinkr   z
^\s*[^#\s])Nr<   r   )itemsr   r   r   rZ   r   r   r   r   r1   r   r   
namespacessearchrB   sanitize_css)	rQ   r   attrsnamespaced_nameval	namespacer   	new_valuenew_vals	            r+   r   !BleachSanitizerFilter.allow_token  sY   U? E(-f(;(;(=$"1	 ''ftAA #&:&:: $ 7 7=S=S TI ( #C #&B&BB ff%A3QTVG%mmoG" 
 & %-(D,E,EE&&&11':FC+  99]C88$ #o5))"00==cB ! *-o&k )>n "&Mr*   c                    US   nUS:X  a  SUS    S3US'   OUS   (       a  US;   d   e/ nUS   R                  5        Hb  u  u  pEnU(       a	  U(       d  XTpTUb  U[        R                  ;  a  UnO[        R                  U    SU 3nUR                  S	U S
U S35        Md     SUS    SR	                  U5       S3US'   OSUS    S3US'   UR                  S5      (       a  US   S S  S3US'   SUS'   US	 U$ )Nr   r   z</r   >r   )r   r   r   r   z="r   <r   selfClosingz/>r   )r   r   prefixesr   r   r   )rQ   r   r   r   nsr   vr   s           r+   r   &BleachSanitizerFilter.disallowed_tokenZ  s=   6]
! vq1E&M6]!9999E!&v!4!4!6
A d# :=+A+A!A&*O)6)?)?)C(DAdV&LO
 q 1A3a89! "7"  frwwu~.>a@E&M  fa0E&M99]##$V}Sb12"5E&M$f&Mr*   )	rZ   rW   r   r   rB   rX   rY   r   r   )r%   r&   r'   r(   rh   ri   rj   rk   r   r   r   r   rS   r   r   r   r   r   r   r   r   r)   r$   r*   r+   r_   r_      sj     "%+%55 - E E*??# <9|
B

)V;z8tCJ$r*   r_   )	itertoolsr   r   rO   xml.sax.saxutilsr   bleachr   r   r~   ri   rj   rk   r   rangechrINVISIBLE_CHARACTERScompileUNICODEr   r   UserWarningr"   r-   ry   SanitizerFilterr_   )cs   0r+   <module>r      s     	  %    ( '	Iy  9:  ww5A;b"uR}EFESVEF 
 **S+?%?#%ErzzR  ! 	K 	U0 U0p(LVBM99 Be Gs   'C