
^Wc           @` s   d  d l  m Z m Z m Z d  d l Z d  d l m Z m Z d  d l m	 Z
 d d l m Z d d l m Z e j d e j  Z d	 e f d
     YZ d e e f d     YZ d S(   i    (   t   absolute_importt   divisiont   unicode_literalsN(   t   escapet   unescape(   t   urllib_parsei   (   t   HTMLTokenizer(   t
   tokenTypesuB  
                               ^
                               # Match a content type <application>/<type>
                               (?P<content_type>[-a-zA-Z0-9.]+/[-a-zA-Z0-9.]+)
                               # Match any character set and encoding
                               (?:(?:;charset=(?:[-a-zA-Z0-9]+)(?:;(?:base64))?)
                                 |(?:;(?:base64))?(?:;charset=(?:[-a-zA-Z0-9]+))?)
                               # Assume the rest is data
                               ,.*
                               $
                               t   HTMLSanitizerMixinc           B` s^  e  Z d  Z d d d d d d d d d	 d
 d d d d d d d d d d d d d d d d d d d d d d  d! d" d# d$ d% d& d' d( d) d* d+ d, d- d. d/ d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 d: d; d< d= d> d? d@ dA dB dC dD dE dF dG dH dI dJ dK dL dM dN dO dP dQ dR dS dT dU dV dW dX dY dZ d[ d\ d] d^ d_ d` da db dc gc Z dd de df dg dh di dj dk dl dm dn do dp dq dr ds dt du dv dw dx dy dz d{ d| d} d~ g Z d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d g# Z d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d( d d d d d d d d d d d d d d d d d7 d d d d d d d d d d d d d d d d d d d d d d d d d d d d d d ddddddddd	d
