o
    ì6Wj0]  ã                   @   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   úevent-sourceÚaÚbÚiÚmÚpÚqÚsÚuÚbrÚddÚdlÚdtÚemÚh1Úh2Úh3Úh4Úh5Úh6ÚhrÚliÚolÚtdÚthÚtrÚttÚulÚbigÚcolÚdelÚdfnÚdirÚdivÚimgÚinsÚkbdÚmapÚnavÚpreÚsubÚsupÚvarÚabbrÚareaÚciteÚcodeÚfontÚformÚmenuÚsampÚspanÚtimeÚasideÚaudioÚinputÚlabelÚmeterÚsmallÚsoundÚtableÚtbodyÚtfootÚtheadÚvideoÚbuttonÚcanvasÚcenterÚdialogÚfigureÚfooterÚheaderÚkeygenÚlegendÚnextidÚoptionÚoutputÚselectÚsourceÚspacerÚstrikeÚstrongÚacronymÚaddressÚarticleÚcaptionÚcommandÚdetailsÚsectionÚcolgroupÚdatagridÚdatalistÚfieldsetÚmulticolÚnoscriptÚoptgroupÚprogressÚtextareaÚ
blockquoteÚ
figcaption>�   ú
point-sizeú
repeat-maxú
repeat-minúaccept-charsetÚchÚidÚaltr&   ÚendÚforÚlowÚmaxÚminÚpqgÚrelÚrevÚsrcÚurnr1   ÚaxisÚcharr3   ÚcolsÚdataÚfacer6   ÚhighÚhrefÚiconÚlangÚlistÚloopÚnameÚopenÚpingÚrowsÚsizer9   ÚstepÚtypeÚvrmlÚwrapÚalignÚchoffÚclassÚclearÚcolorÚdelayÚframeÚismapr>   ÚmediaÚrulesÚscopeÚshapeÚstartÚstyleÚtitleÚvalueÚwidthÚacceptÚactionÚborderÚcoordsÚdynsrcÚgutterÚheightÚhiddenÚhspaceÚlowsrcÚmethodÚnohrefÚnowrapÚposterÚpromptÚtargetÚusemapÚvalignÚvolumeÚvspaceÚbalanceÚbgcolorÚcharoffÚcharsetÚcheckedÚcolspanÚcompactÚdatafldÚdatasrcÚdefaultÚenctypeÚheadersÚkeytypeÚloopendÚnoshadeÚoptimumÚpatternÚpreloadÚreplaceÚrowspanÚsummaryÚcontrolsÚdatetimeÚdisabledÚhreflangÚlongdescÚmultipleÚreadonlyÚrequiredÚselectedÚsuppressÚtabindexÚtemplateÚvariableÚ	accesskeyÚ	autofocusÚ	challengeÚ	draggableÚ	hidefocusÚ	inputmodeÚ	loopcountÚ	loopstartÚ	maxlengthÚ
backgroundÚ
galleryimgÚ
radiogroupÚ
toppaddingÚbordercolorÚcellpaddingÚcellspacingÚleftspacingÚautocompleteÚbgpropertiesÚdatapagesizeÚrightspacingÚunselectableÚbottompaddingÚbordercolordarkÚcontenteditableÚbordercolorlightúxml:lang>   rœ   ÚappletÚscript>.   ú
text-alignúline-heightúpause-afterúpitch-rangeúspeech-rateútext-indentúwhite-spaceúborder-colorúpause-beforeúspeak-headerúunicode-bidiúvoice-familyúspeak-numeralúletter-spacingúvertical-alignúborder-collapseútext-decorationúbackground-colorúborder-top-colorúborder-left-colorúspeak-punctuationúborder-right-colorúborder-bottom-colorr5   r’   r“   ÚfloatÚpauseÚpitchÚspeakrŸ   Úcursorr¦   Ústressr²   ÚazimuthÚdisplayÚoverflowÚrichnessÚ	directionÚ	elevationú	font-sizeú
font-styleúfont-familyúfont-weightúfont-variant>'   ú
!importantÚredÚtopÚaquaÚautoÚblueÚboldÚbothÚgrayÚleftÚlimeÚnavyÚnoneÚtealÚblackÚblockÚbrownÚgreenÚoliveÚrightÚsolidÚwhiteÚbottomrI   ÚdashedÚdottedÚitalicÚmaroonÚmediumÚnormalr¬   ÚpurpleÚsilverÚyellowÚfuchsiaÚpointerÚcollapseÚ	underlineÚtransparentz\^(#[0-9a-f]+|rgb\(\d+%?,\d*%?,?\d*%?\)?|\d{0,2}\.?\d{0,2}(cm|em|ex|in|mm|pc|pt|px|%|,|\))?)$>,   úannotation-xmlÚmiÚmnÚmoÚmsÚmtdÚmtrÚmathÚmrowÚmsubÚmsupr'  ÚmfracÚmoverÚmrootÚmsqrtÚmsrowÚmtextÚmerrorÚmglyphÚmslineÚmspaceÚmstackÚmstyleÚmtableÚmunderÚmactionÚmfencedÚmpaddedÚmscarryÚmsgroupÚmsubsupÚmencloseÚmlongdivÚmphantomÚ	mscarriesÚ	semanticsÚ
annotationÚ
malignmarkÚ
mlabeledtrÚ
munderoverÚmaligngroupÚmprescriptsÚmmultiscripts>c   úaltimg-widthúaltimg-heightúaltimg-valignro   r&   ry   Úedger6   r�   r‡   Úsider�   ÚcloseÚdepthÚfencer•   ÚotherÚshiftrŸ   ÚxmlnsÚaccentÚaltimgr¦   ÚlengthÚlquoteÚlspaceÚrquoteÚrspaceÚalttextr  ÚlargeopÚmaxsizeÚminsizerÇ   ÚvoffsetÚbevelledÚcrossoutÚencodingÚlocationÚmathsizeÚnotationÚnumalignr  ÚpositionÚrowalignÚrowlinesÚstretchyÚ	charalignÚ	equalrowsÚ	fontstyleÚ	linebreakÚ	mathcolorÚ	selectionÚ	separatorÚ	symmetricÚ
actiontypeÚ
columnspanÚ
denomalignÚ
fontweightÚ
groupalignÚ
rowspacingÚ
separatorsÚ
stackalignÚaccentunderÚcolumnalignÚcolumnlinesÚcolumnwidthÚindentalignÚindentshiftÚlineleadingÚmathvariantÚscriptlevelÚdecimalpointÚdisplaystyleÚequalcolumnsÚframespacingÚindenttargetÚlongdivstyleÚcolumnspacingÚlinethicknessÚmovablelimitsÚscriptminsizeÚalignmentscopeÚlinebreakstyleÚmathbackgroundÚsubscriptshiftÚindentalignlastÚindentshiftlastÚminlabelspacingÚindentalignfirstÚindentshiftfirstÚsuperscriptshiftÚlinebreakmultcharÚinfixlinebreakstyleÚscriptsizemultiplierú
xlink:hrefú
xlink:showú
xlink:typeúxmlns:xlink>#   ú	font-faceúfont-face-srcúmissing-glyphúfont-face-namer   ÚgÚsetÚsvgÚuseÚdefsÚdescÚlineÚpathÚrectÚstopÚtextÚglyphÚhkernÚmpathr�   ÚtspanÚcircleÚmarkerÚswitchÚanimateÚellipseÚpolygonÚmetadataÚpolylineÚanimateColorÚanimateMotionÚforeignObjectÚlinearGradientÚradialGradientÚanimateTransform>Œ   úpanose-1úx-heightúxml:baseú	xml:spaceú
cap-heightú
glyph-nameú
marker-endú
marker-midú
stop-colorú
xlink:roleúarabic-formúhoriz-adv-xútext-anchorúxlink:titleúfont-stretchúmarker-startústop-opacityúunits-per-emúaccent-heightúunicode-rangeúxlink:actuateúxlink:arcroleúhoriz-origin-xúcolor-renderingústroke-dasharrayúoverline-positionústroke-dashoffsetústroke-miterlimitúoverline-thicknessúunderline-positionúunderline-thicknessústrikethrough-positionústrikethrough-thicknessÚdÚkÚrÚxÚyÚbyÚcxÚcyÚdxÚdyÚfxÚfyÚg1Úg2ro   ÚrxÚryÚtoÚu1Úu2Úx1Úx2Úy1Úy2Údurrq   rt   ru   ÚbboxÚfillÚfromrƒ   r†   rÌ  ÚrefXÚrefYrŒ   Úbeginr‘   r“   ÚslopeÚstemhÚstemvrŸ   ru  Úascentr¦   ÚoffsetÚorientÚoriginÚpointsÚrotateÚstroker¯   ÚvaluesÚwidthsÚcontentÚdescentr  ÚhangingÚopacityÚrestartÚunicodeÚversionÚviewBoxÚadditiveÚcalcModeÚkeyTimesÚ	keyPointsÚ	repeatDurÚ	transformÚ
accumulateÚ
alphabeticÚ
keySplinesÚ
pathLengthÚ
visibilityÚ
zoomAndPanÚbaseProfileÚideographicÚmarkerUnitsÚmarkerWidthÚrepeatCountÚmarkerHeightÚmathematicalÚattributeNameÚattributeTypeÚgradientUnitsÚsystemLanguageÚrequiredFeaturesÚrequiredExtensionsÚpreserveAspectRatiorð   ú	fill-ruler  r  r½  r¾  r¿  r  r  rÀ  úfill-opacityr  ústroke-widthústroke-linecapústroke-opacityústroke-linejoinN>   r  r*  rO  rP  rQ  rR  rS  rT  úapplication/xhtml+xmlc                    s(   t t| ƒ ||¡ d| _d| _d| _d S ©Nr   )Úsuperr   Ú__init__ÚunacceptablestackÚmathmlOKÚsvgOK)Úselfr„  Ú_type©Ú	__class__© úc/home/esfera/Documents/content_generation/venv/lib/python3.10/site-packages/feedparser/sanitizer.pyrX  Þ  s   
z_HTMLSanitizer.__init__c                    s$   t t| ƒ ¡  d| _d| _d| _d S rV  )rW  r   ÚresetrY  rZ  r[  )r\  r^  r`  ra  rb  å  s   
z_HTMLSanitizer.resetc           
         s:  | j }i }|| jvs| jr¼|| jv r|  jd7  _| j d¡r8t|ƒ d¡s8|dkr/| 	d¡ |dkr8| 	d¡ |dkrGd|v rG|  j
d7  _
|dkrVd|v rV|  jd7  _| j
rb|| jv rb| j}nZ| jrµ|| jv rµ| js§d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 ]6\}}|dkröd|v rö|  |¡}	|	rõ| 	||	f¡ qÛ||v �r| ||¡}|dk�r
t|ƒ}| 	||f¡ qÛtt| ƒ ||¡ d S )Nr   Úhtmlru  rÇ  )ru  zhttp://www.w3.org/2000/svgrG  )ru  z"http://www.w3.org/1998/Math/MathMLc                 S   ó   g | ]}|  ¡ ‘qS r`  ©Úlower©Ú.0Úattrr`  r`  ra  Ú
<listcomp>  ó    z3_HTMLSanitizer.unknown_starttag.<locals>.<listcomp>c                    ó   g | ]}|ˆ vr|‘qS r`  r`  ©rh  r   re  r`  ra  rj    ó    c                 S   ó   i | ]}|  ¡ |“qS r`  re  rm  r`  r`  ra  Ú
<dictcomp>
  ó    z3_HTMLSanitizer.unknown_starttag.<locals>.<dictcomp>c                 S   rd  r`  re  rg  r`  r`  ra  rj    rk  c                    rl  r`  r`  rm  re  r`  ra  rj    rn  c                 S   ro  r`  re  rm  r`  r`  ra  rp    rq  c                 s   s"   � | ]}|d    d¡r|V  qdS )r   zxlink:N)Ú
startswithrm  r`  r`  ra  Ú	<genexpr>  s   €  z2_HTMLSanitizer.unknown_starttag.<locals>.<genexpr>)rÀ  zhttp://www.w3.org/1999/xlinkrœ   r�   )Úacceptable_attributesÚacceptable_elementsr[  Ú"unacceptable_elements_with_end_tagrY  r]  ÚendswithÚdictÚgetÚappendrZ  Úmathml_elementsÚmathml_attributesÚsvg_elementsÚsvg_attr_mapÚsvg_attributesÚsvg_elem_mapÚanyÚnormalize_attrsÚsanitize_styler   rW  r   Úunknown_starttag)
r\  ÚtagÚattrsrt  ÚkeymapÚmixÚclean_attrsÚkeyrž   Úclean_valuer^  re  ra  r„  ë  sd   





€

€z_HTMLSanitizer.unknown_starttagc                    s¤   || j vrH|| jv r|  jd8  _| jr(|| jv r(|dkr'| jr'|  jd8  _n | jrF|| jv rF| j ||¡}|dkrE| jrE|  jd8  _nd S t	t
| ƒ |¡ d S )Nr   rG  rÇ  )ru  rv  rY  rZ  r{  r[  r}  r€  ry  rW  r   Úunknown_endtag)r\  r…  r^  r`  ra  rŒ  *  s   

