๓
^๊Wc           @` s  d  d l  m Z m Z m Z d  d l m Z y d  d l m Z Wn e k
 rS n Xd d l	 m
 Z
 m Z m Z d d l	 m Z m Z m Z d d l m Z d  d l m Z d	 j e  Z y d  d
 l m Z m Z Wn e k
 r๎ d Z n๖ Xd Z i  Z e d  d k Z xป e e j    D]ง \ Z Z e rDe e  d k s e rce e  d k rcq n  e d k r e e  d k re j  e  Z n e! e  Z e e k sทe j"   rวe e e <qวq q Wd   Z# e e e#  [ d e$ f d     YZ% d   Z& d S(   i    (   t   absolute_importt   divisiont   unicode_literals(   t	   text_type(   t   reducei   (   t   voidElementst   booleanAttributest   spaceCharacters(   t   rcdataElementst   entitiest   xmlEntities(   t   utils(   t   escapeu    (   t   register_errort   xmlcharrefreplace_errorsu   strictu   htmlentityreplaceu   ๔ฟฟi   u   &c   
      C` s  t  |  t t f  rqg  } g  } t } xด t |  j |  j |  j ! D] \ } } | rb t } qD n  | |  j } t j	 |  j | t
 |  j | d g  ! rม t j |  j | | d ! } t } n t |  } | j |  qD Wxz | D]r } t j |  }	 |	 r<| j d  | j |	  |	 j d  sW| j d  qWqๅ | j d t |  d  qๅ Wd j |  |  j f St |   Sd  S(   Ni   u   &u   ;u   &#x%s;u    (   t
   isinstancet   UnicodeEncodeErrort   UnicodeTranslateErrort   Falset	   enumeratet   objectt   startt   endR   t   isSurrogatePairt   mint   surrogatePairToCodepointt   Truet   ordt   appendt   encode_entity_mapt   gett   endswitht   hext   joinR   (
   t   exct   rest
   codepointst   skipt   it   ct   indext	   codepointt   cpt   e(    (    s   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/serializer/htmlserializer.pyt   htmlentityreplace_errors'   s0    ),	t   HTMLSerializerc           B` sก   e  Z e Z d  Z e Z e Z e Z e Z	 e Z
 e Z e Z e Z e Z e Z e Z e Z d Z d   Z d   Z d   Z d d  Z d d  Z d d  Z RS(   u   "u   quote_attr_valuesu
   quote_charu   use_best_quote_charu   omit_optional_tagsu   minimize_boolean_attributesu   use_trailing_solidusu   space_before_trailing_solidusu   escape_lt_in_attrsu   escape_rcdatau   resolve_entitiesu   alphabetical_attributesu   inject_meta_charsetu   strip_whitespaceu   sanitizec      	   K` sg   d | k r t  |  _ n  x6 |  j D]+ } t |  | | j | t |  |    q" Wg  |  _ t  |  _ d S(   u๙  Initialize HTMLSerializer.

        Keyword options (default given first unless specified) include:

        inject_meta_charset=True|False
          Whether it insert a meta element to define the character set of the
          document.
        quote_attr_values=True|False
          Whether to quote attribute values that don't require quoting
          per HTML5 parsing rules.
        quote_char=u'"'|u"'"
          Use given quote character for attribute quoting. Default is to
          use double quote unless attribute value contains a double quote,
          in which case single quotes are used instead.
        escape_lt_in_attrs=False|True
          Whether to escape < in attribute values.
        escape_rcdata=False|True
          Whether to escape characters that need to be escaped within normal
          elements within rcdata elements such as style.
        resolve_entities=True|False
          Whether to resolve named character entities that appear in the
          source tree. The XML predefined entities &lt; &gt; &amp; &quot; &apos;
          are unaffected by this setting.
        strip_whitespace=False|True
          Whether to remove semantically meaningless whitespace. (This
          compresses all whitespace to a single space except within pre.)
        minimize_boolean_attributes=True|False
          Shortens boolean attributes to give just the attribute value,
          for example <input disabled="disabled"> becomes <input disabled>.
        use_trailing_solidus=False|True
          Includes a close-tag slash at the end of the start tag of void
          elements (empty elements whose end tag is forbidden). E.g. <hr/>.
        space_before_trailing_solidus=True|False
          Places a space immediately before the closing slash in a tag
          using a trailing solidus. E.g. <hr />. Requires use_trailing_solidus.
        sanitize=False|True
          Strip all unsafe or unknown constructs from output.
          See `html5lib user documentation`_
        omit_optional_tags=True|False
          Omit start/end tags that are optional.
        alphabetical_attributes=False|True
          Reorder attributes to be in alphabetical order.

        .. _html5lib user documentation: http://code.google.com/p/html5lib/wiki/UserDocumentation
        u
   quote_charN(   R   t   use_best_quote_chart   optionst   setattrR   t   getattrt   errorst   strict(   t   selft   kwargst   attr(    (    s   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/serializer/htmlserializer.pyt   __init__h   s    .)	c         C` s9   t  | t  s t  |  j r1 | j |  j t  S| Sd  S(   N(   R   R   t   AssertionErrort   encodingt   encodet   unicode_encode_errors(   R4   t   string(    (    s   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/serializer/htmlserializer.pyR:      s    	c         C` s9   t  | t  s t  |  j r1 | j |  j d  S| Sd  S(   Nu   strict(   R   R   R8   R9   R:   (   R4   R<   (    (    s   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/serializer/htmlserializer.pyt   encodeStrictค   s    	c         #` s"  | |  _  t } g  |  _ | rI |  j rI d d l m } | | |  } n  |  j rq d d l m } | |  } n  |  j r d d l	 m } | |  } n  |  j
 rม d d l m } | |  } n  |  j r้ d d l m } | |  } n  x2| D]*} | d } | d k rไd | d } | d r9| d | d 7} n | d	 rP| d
 7} n  | d	 rษ| d	 j d  d k rฅ| d	 j d  d k r|  j d  n  d } n d } | d | | d	 | f 7} n  | d 7} |  j |  Vq๐ | d1 k ra| d k s| rF| r1| d j d  d k r1|  j d  n  |  j | d  Vq|  j t | d   Vq๐ | d2 k rโ| d }	 |  j d |	  V|	 t k rจ|  j rจt } n | rพ|  j d  n  xะ| d j   D]พ\ \ }
 } } | } |   |  j d  V|  j |  V|  j sI| t j |	 t    k rฯ| t j d t    k rฯ|  j d  V|  j sg  rpt } n t   f d   t d t  }   j d d     |  j rฟ  j d! d"    n  | r||  j  } |  j! rd   k r๘d   k r๘d } qd   k rd   k rd } qn  | d k r=  j d d#    n   j d d$    |  j |  V|  j    V|  j |  Vq|  j    VqฯqฯW|	 t" k rั|  j# rั|  j$ rภ|  j d%  Vqั|  j d&  Vn  |  j d  Vq๐ | d' k r8| d }	 |	 t k rt } n | r#|  j d  n  |  j d( |	  Vq๐ | d) k r| d } | j d*  d k rs|  j d+  n  |  j d, | d  Vq๐ | d- k r	| d }	 |	 d. } | t% k rฬ|  j d/ |	  n  |  j& r๎| t' k r๎t% | } n
 d0 |	 } |  j |  Vq๐ |  j | d  q๐ Wd  S(3   Ni   (   t   Filteru   typeu   Doctypeu   <!DOCTYPE %su   nameu   publicIdu    PUBLIC "%s"u   systemIdu    SYSTEMu   "i    u   'uA   System identifer contains both single and double quote charactersu    %s%s%su   >u
   Charactersu   SpaceCharactersu   datau   </u   Unexpected </ in CDATAu   StartTagu   EmptyTagu   <%su+   Unexpected child element of a CDATA elementu    u    u   =c         ` s   |  p |   k S(   N(    (   t   xt   y(   t   v(    s   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/serializer/htmlserializer.pyt   <lambda>๖   s    u   >"'=u   &u   &amp;u   <u   &lt;u   &#39;u   &quot;u    /u   /u   EndTagu   </%s>u   Commentu   --u   Comment contains --u	   <!--%s-->u   Entityu   ;u   Entity %s not recognizedu   &%s;(   u
   Charactersu   SpaceCharacters(   u   StartTagu   EmptyTag((   R9   R   R2   t   inject_meta_charsett   filters.inject_meta_charsetR>   t   strip_whitespacet   filters.whitespacet   sanitizet   filters.sanitizert   omit_optional_tagst   filters.optionaltagst   alphabetical_attributest   filters.alphabeticalattributest   findt   serializeErrorR=   R:   R   R   t   escape_rcdataR   t   itemst   minimize_boolean_attributesR   R   t   tuplet   quote_attr_valuesR   R   t   replacet   escape_lt_in_attrst
   quote_charR.   R   t   use_trailing_solidust   space_before_trailing_solidusR	   t   resolve_entitiesR
   (   R4   t
   treewalkerR9   t   in_cdataR>   t   tokent   typet   doctypeRV   t   namet   attr_namespacet	   attr_namet
   attr_valuet   kt
   quote_attrt   datat   key(    (   RA   s   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/serializer/htmlserializer.pyt	   serializeซ   sา    						



	

	#
						
	



c         C` sE   | r% d j  t |  j | |    Sd j  t |  j |    Sd  S(   Nt    u    (   R!   t   listRg   (   R4   RZ   R9   (    (    s   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/serializer/htmlserializer.pyt   render.  s    u   XXX ERROR MESSAGE NEEDEDc         C` s&   |  j  j |  |  j r" t  n  d  S(   N(   R2   R   R3   t   SerializeError(   R4   Re   (    (    s   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/serializer/htmlserializer.pyRN   4  s    	(   u   quote_attr_valuesu
   quote_charu   use_best_quote_charu   omit_optional_tagsu   minimize_boolean_attributesu   use_trailing_solidusu   space_before_trailing_solidusu   escape_lt_in_attrsu   escape_rcdatau   resolve_entitiesu   alphabetical_attributesu   inject_meta_charsetu   strip_whitespaceu   sanitizeN(   t   __name__t
   __module__R   RS   RV   R   R.   RI   RQ   RW   RX   RU   RO   RY   RK   RC   RE   RG   R/   R7   R:   R=   t   NoneRg   Rj   RN   (    (    (    s   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/serializer/htmlserializer.pyR-   I   s4        	5		c         C` s   d S(   u   Error in serialized treeN(    (   t	   Exception(    (    s   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/serializer/htmlserializer.pyRk   ;  s    N('   t
   __future__R    R   R   t   pip._vendor.sixR   t	   functoolsR   t   ImportErrort	   constantsR   R   R   R   R	   R
   Rh   R   t   xml.sax.saxutilsR   R!   t   codecsR   R   R;   R   t   lent   is_ucs4Ri   RP   Rc   RA   R   R   t   islowerR,   R   R-   Rk   (    (    (    s   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/serializer/htmlserializer.pyt   <module>   s@   
	๒