a
    ‘´íj0]  ã                   @   sj   d dl Z ddlmZ ddlmZ G dd„ deƒZdd„ Ze  d	e j¡Z	e  d
e j¡Z
e  d¡Zdd„ ZdS )é    Né   )Ú_BaseHTMLProcessor)Úmake_safe_absolute_uric                       sÖ   e Zd Zh d£Zh d£Zh d£Zh d£Zh d£Ze 	d¡Z
h d£Zh d£Zh d	£Zh d
£ZdZdZh d£Zd!‡ fdd„	Z‡ fdd„Z‡ fdd„Z‡ fdd„Zdd„ Zdd„ Z‡ fdd„Zdd„ Zd"‡ fdd „	Z‡  ZS )#Ú_HTMLSanitizer>d   Ztbodyzevent-sourceZnavÚoptionZtheadÚvarÚcolZvideoZh4ZcanvasÚbZkeygenZaudioÚstrikeÚsubZinsZbuttonZtextareaÚpreZliÚmÚsZemZulÚdivÚuZasideZkbdÚdtÚoutputZh6ÚtableZsampÚqÚtdÚinputZmulticolÚselectÚsoundZh3ÚdelÚhrZ
figcaptionÚlabelÚcodeÚcaptionÚaddressZh1ZdatalistÚheaderÚiZh5ZmeterÚolÚspanÚdetailsÚdfnÚbigZdialogÚprogressZoptgroupÚfontZtfootÚttÚfooterZimgÚdirZh2ÚcommandÚstrongÚsectionZnoscriptÚthÚdlZarticleZcolgroupZ
blockquoteZsmallÚaÚcenterÚddZareaÚsupZdatagridÚtimeZfigureZnextidÚmapZfieldsetZspacerZlegendÚbrÚpZacronymÚsourceÚabbrÚciteÚformZmenuÚtr>�   ÚclearÚdefaultÚcolsÚshapeÚlangÚtemplateZgutterÚminZnohrefÚscopeÚstyleZchoffÚlowÚcolorÚdatetimeÚstepZdynsrcZunselectableZdatasrcÚsummaryÚurnÚrulesZ	autofocusZleftspacingZdatafldZhspaceÚcompactÚdisabledÚstartZdatapagesizez
point-sizeZ	loopstartZmediaZrightspacingZposterZtabindexÚrowsZaltÚhighÚframeZbgpropertiesZoptimumZvspaceÚsizeÚsuppressZvalignÚcharZhiddenÚselectedZ	accesskeyZcellpaddingÚclassÚrowspanZbordercolorlightÚiconÚautocompleteÚbgcolorZcolspanZ	hidefocusÚrequiredÚvaluer   ÚpatternÚendÚreadonlyÚheadersZloopendZcharoffÚwidthZ	draggableZlongdescZenctypeÚalignÚpromptÚ
backgroundz
repeat-minÚsrcÚdataÚrevÚtitleZusemapZnoshadeÚnameÚforr"   ÚchZkeytypeúxml:langÚdelayÚcharsetÚopenZcontenteditableÚhrefZcontrolsZbordercolordarkZvrmlr*   Z	loopcountZismapÚ	challengeÚtypeÚborderZlowsrcÚvariableÚrelzaccept-charsetÚmethodÚwrapÚvolumeÚacceptÚcheckedZfaceÚtargetZbordercolorZmultipleÚreplaceZaxisÚidZcoordsZ
toppaddingZ	maxlengthZpqgZ
galleryimgZbalanceZ
radiogroupZbottompaddingZhreflangÚactionz
repeat-maxr9   r:   r;   ÚnowrapÚloopZpreloadÚlistZ	inputmodeZpingÚmaxÚheightZcellspacing>   ÚscriptZappletrE   >.   r=   zletter-spacingúfont-variantry   zborder-left-colorú
font-stylezunicode-bidizvoice-familyzborder-colorzspeak-headerzline-heightÚ	directionz
text-alignZspeakzpause-afterztext-decorationÚpauser'   rG   ÚoverflowZazimuthZstresszbackground-colorÚdisplayzborder-collapsezwhite-spaceZrichnessúfont-familyúfont-weightzpitch-rangezspeak-numeralú	font-sizezborder-bottom-colorzvertical-alignztext-indentzborder-right-colorrb   zspeech-rateÚfloatzpause-beforeZpitchzspeak-punctuationÚcursorr„   Z	elevationzborder-top-color>'   ÚnoneÚleftZnavyÚredÚitalicÚtransparentÚwhiteÚblueÚtealÚnormalÚautoÚblockZpointerZbrownÚtopZbothZdottedÚboldZmediumZmaroonÚ	underlineÚbottomÚgrayÚyellowZlimez
!importantÚpurpleÚsilverZfuchsiaZoliveÚblackr€   ZaquaÚgreenZdashedr1   ÚrightZsolidZcollapsez\^(#[0-9a-f]+|rgb\(\d+%?,\d*%?,?\d*%?\)?|\d{0,2}\.?\d{0,2}(cm|em|ex|in|mm|pc|pt|px|%|,|\))?)$>,   r‘   Z	mscarriesZmtrZmstackZmnZmspaceZmtextZmglyphZmmultiscriptsZmfracZmsubsupZmsubÚmiZmstyleZmprescriptsZmerrorZmpaddedZmrootZmsgroupZmoverZmrowZ	semanticszannotation-xmlZmunderZmsrowZmaligngroupZmactionZmencloseZ
mlabeledtrZ
munderoverZmscarryÚmathZmtableÚmsZmlongdivZmsupZmfencedZmphantomZmtdZ
malignmarkZmslineÚmoZmsqrtÚ
annotation>c   ÚnotationZindentalignZscriptsizemultiplierZdecimalpointZstretchyZindentalignfirstZinfixlinebreakstyleÚencodingÚlengthZ
groupalignZcrossoutZvoffsetZalttextZminlabelspacingZ
stackalignZ	charalignZ
denomalignÚ
separatorsZ	equalrowsZlinethicknessÚedgeZscriptminsizeZframespacingZ	fontstyleZscriptlevelZlineleadingÚlocationZlquoterR   Z
fontweightZrowlinesú
xlink:typeÚmaxsizeZaccentÚotherZrspaceÚpositionzaltimg-heightÚ	separatorÚdepthrX   Zaltimgr‹   Z	mathcolorÚshiftZ
actiontypeZsuperscriptshiftZalignmentscopeZsideúxmlns:xlinkZ	symmetricrb   Úxmlnsrc   rf   ZdisplaystyleZmathbackgroundZrquoteZindentalignlastZindentshiftlastrp   Zlongdivstyleú
xlink:hrefrŠ   Zcolumnalignrq   r*   zaltimg-valignZaccentunderZlargeopZlspaceZfenceZlinebreakstyleZcolumnlinesZcolumnspacingZminsizeZ	selectionZbevelledÚclosezaltimg-widthZsubscriptshiftZ
columnspanZrowalignr~   Z	linebreakZequalcolumnsZindentshiftZmovablelimitsZ
rowspacingú
xlink:showZlinebreakmultcharZmathsizer;   ZindentshiftfirstZcolumnwidthZnumalignZmathvariantZindenttargetr„   >#   ZanimateTransformZradialGradientZglyphri   ZpolylineZmpathZlinearGradientÚswitchZforeignObjectÚmetadataZuseZdefsÚtextÚmarkerÚsvgZtspanZhkernzfont-face-srcZanimateMotionÚlinezfont-face-nameÚrectÚsetÚgZanimateZpolygonÚdescÚstopZanimateColorÚpathZellipser0   Úcirclez	font-facezmissing-glyph>Œ   ú	fill-rulerA   ZstemhÚy2Z
pathLengthZ	repeatDurÚstrokeZsystemLanguageZadditiveZgradientUnitsrC   ÚrxZ	transformZrepeatCountZdxZpointsZmarkerHeightrG   ZfxZhangingÚtoZcxÚyústroke-opacityz
marker-endZorientZviewBoxZbboxzxlink:actuatezstop-opacityrÉ   Z	keyPointsÚwidthsz
stop-colorÚu2ZstemvZcalcModeÚy1zunderline-positionZmarkerUnitszoverline-positionZslopeÚdZideographicr²   zmarker-startZdurÚg1zstroke-dashoffsetrW   ÚversionZbyúfill-opacityzcolor-renderingr‹   zhoriz-adv-xzunicode-rangerŒ   Úfromústroke-linejoinr_   r¹   ÚfyZopacityZdyzarabic-formústroke-linecaprb   zaccent-heightZdescentZbaseProfileztext-anchorrº   zxlink:titleÚbeginÚrZattributeNamezstrikethrough-positionZrefXzstrikethrough-thicknessZx2Úcontentrj   Úg2rm   ZascentÚoriginr»   zhoriz-origin-xz
xlink:roleÚxz	xml:spaceZrequiredFeaturesZpreserveAspectRatior�   ZrequiredExtensionsz
cap-heightrs   Z
zoomAndPanÚu1zfont-stretchÚfillzoverline-thicknessÚx1zunits-per-emÚcyZkeyTimesr†   ZmathematicalÚoffsetZrestartr‡   r|   z
marker-midZmarkerWidthÚrotateústroke-widthZ
visibilityr~   z
glyph-namezstroke-dasharrayZrefYÚunicodeÚkÚ
accumulatezunderline-thicknessr½   zx-heightÚvaluesZ
alphabeticzxlink:arcrolerŽ   Zryzxml:baseZattributeTypeZ
keySplinesrƒ   r„   zpanose-1zstroke-miterlimitN>   rä   rË   rÜ   rÑ   ré   rØ   rÍ   rÚ   úapplication/xhtml+xmlc                    s(   t t| ƒ ||¡ d| _d| _d| _d S ©Nr   )Úsuperr   Ú__init__ÚunacceptablestackÚmathmlOKÚsvgOK)Úselfr­   Ú_type©Ú	__class__© úS/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/feedparser/sanitizer.pyrñ   Þ  s    z_HTMLSanitizer.__init__c                    s$   t t| ƒ ¡  d| _d| _d| _d S rï   )rð   r   Úresetrò   ró   rô   )rõ   r÷   rù   rú   rû   å  s    z_HTMLSanitizer.resetc           
         sT  | j }i }|| jvs| j�r‚|| jv r4|  jd7  _| j d¡rrt|ƒ d¡sr|dkr`| 	d¡ |dkrr| 	d¡ |dkr�d|v r�|  j
d7  _
|dkr®d|v r®|  jd7  _| j
rÆ|| jv rÆ| j}n¼| j�rr|| jv �rr| j�sVdd	„ | jD ƒ‰ ‡ fd
d	„| jD ƒ}ˆ | _dd„ |D ƒ| _dd	„ | jD ƒ‰ ‡ fdd	„| jD ƒ}ˆ | _dd„ |D ƒ| _| j}| j ||¡}| j}n|| jv�r‚d S | j
�s’| j�rºtdd„ |D ƒƒ�rºd|v�rº| 	d¡ g }|  |¡D ]t\}}|dk�rd|v �r|  |¡}	|	�r:| 	||	f¡ n6||v �rÈ| ||¡}|dk�r,t|ƒ}| 	||f¡ �qÈtt| ƒ ||¡ d S )Nr   Úhtmlrº   rÂ   )rº   zhttp://www.w3.org/2000/svgr¨   )rº   z"http://www.w3.org/1998/Math/MathMLc                 S   s   g | ]}|  ¡ ‘qS rù   ©Úlower©Ú.0Úattrrù   rù   rú   Ú
<listcomp>  ó    z3_HTMLSanitizer.unknown_starttag.<locals>.<listcomp>c                    s   g | ]}|ˆ vr|‘qS rù   rù   ©r   r0   rý   rù   rú   r    r  c                 S   s   i | ]}|  ¡ |“qS rù   rý   r  rù   rù   rú   Ú
<dictcomp>
  r  z3_HTMLSanitizer.unknown_starttag.<locals>.<dictcomp>c                 S   s   g | ]}|  ¡ ‘qS rù   rý   rÿ   rù   rù   rú   r    r  c                    s   g | ]}|ˆ vr|‘qS rù   rù   r  rý   rù   rú   r    r  c                 S   s   i | ]}|  ¡ |“qS rù   rý   r  rù   rù   rú   r    r  c                 s   s    | ]}|d    d¡r|V  qdS )r   zxlink:N)Ú
startswithr  rù   rù   rú   Ú	<genexpr>  r  z2_HTMLSanitizer.unknown_starttag.<locals>.<genexpr>)r¹   zhttp://www.w3.org/1999/xlinkrE   rq   )Úacceptable_attributesÚacceptable_elementsrô   Ú"unacceptable_elements_with_end_tagrò   rö   ÚendswithÚdictÚgetÚappendró   Úmathml_elementsÚmathml_attributesÚsvg_elementsÚsvg_attr_mapÚsvg_attributesÚsvg_elem_mapÚanyZnormalize_attrsÚsanitize_styler   rð   r   Úunknown_starttag)
rõ   ÚtagÚattrsr  ZkeymapZmixZclean_attrsÚkeyr]   Zclean_valuer÷   rý   rú   r  ë  s`    