€€z_HTMLSanitizer.unknown_endtagc                 C   ó   d S ©Nr`  ©r\  rÏ  r`  r`  ra  Ú	handle_pi9  ó   z_HTMLSanitizer.handle_pic                 C   r�  rŽ  r`  r�  r`  r`  ra  Úhandle_decl<  r‘  z_HTMLSanitizer.handle_declc                    s   | j stt| ƒ |¡ d S d S rŽ  )rY  rW  r   Úhandle_datar�  r^  r`  ra  r“  ?  s   ÿz_HTMLSanitizer.handle_datac                 C   s  t  d¡ d|¡}t  d|¡sdS t  dd|¡ ¡ rdS g }t  d|¡D ]Z\}}|s+q$| ¡ | jv r>| |d | d ¡ q$| 	d	¡d
  ¡ dv ri| 	¡ D ]}|| j
vr\| j |¡s\ nqM| |d | d ¡ q$| jr~| ¡ | jv r~| |d | d ¡ q$d |¡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   )rß   r¢   ÚmarginÚpadding)ÚreÚcompiler.   ÚmatchÚstripÚfindallrf  Úacceptable_css_propertiesrz  ÚsplitÚacceptable_css_keywordsÚvalid_css_valuesr[  Úacceptable_svg_propertiesÚjoin)r\  rœ   ÚcleanÚproprž   Úkeywordr`  r`  ra  rƒ  C  s0   

ÿ€€€
z_HTMLSanitizer.sanitize_styler   c                    sL   t t| ƒ ||¡}|dkr|S t d¡ | j|d ¡}|r!| ¡ S t| jƒS )Nr   z--[^>]*>é   )	rW  r   Úparse_commentrš  r›  ÚsearchÚrawdatarq   Úlen)r\  r	   ÚreportÚretrœ  r^  r`  ra  r©  c  s   
z_HTMLSanitizer.parse_comment)NrU  )r   )Ú__name__Ú
__module__Ú__qualname__ru  rt  rv  rŸ  r¡  rš  r›  r¢  r{  r|  r}  r  r~  r€  r£  rX  rb  r„  rŒ  r�  r’  r“  rƒ  r©  Ú__classcell__r`  r`  r^  ra  r   "   s6    g 2*ÿ/g' ? r   c                 C   s<   t ||ƒ}|  dd¡} | | ¡ | ¡ }| ¡  dd¡}|S )Nz	<![CDATA[z&lt;![CDATA[z
Ú
)r   rÆ   ÚfeedrR   r�  )Úhtml_sourcer„  r]  r   r~   r`  r`  ra  Ú_sanitize_htmlp  s   

r¶  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 |¡}|r5|d p6d}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   s   netscapeÚrss091nc                 S   s   g | ]	}t  |¡r|‘qS r`  )ÚRE_SAFE_ENTITY_PATTERNrœ  )rh  Úer`  r`  ra  rj  ¦  s    ýÿz#replace_doctype.<locals>.<listcomp>s   <!DOCTYPE feed [
<!ENTITYs   >
<!ENTITY s   >
]>c                 S   s"   i | ]\}}|  d ¡|  d ¡“qS )zutf-8)Údecode)rh  r  Úvr`  r`  ra  rp  ²  s    ÿÿz#replace_doctype.<locals>.<dictcomp>)rš  rª  r›   ÚRE_ENTITY_PATTERNrž  r.   ÚRE_DOCTYPE_PATTERNrf  r¬  r¤  rº  )	r~   r›   ÚheadÚentity_resultsÚdoctype_resultsÚdoctyper3  ÚreplacementÚsafe_entitiesr`  r`  ra  Úreplace_doctypeŠ  s4   	"

þÿþþ
rÆ  )rš  rc  r   Úurlsr   r   r¶  r›  Ú	MULTILINEr¾  r¿  rº  rÆ  r`  r`  r`  ra  Ú<module>   s         T