ddddddQ dddddddddd dddddddd d!d"d#d$d%d&g Z d'd d(d(d(d)d*d+d,d-d.d/d0d1d2d3d d d4d5d6d7d8d8d9d:d;d<d<d<d=d>d
d?d@dAdBdCd$d$dDdEdFdGdHg- Z dIdJdKdLdMdNdOdPdQdRdSdTdUdVd dWd dXdYdZd[d\d]d^d_d-d`d dadbdcdddedfdgdhdidjdkdldmdndodpdqd drdsd dtdudvdwdxd dydzd{d|d}d~dd d d dddddddd ddddddddddddddddddddddddddddddddddddddddddddddd$ddddddddDddEddFdd&ddGdHddddg Z d dd d d d d d d d d d dDdg Z	 dWdddadd d{dzdyddg Z
 dd d d d dddd d d ddd d g Z ddddddddd d ddd-ddd' dddedgdhdid dddddddddddddddddddddd!dd$g. Z dddddddddd ddddddddddddd~ d dd dddddddd	d
ddddg' Z dadbdcdddddg Z ddddddddddddddddddd d!d"d#d g Z d$d%d&d'd(d)g Z e e e Z e e e Z e Z e Z e Z e Z e Z d*  Z d+  Z d,  Z d-  Z RS(.  uA    sanitization of XHTML+MathML+SVG and of inline style attributes.u   au   abbru   acronymu   addressu   areau   articleu   asideu   audiou   bu   bigu
   blockquoteu   bru   buttonu   canvasu   captionu   centeru   citeu   codeu   colu   colgroupu   commandu   datagridu   datalistu   ddu   delu   detailsu   dfnu   dialogu   diru   divu   dlu   dtu   emu   event-sourceu   fieldsetu
   figcaptionu   figureu   footeru   fontu   formu   headeru   h1u   h2u   h3u   h4u   h5u   h6u   hru   iu   imgu   inputu   insu   keygenu   kbdu   labelu   legendu   liu   mu   mapu   menuu   meteru   multicolu   navu   nextidu   olu   outputu   optgroupu   optionu   pu   preu   progressu   qu   su   sampu   sectionu   selectu   smallu   soundu   sourceu   spaceru   spanu   strikeu   strongu   subu   supu   tableu   tbodyu   tdu   textareau   timeu   tfootu   thu   theadu   tru   ttu   uu   ulu   varu   videou   mactionu   mathu   merroru   mfracu   miu   mmultiscriptsu   mnu   mou   moveru   mpaddedu   mphantomu   mprescriptsu   mrootu   mrowu   mspaceu   msqrtu   mstyleu   msubu   msubsupu   msupu   mtableu   mtdu   mtextu   mtru   munderu
   munderoveru   noneu   animateu   animateColoru   animateMotionu   animateTransformu   clipPathu   circleu   defsu   descu   ellipseu	   font-faceu   font-face-nameu   font-face-srcu   gu   glyphu   hkernu   linearGradientu   lineu   markeru   metadatau   missing-glyphu   mpathu   pathu   polygonu   polylineu   radialGradientu   rectu   setu   stopu   svgu   switchu   textu   titleu   tspanu   useu   acceptu   accept-charsetu	   accesskeyu   actionu   alignu   altu   autocompleteu	   autofocusu   axisu
   backgroundu   balanceu   bgcoloru   bgpropertiesu   borderu   bordercoloru   bordercolordarku   bordercolorlightu   bottompaddingu   cellpaddingu   cellspacingu   chu	   challengeu   charu   charoffu   choffu   charsetu   checkedu   classu   clearu   coloru   colsu   colspanu   compactu   contenteditableu   controlsu   coordsu   datau   datafldu   datapagesizeu   datasrcu   datetimeu   defaultu   delayu   disabledu	   draggableu   dynsrcu   enctypeu   endu   faceu   foru   frameu
   galleryimgu   gutteru   headersu   heightu	   hidefocusu   hiddenu   highu   hrefu   hreflangu   hspaceu   iconu   idu	   inputmodeu   ismapu   keytypeu   leftspacingu   langu   listu   longdescu   loopu	   loopcountu   loopendu	   loopstartu   lowu   lowsrcu   maxu	   maxlengthu   mediau   methodu   minu   multipleu   nameu   nohrefu   noshadeu   nowrapu   openu   optimumu   patternu   pingu
   point-sizeu   posteru   pqgu   preloadu   promptu
   radiogroupu   readonlyu   relu
   repeat-maxu
   repeat-minu   replaceu   requiredu   revu   rightspacingu   rowsu   rowspanu   rulesu   scopeu   selectedu   shapeu   sizeu   srcu   startu   stepu   styleu   summaryu   suppressu   tabindexu   targetu   templateu
   toppaddingu   typeu   unselectableu   usemapu   urnu   valignu   valueu   variableu   volumeu   vspaceu   vrmlu   widthu   wrapu   xml:langu
   actiontypeu   columnalignu   columnlinesu   columnspacingu
   columnspanu   depthu   displayu   displaystyleu   equalcolumnsu	   equalrowsu   fenceu	   fontstyleu
   fontweightu   linethicknessu   lspaceu   mathbackgroundu	   mathcoloru   mathvariantu   maxsizeu   minsizeu   otheru   rowalignu   rowlinesu
   rowspacingu   rspaceu   scriptlevelu	   selectionu	   separatoru   stretchyu
   xlink:hrefu
   xlink:showu
   xlink:typeu   xmlnsu   xmlns:xlinku   accent-heightu
   accumulateu   additiveu
   alphabeticu   arabic-formu   ascentu   attributeNameu   attributeTypeu   baseProfileu   bboxu   beginu   byu   calcModeu
   cap-heightu	   clip-pathu   color-renderingu   contentu   cxu   cyu   du   dxu   dyu   descentu   duru   fillu   fill-opacityu	   fill-ruleu   font-familyu	   font-sizeu   font-stretchu
   font-styleu   font-variantu   font-weightu   fromu   fxu   fyu   g1u   g2u
   glyph-nameu   gradientUnitsu   hangingu   horiz-adv-xu   horiz-origin-xu   ideographicu   ku	   keyPointsu
   keySplinesu   keyTimesu
   marker-endu
   marker-midu   marker-startu   markerHeightu   markerUnitsu   markerWidthu   mathematicalu   offsetu   opacityu   orientu   originu   overline-positionu   overline-thicknessu   panose-1u
   pathLengthu   pointsu   preserveAspectRatiou   ru   refXu   refYu   repeatCountu	   repeatDuru   requiredExtensionsu   requiredFeaturesu   restartu   rotateu   rxu   ryu   slopeu   stemhu   stemvu
   stop-coloru   stop-opacityu   strikethrough-positionu   strikethrough-thicknessu   strokeu   stroke-dasharrayu   stroke-dashoffsetu   stroke-linecapu   stroke-linejoinu   stroke-miterlimitu   stroke-opacityu   stroke-widthu   systemLanguageu   text-anchoru   tou	   transformu   u1u   u2u   underline-positionu   underline-thicknessu   unicodeu   unicode-rangeu   units-per-emu   valuesu   versionu   viewBoxu
   visibilityu   widthsu   xu   x-heightu   x1u   x2u   xlink:actuateu   xlink:arcroleu
   xlink:roleu   xlink:titleu   xml:baseu	   xml:spaceu   yu   y1u   y2u
   zoomAndPanu   color-profileu   cursoru   filteru   masku   altGlyphu   feImageu   textpathu   trefu   azimuthu   background-coloru   border-bottom-coloru   border-collapseu   border-coloru   border-left-coloru   border-right-coloru   border-top-coloru	   directionu	   elevationu   floatu   letter-spacingu   line-heightu   overflowu   pauseu   pause-afteru   pause-beforeu   pitchu   pitch-rangeu   richnessu   speaku   speak-headeru   speak-numeralu   speak-punctuationu   speech-rateu   stressu
   text-alignu   text-decorationu   text-indentu   unicode-bidiu   vertical-alignu   voice-familyu   white-spaceu   autou   aquau   blacku   blocku   blueu   boldu   bothu   bottomu   brownu   collapseu   dashedu   dottedu   fuchsiau   grayu   greenu
   !importantu   italicu   leftu   limeu   maroonu   mediumu   navyu   normalu   oliveu   pointeru   purpleu   redu   rightu   solidu   silveru   tealu   topu   transparentu	   underlineu   whiteu   yellowu   ed2ku   ftpu   httpu   httpsu   ircu   mailtou   newsu   gopheru   nntpu   telnetu   webcalu   xmppu   calltou   feedu   aimu   rsyncu   tagu   sshu   sftpu   rtspu   afsu	   image/pngu
   image/jpegu	   image/gifu
   image/webpu	   image/bmpu
   text/plainc         C` s   | d } | t  t j    k r/ t | } n  | t d t d t d f k r | d |  j k rs |  j | |  S|  j | |  Sn | t d k r n | Sd  S(   Nu   typeu   StartTagu   EndTagu   EmptyTagu   nameu   Comment(   t   listR   t   keyst   allowed_elementst   allowed_tokent   disallowed_token(   t   selft   tokent
   token_type(    (    so   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/sanitizer.pyt   sanitize_token   s    
c   
      C` sS  d | k rOt  g  | d d  d  d  D]' \ } } | |  j k r' | | f ^ q'  } x|  j D]} | | k ry qa n  t j d d t | |   j   } | j d d  } y t j |  } Wn t	 k
 r d  } | | =n X| ra | j ra | j |  j k r| | =n  | j d k rht j | j  }	 |	 s@| | =qe|	 j d  |  j k re| | =qeqhqa qa WxC |  j D]8 } | | k rvt j d d t | |   | | <qvqvW| d	 |  j k rd
 | k rt j d | d
  r| d
 =n  d | k r|  j | d  | d <n  g  t | j    D] \ } } | | g ^ q*| d <n  | S(   Nu   dataiu   [` - - \s]+u    u   �u   content_typeu   url\s*\(\s*[^#\s][^)]+?\)u    u   nameu
   xlink:hrefu   ^\s*[^#\s].*u   style(   t   dictt   allowed_attributest   attr_val_is_urit   ret   subR   t   lowert   replacet   urlparset
   ValueErrort   Nonet   schemet   allowed_protocolst   content_type_rgxt   matcht   patht   groupt   allowed_content_typest   svg_attr_val_allows_reft   svg_allow_local_hreft   searcht   sanitize_cssR	   t   items(
   R   R   R   t   namet   valt   attrst   attrt   val_unescapedt   urit   m(    (    so   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/sanitizer.pyR      sJ    !$

	
8c         C` s  | t  d k r% d | d | d <ns | d r d j g  | d D]" \ } } d | t |  f ^ q@  } d | d | f | d <n d | d | d <| j d	  r | d d
  d | d <n  | d t t  j    k r d | d <n t  d | d <| d =| S(   Nu   EndTagu   </%s>u   nameu   datau    u    %s="%s"u   <%s%s>u   <%s>u   selfClosingiu   />u   typeu
   Characters(   R   t   joinR   t   getR	   R
   (   R   R   R   t   kt   vR*   (    (    so   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/sanitizer.pyR      s    
<c         C` sc  t  j d  j d |  } t  j d |  s1 d St  j d |  sG d Sg  } xt  j d |  D] \ } } | sx q` n  | j   |  j k r | j | d | d  q` | j d	  d
 j   d k r!x | j   D], } | |  j	 k r t  j d |  r Pq q W| j | d | d  q` | j   |  j
 k r` | j | d | d  q` q` Wd j |  S(   Nu   url\s*\(\s*[^\s)]+?\s*\)\s*u    u@   ^([:,;#%.\sa-zA-Z0-9!]|\w-\w|'[\s\w]+'|"[\s\w]+"|\([\d,\s]+\))*$u    u    ^\s*([-\w]+\s*:[^:;]*(;\s*|$))*$u   ([-\w]+)\s*:\s*([^:;]*)u   : u   ;u   -i    u
   backgroundu   borderu   marginu   paddingu\   ^(#[0-9a-f]+|rgb\(\d+%?,\d*%?,?\d*%?\)?|\d{0,2}\.?\d{0,2}(cm|em|ex|in|mm|pc|pt|px|%|,|\))?)$(   u
   backgroundu   borderu   marginu   padding(   R   t   compileR   R   t   findallR   t   allowed_css_propertiest   appendt   splitt   acceptable_css_keywordst   allowed_svg_propertiesR/   (   R   t   stylet   cleant   propt   valuet   keyword(    (    so   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/sanitizer.pyR&     s*    	 (   t   __name__t
   __module__t   __doc__t   acceptable_elementst   mathml_elementst   svg_elementst   acceptable_attributest   mathml_attributest   svg_attributesR   R#   R$   t   acceptable_css_propertiesR8   t   acceptable_svg_propertiest   acceptable_protocolst   acceptable_content_typesR   R   R5   t   allowed_css_keywordsR9   R   R"   R   R   R   R&   (    (    (    so   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/sanitizer.pyR      s  								)	t   HTMLSanitizerc           B` s,   e  Z d e e e e d d   Z d   Z RS(   c      
   C` s)   t  j |  | | | | | | d | d  S(   Nt   parser(   R   t   __init__(   R   t   streamt   encodingt	   parseMetat
   useChardett   lowercaseElementNamet   lowercaseAttrNameRN   (    (    so   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/sanitizer.pyRO   !  s    c         c` s;   x4 t  j |   D]# } |  j |  } | r | Vq q Wd  S(   N(   R   t   __iter__R   (   R   R   (    (    so   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/sanitizer.pyRV   (  s    N(   R?   R@   R   t   Truet   FalseRO   RV   (    (    (    so   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/sanitizer.pyRM      s   	(   t
   __future__R    R   R   R   t   xml.sax.saxutilsR   R   t	   six.movesR   R   t	   tokenizerR   t	   constantsR   R3   t   VERBOSER   t   objectR   RM   (    (    (    so   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/sanitizer.pyt   <module>   s   
 