z_HTMLSanitizer.unknown_starttagc                    s¤   || j vr�|| jv r"|  jd8  _| jrP|| jv rP|dkr�| jr�|  jd8  _n@| jrŒ|| jv rŒ| j ||¡}|dkr�| jr�|  jd8  _nd S t	t
| ƒ |¡ d S )Nr   r¨   rÂ   )r	  r
  rò   ró   r  rô   r  r  r  rð   r   Úunknown_endtag)rõ   r  r÷   rù   rú   r  *  s    

z_HTMLSanitizer.unknown_endtagc                 C   s   d S ©Nrù   ©rõ   rÀ   rù   rù   rú   Ú	handle_pi9  s    z_HTMLSanitizer.handle_pic                 C   s   d S r  rù   r  rù   rù   rú   Úhandle_decl<  s    z_HTMLSanitizer.handle_declc                    s   | j stt| ƒ |¡ d S r  )rò   rð   r   Úhandle_datar  r÷   rù   rú   r   ?  s    z_HTMLSanitizer.handle_datac                 C   s  t  d¡ d|¡}t  d|¡s"dS t  dd|¡ ¡ r8dS g }t  d|¡D ]´\}}|sVqH| ¡ | jv r|| |d | d ¡ qH| 	d	¡d
  ¡ dv rÒ| 	¡ D ]}|| j
