Format: application/x-python-code
⬇ Download File (12.7 KB)
   1  o
   2  
   3  /'h0]�@sjddlZddlmZddlmZGdd�de�Zdd�Ze�d	ej�Z	e�d
   4  ej�Z
   5  e�d�Zdd
   6  �ZdS)�N�)�_BaseHTMLProcessor)�make_safe_absolute_urics�eZdZhd�Zhd�Zhd�Zhd�Zhd�Ze�	d�Z
   7  hd�Zhd�Zhd	�Z
   8  hd
   9  �ZdZdZhd�Zd!�fdd�	Z�fdd�Z�fdd�Z�fdd�Zdd�Zdd�Z�fdd�Zdd�Zd"�fdd �	Z�ZS)#�_HTMLSanitizer>d�br�codeZul�inputZaudio�outputZmenuzevent-sourceZkeygen�bigZspacerZfieldsetZdatalist�tt�pZ
  10  figcaptionZoptgroup�soundZlegend�s�spanZcanvasZliZ
  11  blockquoteZnoscript�abbr�font�colZh5Zem�var�dfnZimg�sectionZolZmulticol�iZh4�dir�strongZtfoot�map�dtZarea�b�captionZacronym�addressZfigureZaside�sourceZsamp�table�citeZh3�a�div�label�h2ZinsZarticleZvideo�dd�details�header�q�centerZdatagridZmeter�supZkbdZnav�progressZdialog�thZh6�option�h1Zcolgroup�form�dlZnextid�hr�subZtextareaZsmall�strike�trZbutton�pre�time�footer�m�selectZtbodyZthead�command�td�u�del>�ZbordercolorlightZ
  12  toppadding�endZcontenteditableZdatafldZloopendZ	maxlengthZhreflangZbordercolor�revZalt�idZdatasrc�hrefZenctype�promptZtabindex�requiredrZcharoff�nameZgutterZhspaceZ	inputmode�shape�autocomplete�coordsZismap�ch�targetr�classZvrml�styleZ
  13  galleryimgZ
  14  bottompaddingZkeytype�wrapZ	loopcount�title�delayZoptimumZ
  15  radiogroupZcontrols�heightr�method�scopeZbgpropertiesZdatapagesize�action�headers�colorZbalance�srczaccept-charset�volumeZ	draggableZcellpaddingZfaceZvspaceZping�openr �rowspan�type�lang�lowZunselectableZusemapr#Zaxis�for�highZhidden�min�bgcolorZcolspan�nowrap�readonly�clearZdynsrcz
  16  repeat-min�xml:langZ	accesskey�icon�maxZ	autofocus�list�sizeZleftspacing�dataZcellspacingz
  17  point-sizeZposterZ	hidefocus�loopZnohref�frame�border�checkedZpreload�pattern�selectedZlongdesc�summary�variable�widthZ	loopstartr/�
  18  backgroundZpqg�acceptZlowsrc�charsetZvalign�char�templateZbordercolordark�stepZnoshadez
  19  repeat-max�datetime�rows�start�compact�	challenge�replaceZrightspacing�valueZchoff�disabledZmultiple�urn�relZmedia�default�suppress�cols�rules�align>rK�scriptZapplet>.rrq�	font-sizeztext-decorationzwhite-spaceZazimuthzspeak-punctuationzborder-bottom-colorrbz
  20  speak-numeral�display�font-weight�	directionzborder-colorZpitchrO�
  21  font-style�cursorzletter-spacingzline-heightzspeech-rateZpausezpause-beforeztext-indent�overflowrTzpitch-rangeZstressrVzvoice-familyzspeak-headerzborder-left-colorzpause-afterzborder-right-color�font-variantZspeak�font-familyzunicode-bidiz
  22  text-align�floatzborder-top-colorzvertical-alignZ	elevationzbackground-colorzborder-collapseZrichness>'�pointerZcollapse�yellow�rightr`�top�blackZboth�teal�purple�normalZsolid�transparentZfuchsiaZaquaZolive�grayr)�bluez
  23  !important�autoZbrownZnavyZdotted�bottom�green�left�red�blockZlime�	underlineZdashedZmaroon�italic�none�white�silverZmedium�boldz\^(#[0-9a-f]+|rgb\(\d+%?,\d*%?,?\d*%?\)?|\d{0,2}\.?\d{0,2}(cm|em|ex|in|mm|pc|pt|px|%|,|\))?)$>,ZmscarryZmtdZmsgroupZmaligngroupZmtableZmsqrtZmsrow�moZmrootZmnZmtextZmfracZmfencedZmglyphZmrowZmlongdivZmactionZmtr�
  24  annotationZmslineZmspace�miZ
  25  munderoverZmover�mathZmerrorZ
  26  mmultiscriptsZ	semanticsZmsub�msZmprescriptsZmstackZmunderZmsupZmpaddedZ
  27  malignmarkzannotation-xmlZmphantomr�ZmencloseZmsubsupZ	mscarriesZ
  28  mlabeledtrZmstyle>czaltimg-widthZ
  29  linethickness�	separatorZlinebreakmultcharZlineleadingZminsizer�Z	mathcolorZ
  30  scriptminsizer@rAZ	charalignZbevelledZrspace�
  31  xlink:showZinfixlinebreakstyleZaccentunder�otherZ
  32  groupalignZscriptlevelZcolumnalignZrowalignZindentalignfirstZindentalignlastZ	linebreak�xmlns:xlinkZ
  33  columnspacingZcolumnwidthZmathvariant�
  34  xlink:hrefrOrZlinebreakstyleZaltimgZ
  35  fontweightZdecimalpointZ
  36  rowspacing�
  37  xlink:typerUZvoffsetZequalcolumnsZ
  38  actiontyperWrXZalttextZdisplaystyleZ	equalrowsZindentshiftfirstZframespacingZsuperscriptshiftZminlabelspacingZlargeopZlspace�encodingZindentshiftZindentalignZsubscriptshiftZrquoteZ	selectionZ
  39  denomalignZrowlines�lengthrjZlongdivstyle�xmlnsrqr/ZalignmentscopeZ
  40  stackalign�closeZindenttargetZstretchy�depthZ	fontstyleZ	symmetricZ
  41  movablelimitsZmathsize�
  42  separators�positionZnumalignz
  43  altimg-height�locationZside�notationZscriptsizemultiplierr�ZaccentZcolumnlinesZ
  44  columnspanZfence�shiftZindentshiftlastz
  45  altimg-valignZcrossout�edgeZlquoteZmathbackground�maxsizer�>#ZtspanZglyphZanimateTransformZradialGradient�rectZ
  46  foreignObjectZpolylineZanimateZanimateColorrM�switchz
  47  missing-glyph�setZ
  48  animateMotionZdefs�path�svgz	font-facezfont-face-nameZlinearGradientZpolygonZuse�marker�circle�stop�metadata�line�descZellipse�g�textr!Zhkernz
  49  font-face-srcZmpath>�Z
  50  zoomAndPan�stroke-linejoinZ	repeatDurr>ZsystemLanguage�fill-opacity�cyZ
  51  attributeTyper�Zfx�y1ZdescentZrestartr@Zryz
  52  cap-heightZrequiredFeaturesZpointsz
  53  unicode-rangeZrefXzunderline-positionZmarkerUnitszunits-per-emZx2r�ZstemvrD�unicodezoverline-position�fillZ
  54  alphabeticZideographicZslopezstrikethrough-thicknessZmarkerWidthZ
  55  pathLengthZdyZhanging�widthsrIzx-heightz
  56  xlink:actuaterJzstroke-miterlimitZ
  57  visibility�u1�fyZ
  58  gradientUnitsZbyzstroke-dashoffsetr�ZrepeatCountzstop-opacity�xzxlink:titleZpreserveAspectRatioz
  59  marker-midr��yZbbox�drOzmarker-startZstemhzstroke-dasharray�cx�values�to�x1�y2�g2Zadditivezxml:baseZkeyTimesr��rrTz
  60  xlink:role�
  61  accumulater��rxzunderline-thickness�versionrY�fromrZ�contentzarabic-form�stroke-linecapZopacity�stroke-opacityZbaseProfiler^r�Z	transformz
  62  accent-heightzpanose-1zhoriz-origin-xrcz
  63  marker-endr�ztext-anchorre�originzfont-stretchz
  64  glyph-namer�Zmathematical�rotateZmarkerHeightZdxzcolor-rendering�offsetz	xml:spacer�zoverline-thicknessZrefYZcalcModeZ
  65  attributeNamer�Zorientrq�g1ZrequiredExtensionsZdur�stroke-width�strokeZ	keyPoints�	fill-rulezhoriz-adv-xr��beginZascentz
  66  xlink:arcrole�u2�kz
  67  stop-colorZviewBoxZ
  68  keySplineszstrikethrough-positionN>r�r�r�r�r�r�r�r��application/xhtml+xmlcs(tt|��||�d|_d|_d|_dS�Nr)�superr�__init__�unacceptablestack�mathmlOK�svgOK)�selfr��_type��	__class__��JC:\Users\shubh\Videos\agent\nova\Lib\site-packages\feedparser/sanitizer.pyr��s
  69  z_HTMLSanitizer.__init__cs$tt|���d|_d|_d|_dSr�)r�r�resetr�r�r�)r�r�r�r�r��s
  70  z_HTMLSanitizer.resetc
  71  s:|j}i}||jvs
  72  |jr�||jvr|jd7_|j�d�r8t|��d�s8|dkr/|�	d�|dkr8|�	d�|dkrGd|vrG|j
  73  d7_
  74  |dkrVd|vrV|jd7_|j
  75  rb||jvrb|j}nZ|jr�||j
  76  vr�|js�dd	�|jD���fd
  77  d	�|jD�}�|_dd�|D�|_d
  78  d	�|j
  79  D���fdd	�|j
  80  D�}�|_
  81  dd�|D�|_|j}|j�||�}|j}n||jvr�dS|j
  82  s�|jr�tdd�|D��r�d|vr�|�	d�g}|�|�D]6\}}|dkr�d|vr�|�|�}	|	r�|�	||	f�q�||v�r|�||�}|dk�r
  83  t|�}|�	||f�q�tt|��||�dS)Nr�htmlr�r�)r�zhttp://www.w3.org/2000/svgr�)r�z"http://www.w3.org/1998/Math/MathMLcS�g|]}|���qSr���lower��.0�attrr�r�r��
  84  <listcomp>�z3_HTMLSanitizer.unknown_starttag.<locals>.<listcomp>c�g|]}|�vr|�qSr�r��rr!rr�r�r�cS�i|]}|��|�qSr�rr	r�r�r��
  85  <dictcomp>
  86  �z3_HTMLSanitizer.unknown_starttag.<locals>.<dictcomp>cSrr�rrr�r�r�rrcrr�r�r	rr�r�r
  87  r
  88  cSrr�rr	r�r�r�rr
  89  css"�|]}|d�d�r|VqdS)rzxlink:N)�
  90  startswithr	r�r�r��	<genexpr>s� z2_HTMLSanitizer.unknown_starttag.<locals>.<genexpr>)r�zhttp://www.w3.org/1999/xlinkrKrA)�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�anyZnormalize_attrs�sanitize_stylerr�r�unknown_starttag)
  91  r��tag�attrsrZkeymapZmixZclean_attrs�keyr~Zclean_valuer�rr�r�sd
  92  
  93  
  94  
  95  
  96  
  97  �
  98  
  99  �z_HTMLSanitizer.unknown_starttagcs�||jvrH||jvr|jd8_|jr(||jvr(|dkr'|jr'|jd8_n |jrF||jvrF|j�||�}|dkrE|jrE|jd8_ndSt	t
 100  |��|�dS)Nrr�r�)rrr�r�rr�rrrr�r�unknown_endtag)r�r r�r�r�r#*s
 101  
 102  ��z_HTMLSanitizer.unknown_endtagcC�dS�Nr��r�r�r�r�r��	handle_pi9�z_HTMLSanitizer.handle_picCr$r%r�r&r�r�r��handle_decl<r(z_HTMLSanitizer.handle_declcs|js
 103  tt|��|�dSdSr%)r�r�r�handle_datar&r�r�r�r*?s�z_HTMLSanitizer.handle_datacCst�d��d|�}t�d|�sdSt�dd|���rdSg}t�d|�D]Z\}}|s+q$|��|jvr>|�|d|d�q$|�	d	�d
 104  ��dvri|�	�D]}||j
 105  vr\|j�|�s\nqM|�|d|d�q$|jr~|��|j
 106  vr~|�|d|d�q$d�|�S)Nzurl\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)rrrk�margin�padding)�re�compiler2�match�strip�findallr�acceptable_css_propertiesr�split�acceptable_css_keywords�valid_css_valuesr��acceptable_svg_properties�join)r�rK�clean�propr~�keywordr�r�r�rCs0
 107  
 108  ����
 109  z_HTMLSanitizer.sanitize_stylercsLtt|��||�}|dkr|St�d��|j|d�}|r!|��St|j�S)Nrz--[^>]*>�)	r�r�
 110  parse_commentr1r2�search�rawdatar>�len)r�r�report�retr3r�r�r�r@cs
 111  z_HTMLSanitizer.parse_comment)Nr�)r)�__name__�
 112  __module__�__qualname__rrrr6r8r1r2r9rrrrrrr:r�r�rr#r'r)r*rr@�
 113  __classcell__r�r�r�r�r"s6g2*�/g'? rcCs<t||�}|�dd�}|�|�|��}|���dd�}|S)Nz	<![CDATA[z&lt;![CDATA[z
 114  �
 115  )rr}�feedr	r4)Zhtml_sourcer�r�rrhr�r�r��_sanitize_htmlps
 116  
 117  rLs^\s*<!ENTITY([^>]*?)>s^\s*<!DOCTYPE([^>]*?)>s\s+(\w+)\s+"(&#\w+;|[^&"]*)"c	Cs�t�d|�}|r|��p
 118  d}|d|d�||dd�}}t�|�}t�d|�}t�|�}|r5|dp6d}d|��vr@d}nd}d}t|�dkr^|r^d	d
 119  �|D�}|r^dd�	|�d
 120  }t�||�|}dd�t
 121  �|�D�}|||fS)z�Strips and replaces the DOCTYPE, returns (rss_version, stripped_data)
 122  
 123      rss_version may be 'rss091n' or None
 124      stripped_data is the same XML document with a replaced DOCTYPE
 125      s<\w�����Nr�rsnetscapeZrss091ncSsg|]	}t�|�r|�qSr�)�RE_SAFE_ENTITY_PATTERNr3)r�er�r�r�r�s��z#replace_doctype.<locals>.<listcomp>s<!DOCTYPE feed [
 126  <!ENTITYs>
 127  <!ENTITY s>
 128  ]>cSs"i|]
 129  \}}|�d�|�d��qS)zutf-8)�decode)rr��vr�r�r�r�s��z#replace_doctype.<locals>.<dictcomp>)r1rArz�RE_ENTITY_PATTERNr5r2�RE_DOCTYPE_PATTERNrrCr;rO)	rhrz�headZentity_resultsZdoctype_results�doctyper��replacementZ
 130  safe_entitiesr�r�r��replace_doctype�s4	"
 131  
 132  ����
 133  rX)
 134  r1r�r�urlsrrrLr2�	MULTILINErSrTrOrXr�r�r�r��<module>sT
 135