vrš| j |¡sš qüqš| |d | d ¡ qH| jrH| ¡ | jv rH| |d | d ¡ qHd |¡S )Nzurl\s*\(\s*[^\s)]+?\s*\)\s*ú z@^([:,;#%.\sa-zA-Z0-9!]|\w-\w|'[\s\w]+'|"[\s\w]+"|\([\d,\s]+\))*$Ú z\s*[-\w]+\s*:\s*[^:;]*;?z([-\w]+)\s*:\s*([^:;]*)z: ú;ú-r   )re   rt   ÚmarginÚpadding)ÚreÚcompiler   ÚmatchÚstripÚfindallrþ   Úacceptable_css_propertiesr  ÚsplitÚacceptable_css_keywordsÚvalid_css_valuesrô   Úacceptable_svg_propertiesÚjoin)rõ   rE   ÚcleanÚpropr]   Úkeywordrù   rù   rú   r  C  s,    ÿ
þz_HTMLSanitizer.sanitize_styler   c                    sL   t t| ƒ ||¡}|dkr|S t d¡ | j|d ¡}|rB| ¡ S t| jƒS )Nr   z--[^>]*>é   )	rð   r   Úparse_commentr'  r(  ÚsearchÚrawdatar_   Úlen)rõ   r    ÚreportÚretr)  r÷   rù   rú   r6  c  s    z_HTMLSanitizer.parse_comment)Nrî   )r   )Ú__name__Ú
__module__Ú__qualname__r	  r  r
  r,  r.  r'  r(  r/  r  r  r  r  r  r  r0  rñ   rû   r  r  r  r  r   r  r6  Ú__classcell__rù   rù   r÷   rú   r   "   s4   g 2*ÿ/g' ? r   c                 C   s<   t ||ƒ}|  dd¡} | | ¡ | ¡ }| ¡  dd¡}|S )Nz	<![CDATA[z&lt;![CDATA[z
Ú
)r   r}   Úfeedr   r*  )Zhtml_sourcer­   rö   r7   rg   rù   rù   rú   Ú_sanitize_htmlp  s    

rB  s   ^\s*<!ENTITY([^>]*?)>s   ^\s*<!DOCTYPE([^>]*?)>s   \s+(\w+)\s+"(&#\w+;|[^&"]*)"c           	      C   sê   t  d| ¡}|r| ¡ pd}| d|d … | |d d…  }} t |¡}t d|¡}t |¡}|rj|d pld}d| ¡ v r€d}nd}d}t|ƒdkr¼|r¼d	d
„ |D ƒ}|r¼dd 	|¡ d }t ||¡|  } dd„ t
 |¡D ƒ}|| |fS )z·Strips and replaces the DOCTYPE, returns (rss_version, stripped_data)

    rss_version may be 'rss091n' or None
    stripped_data is the same XML document with a replaced DOCTYPE
    s   <\wéÿÿÿÿNr   r  r   s   netscapeZrss091nc                 S   s   g | ]}t  |¡r|‘qS rù   )ÚRE_SAFE_ENTITY_PATTERNr)  )r   Úerù   rù   rú   r  ¦  s   
þz#replace_doctype.<locals>.<listcomp>s   <!DOCTYPE feed [
<!ENTITYs   >
<!ENTITY s   >
]>c                 S   s"   i | ]\}}|  d ¡|  d ¡“qS )zutf-8)Údecode)r   rë   Úvrù   rù   rú   r  ²  s   ÿz#replace_doctype.<locals>.<dictcomp>)r'  r7  rO   ÚRE_ENTITY_PATTERNr+  r   ÚRE_DOCTYPE_PATTERNrþ   r9  r1  rD  )	rg   rO   ÚheadZentity_resultsZdoctype_resultsÚdoctyper×   ÚreplacementZsafe_entitiesrù   rù   rú   Úreplace_doctypeŠ  s4    	"

þÿþþrM  )r'  rü   r   Úurlsr   r   rB  r(  Ú	MULTILINErH  rI  rD  rM  rù   rù   rù   rú   Ú<module>   s         T
