
^Wc        !   @` s  d  d l  m Z m Z m Z d  d l m Z d  d l m Z d  d l Z d  d l	 Z	 d d l
 m Z m Z m Z m Z d d l
 m Z m Z d d l m Z d  d	 l m Z y d  d
 l m Z Wn e k
 r e Z n Xy d  d l m Z Wn' e k
 rd e f d     YZ n Xe g  e D] Z e j d  ^ q" Z e g  e D] Z e j d  ^ qJ Z e g  e D] Z e j d  ^ qr Z e e d d g  BZ d Z  e j! re	 j" e  e# d   Z$ n e	 j" e   Z$ e% 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 g   Z& e	 j" d3  Z' i  Z( d4 e f d5     YZ) d e+ e+ d6  Z, d7 e f d8     YZ- d9 e- f d:     YZ. d; e/ f d<     YZ0 d= e f d>     YZ1 d? e f d@     YZ2 dA   Z3 d S(B   i    (   t   absolute_importt   divisiont   unicode_literals(   t	   text_type(   t   http_clientNi   (   t   EOFt   spaceCharacterst   asciiLetterst   asciiUppercase(   t	   encodingst   ReparseException(   t   utils(   t   StringIO(   t   BytesIO(   t   BufferedIOBaseR   c           B` s   e  Z RS(    (   t   __name__t
   __module__(    (    (    sq   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/inputstream.pyR      s   u   asciit   >t   <u   [---﷐-﷯￾￿🿾🿿𯿾𯿿𿿾𿿿񏿾񏿿񟿾񟿿񯿾񯿿񿿾񿿿򏿾򏿿򟿾򟿿򯿾򯿿򿿾򿿿󏿾󏿿󟿾󟿿󯿾󯿿󿿾󿿿􏿾􏿿]u   "\uD800-\uDFFF"i i i i i i i i i i i i i i i i i	 i	 i
 i
 i i i i i i i i i i i i u   [	- -/:-@[-`{-~]t   BufferedStreamc           B` sM   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 RS(   u   Buffering for streams that do not have buffering of their own

    The buffer is implemented as a list of chunks on the assumption that
    joining many strings will be slow since it is O(n**2)
    c         C` s%   | |  _  g  |  _ d d g |  _ d  S(   Nii    (   t   streamt   buffert   position(   t   selfR   (    (    sq   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/inputstream.pyt   __init__A   s    		c         C` sJ   d } x, |  j  |  j d  D] } | t |  7} q W| |  j d 7} | S(   Ni    i   (   R   R   t   len(   R   t   post   chunk(    (    sq   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/inputstream.pyt   tellF   s
    c         C` sx   | |  j    k s t  | } d } x> t |  j |  | k  rd | t |  j |  8} | d 7} q' W| | g |  _ d  S(   Ni    i   (   t   _bufferedBytest   AssertionErrorR   R   R   (   R   R   t   offsett   i(    (    sq   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/inputstream.pyt   seekM   s    c         C` sp   |  j  s |  j |  S|  j d t |  j   k r_ |  j d t |  j  d  k r_ |  j |  S|  j |  Sd  S(   Ni    i   i(   R   t   _readStreamR   R   t   _readFromBuffer(   R   t   bytes(    (    sq   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/inputstream.pyt   readV   s    	 c         C` s&   t  g  |  j D] } t |  ^ q  S(   N(   t   sumR   R   (   R   t   item(    (    sq   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/inputstream.pyR   _   s    c         C` sL   |  j  j |  } |  j j |  |  j d c d 7<t |  |  j d <| S(   Ni    i   (   R   R%   R   t   appendR   R   (   R   R$   t   data(    (    sq   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/inputstream.pyR"   b   s
    c         C` s"  | } g  } |  j  d } |  j  d } x | t |  j  k  r | d k r | d k s\ t  |  j | } | t |  | k r | } | | | g |  _  n/ t |  | } | t |  g |  _  | d 7} | j | | | | ! | | 8} d } q) W| r| j |  j |   n  d j |  S(   Ni    i   t    (   R   R   R   R   R(   R"   t   join(   R   R$   t   remainingBytest   rvt   bufferIndext   bufferOffsett   bufferedDatat   bytesToRead(    (    sq   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/inputstream.pyR#   i   s&    $


(
   R   R   t   __doc__R   R   R!   R%   R   R"   R#   (    (    (    sq   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/inputstream.pyR   :   s   								c         C` s   t  |  t j  r t } n9 t |  d  rE t  |  j d  t  } n t  |  t  } | r | d  k	 ru t d   n  t	 |   St
 |  | | |  Sd  S(   Nu   readi    u7   Cannot explicitly set an encoding with a unicode string(   t
   isinstanceR   t   HTTPResponset   Falset   hasattrR%   R   t   Nonet	   TypeErrort   HTMLUnicodeInputStreamt   HTMLBinaryInputStream(   t   sourcet   encodingt	   parseMetat   chardett	   isUnicode(    (    sq   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/inputstream.pyt   HTMLInputStream   s    	
R9   c           B` s}   e  Z d  Z d Z d   Z d   Z d   Z d   Z d   Z d   Z	 d d  Z d	   Z d
   Z e d  Z d   Z RS(   u   Provides a unicode stream of characters to the HTMLTokenizer.

    This class takes care of character encoding and removing or replacing
    incorrect byte-sequences and also provides column and line tracking.

    i (  c         C` s   t  j s d |  _ d |  _ n] t d  d k rW |  j |  _ t j t	 d   |  _ n$ |  j
 |  _ t j t	 d   |  _ d g |  _ d	 |  _ |  j |  |  _ |  j   d S(
   u  Initialises the HTMLInputStream.

        HTMLInputStream(source, [encoding]) -> Normalized stream from source
        for use by html5lib.

        source can be either a file-object, local filename or a string.

        The optional encoding parameter must be a string that indicates
        the encoding.  If specified, that encoding will be used,
        regardless of any BOM or later declaration (such as in a meta
        element)

        parseMeta - Look for a <meta> element containing encoding information

        u   􏿿i   u   "[\uD800-\uDFFF]"uJ   "([\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF])"i    u   utf-8u   certainN(   u   utf-8u   certain(   R   t   supports_lone_surrogatesR7   t   reportCharacterErrorst   replaceCharactersRegexpR   t   characterErrorsUCS4t   ret   compilet   evalt   characterErrorsUCS2t   newLinest   charEncodingt
   openStreamt
   dataStreamt   reset(   R   R;   (    (    sq   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/inputstream.pyR      s    			c         C` sC   d |  _  d |  _ d |  _ g  |  _ d |  _ d |  _ d  |  _ d  S(   Nu    i    (   R   t	   chunkSizet   chunkOffsett   errorst   prevNumLinest   prevNumColsR7   t   _bufferedCharacter(   R   (    (    sq   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/inputstream.pyRM      s    						c         C` s(   t  | d  r | } n t |  } | S(   uv   Produces a file object from source.

        source can be either a file object, local filename or a string.

        u   read(   R6   R   (   R   R;   R   (    (    sq   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/inputstream.pyRK      s    	c         C` st   |  j  } | j d d |  } |  j | } | j d d |  } | d k r\ |  j | } n | | d } | | f S(   Nu   
i    ii   (   R   t   countRQ   t   rfindRR   (   R   R   R   t   nLinest   positionLinet   lastLinePost   positionColumn(    (    sq   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/inputstream.pyt	   _position   s    	c         C` s&   |  j  |  j  \ } } | d | f S(   u:   Returns (line, col) of the current position in the stream.i   (   RZ   RO   (   R   t   linet   col(    (    sq   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/inputstream.pyR      s    c         C` sL   |  j  |  j k r% |  j   s% t Sn  |  j  } |  j | } | d |  _  | S(   uo    Read one character from the stream or queue if available. Return
            EOF when EOF is reached.
        i   (   RO   RN   t	   readChunkR   R   (   R   RO   t   char(    (    sq   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/inputstream.pyR^      s    	c         C` sd  | d  k r |  j } n  |  j |  j  \ |  _ |  _ d |  _ d |  _ d |  _ |  j j	 |  } |  j
 r |  j
 | } d  |  _
 n
 | s t St |  d k r t | d  } | d k s d | k o d k n r | d |  _
 | d  } q n  |  j r$|  j |  |  j j d |  } n  | j d	 d
  } | j d d
  } | |  _ t |  |  _ t S(   Nu    i    i   ii   i   i  u   �u   
u   
u   (   R7   t   _defaultChunkSizeRZ   RN   RQ   RR   R   RO   RL   R%   RS   R5   R   t   ordRB   RC   t   subt   replacet   True(   R   RN   R)   t   lastv(    (    sq   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/inputstream.pyR]     s2    				(		c         C` s:   x3 t  t t j |    D] } |  j j d  q Wd  S(   Nu   invalid-codepoint(   t   rangeR   t   invalid_unicode_ret   findallRP   R(   (   R   R)   R    (    (    sq   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/inputstream.pyRD   +  s    "c         C` s  t  } x t j |  D] } | r( q n  t | j    } | j   } t j | | | d ! r t j | | | d ! } | t	 k r |  j
 j d  n  t } q | d k r | d k r | t |  d k r |  j
 j d  q t  } |  j
 j d  q Wd  S(   Ni   u   invalid-codepointi   i  i   (   R5   Rf   t   finditerR`   t   groupt   startR   t   isSurrogatePairt   surrogatePairToCodepointt   non_bmp_invalid_codepointsRP   R(   Rc   R   (   R   R)   t   skipt   matcht	   codepointR   t   char_val(    (    sq   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/inputstream.pyRH   /  s     	c   
      C` s}  y t  | | f } Wn t k
 r x& | D] } t |  d k  s+ t  q+ Wd j g  | D] } d t |  ^ qZ  } | s d | } n  t j d |  } t  | | f <n Xg  } x t ri| j |  j	 |  j
  } | d k r |  j
 |  j k r?Pq?nB | j   } | |  j k r?| j |  j	 |  j
 | ! | |  _
 Pn  | j |  j	 |  j
  |  j   s Pq q Wd j |  }	 |	 S(   u    Returns a string of characters from the stream up to but not
        including any character in 'characters' or EOF. 'characters' must be
        a container that supports the 'in' method and iteration over its
        characters.
        i   u    u   \x%02xu   ^%su   [%s]+N(   t   charsUntilRegExt   KeyErrorR`   R   R+   RE   RF   Rc   Ro   R   RO   R7   RN   t   endR(   R]   (
   R   t
   characterst   oppositet   charst   ct   regexR-   t   mRt   t   r(    (    sq   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/inputstream.pyt
   charsUntilF  s2    ,%		c         C` so   | d  k	 rk |  j d k r= | |  j |  _ |  j d 7_ qk |  j d 8_ |  j |  j | k sk t  n  d  S(   Ni    i   (   R7   RO   R   RN   R   (   R   R^   (    (    sq   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/inputstream.pyt   ungetu  s    N(   R   R   R2   R_   R   RM   RK   RZ   R   R^   R7   R]   RD   RH   R5   R|   R}   (    (    (    sq   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/inputstream.pyR9      s   	&					)		/R:   c           B` s\   e  Z d  Z d e e d  Z d   Z d   Z e e d  Z d   Z	 d   Z
 d   Z RS(	   u   Provides a unicode stream of characters to the HTMLTokenizer.

    This class takes care of character encoding and removing or replacing
    incorrect byte-sequences and also provides column and line tracking.

    c         C` s   |  j  |  |  _ t j |  |  j  t |  d f |  _ d |  _ d |  _ d |  _ |  j d d k r |  j
 | |  |  _ n  |  j   d S(   u  Initialises the HTMLInputStream.

        HTMLInputStream(source, [encoding]) -> Normalized stream from source
        for use by html5lib.

        source can be either a file-object, local filename or a string.

        The optional encoding parameter must be a string that indicates
        the encoding.  If specified, that encoding will be used,
        regardless of any BOM or later declaration (such as in a meta
        element)

        parseMeta - Look for a <meta> element containing encoding information

        u   certaini   id   u   windows-1252i    N(   RK   t	   rawStreamR9   R   t	   codecNameRJ   t   numBytesMetat   numBytesChardett   defaultEncodingR7   t   detectEncodingRM   (   R   R;   R<   R=   R>   (    (    sq   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/inputstream.pyR     s    			c         C` s6   t  j |  j d  |  j d  |  _ t j |   d  S(   Ni    u   replace(   t   codecst	   getreaderRJ   R~   RL   R9   RM   (   R   (    (    sq   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/inputstream.pyRM     s    c         C` sU   t  | d  r | } n t |  } y | j | j    Wn t |  } n X| S(   uv   Produces a file object from source.

        source can be either a file object, local filename or a string.

        u   read(   R6   R   R!   R   R   (   R   R;   R   (    (    sq   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/inputstream.pyRK     s    	c   
      C` s  |  j    } d } | d  k r9 | r9 |  j   } d } n  | d  k r8| r8d } y y d d l m } Wn! t k
 r d d l m } n Xg  } |   } x[ | j s |  j j	 |  j
  } t | t  s t  | s Pn  | j |  | j |  q W| j   | j d } |  j j d  Wq8t k
 r4q8Xn  | d  k rVd } |  j } n  i d d 6}	 | j   |	 k r|	 | j   } n  | | f S(   Nu   certainu	   tentativei    (   t   UniversalDetectoru   encodingu   windows-1252u
   iso-8859-1(   t	   detectBOMR7   t   detectEncodingMetat   charade.universaldetectorR   t   ImportErrort   chardet.universaldetectort   doneR~   R%   R   R3   R$   R   R(   t   feedt   closet   resultR!   R   t   lower(
   R   R=   R>   R<   t
   confidenceR   t   bufferst   detectorR   t   encodingSub(    (    sq   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/inputstream.pyR     sB    		
c         C` s   |  j  d d k s t  t |  } | d	 k r: d } n  | d  k rJ d  S| |  j  d k rv |  j  d d f |  _  nF |  j j d  |  j   | d f |  _  t d |  j  d | f   d  S(
   Ni   u   certainu   utf-16u	   utf-16-beu	   utf-16-leu   utf-8i    u   Encoding changed from %s to %s(   u   utf-16u	   utf-16-beu	   utf-16-le(   RJ   R   R   R7   R~   R!   RM   R
   (   R   t   newEncoding(    (    sq   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/inputstream.pyt   changeEncoding  s    	
c         C` s   i d t  j 6d t  j 6d t  j 6d t  j 6d t  j 6} |  j j d  } t | t	  s_ t
  | j | d   } d } | s | j |  } d } | s | j | d   } d } q n  |  j j | r | p d	  | S(
   u   Attempts to detect at BOM at the start of the stream. If
        an encoding can be determined from the BOM return the name of the
        encoding otherwise return Noneu   utf-8u	   utf-16-leu	   utf-16-beu	   utf-32-leu	   utf-32-bei   i   i   i    (   R   t   BOM_UTF8t   BOM_UTF16_LEt   BOM_UTF16_BEt   BOM_UTF32_LEt   BOM_UTF32_BER~   R%   R3   R$   R   t   getR!   (   R   t   bomDictt   stringR<   R!   (    (    sq   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/inputstream.pyR   
  s     
c         C` sk   |  j  j |  j  } t | t  s* t  t |  } |  j  j d  | j   } | d k rg d } n  | S(   u9   Report the encoding declared by the meta element
        i    u   utf-16u	   utf-16-beu	   utf-16-leu   utf-8(   u   utf-16u	   utf-16-beu	   utf-16-le(	   R~   R%   R   R3   R$   R   t   EncodingParserR!   t   getEncoding(   R   R   t   parserR<   (    (    sq   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/inputstream.pyR   )  s    	N(   R   R   R2   R7   Rc   R   RM   RK   R   R   R   R   (    (    (    sq   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/inputstream.pyR:     s   (		-		t   EncodingBytesc           B` s   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 e e
 e	  Z d	   Z e e  Z e d
  Z d   Z d   Z d   Z RS(   u   String-like object with an associated position and various extra methods
    If the position is ever greater than the string length then an exception is
    raisedc         C` s+   t  | t  s t  t j |  | j    S(   N(   R3   R$   R   t   __new__R   (   R   t   value(    (    sq   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/inputstream.pyR   <  s    c         C` s   d |  _  d  S(   Ni(   RZ   (   R   R   (    (    sq   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/inputstream.pyR   @  s    c         C` s   |  S(   N(    (   R   (    (    sq   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/inputstream.pyt   __iter__C  s    c         C` sS   |  j  d } |  _  | t |   k r/ t  n | d k  rD t  n  |  | | d !S(   Ni   i    (   RZ   R   t   StopIterationR8   (   R   t   p(    (    sq   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/inputstream.pyt   __next__F  s    		c         C` s
   |  j    S(   N(   R   (   R   (    (    sq   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/inputstream.pyt   nextN  s    c         C` sY   |  j  } | t |   k r$ t  n | d k  r9 t  n  | d |  _  } |  | | d !S(   Ni    i   (   RZ   R   R   R8   (   R   R   (    (    sq   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/inputstream.pyt   previousR  s    			c         C` s+   |  j  t |   k r t  n  | |  _  d  S(   N(   RZ   R   R   (   R   R   (    (    sq   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/inputstream.pyt   setPosition[  s    	c         C` s<   |  j  t |   k r t  n  |  j  d k r4 |  j  Sd  Sd  S(   Ni    (   RZ   R   R   R7   (   R   (    (    sq   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/inputstream.pyt   getPosition`  s
    	c         C` s   |  |  j  |  j  d !S(   Ni   (   R   (   R   (    (    sq   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/inputstream.pyt   getCurrentBytej  s    c         C` sc   |  j  } xJ | t |   k  rU |  | | d !} | | k rH | |  _ | S| d 7} q W| |  _ d S(   u   Skip past a list of charactersi   N(   R   R   RZ   R7   (   R   Rw   R   Rx   (    (    sq   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/inputstream.pyRn   o  s    			c         C` sc   |  j  } xJ | t |   k  rU |  | | d !} | | k rH | |  _ | S| d 7} q W| |  _ d  S(   Ni   (   R   R   RZ   R7   (   R   Rw   R   Rx   (    (    sq   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/inputstream.pyt	   skipUntil{  s    			c         C` sQ   |  j  } |  | | t |  !} | j |  } | rM |  j  t |  7_  n  | S(   u   Look for a sequence of bytes at the start of a string. If the bytes
        are found return True and advance the position to the byte after the
        match. Otherwise return False and leave the position alone(   R   R   t
   startswith(   R   R$   R   R)   R-   (    (    sq   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/inputstream.pyt
   matchBytes  s    	c         C` sh   |  |  j  j |  } | d k r^ |  j d k r= d |  _ n  |  j | t |  d 7_ t St  d S(   u   Look for the next sequence of bytes matching a given sequence. If
        a match is found advance the position to the last byte of the matchii    i   N(   R   t   findRZ   R   Rc   R   (   R   R$   t   newPosition(    (    sq   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/inputstream.pyt   jumpTo  s    (   R   R   R2   R   R   R   R   R   R   R   R   t   propertyR   R   t   currentBytet   spaceCharactersBytesRn   R   R   R   (    (    (    sq   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/inputstream.pyR   8  s    												R   c           B` s_   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	   Z RS(
   u?   Mini parser for detecting character encoding from meta elementsc         C` s   t  |  |  _ d |  _ d S(   u3   string - the data to work on for encoding detectionN(   R   R)   R7   R<   (   R   R)   (    (    sq   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/inputstream.pyR     s    c         C` s   d |  j  f d |  j f d |  j f d |  j f d |  j f d |  j f f } xv |  j D]k } t } xR | D]J \ } } |  j j |  rk y |   } PWq t k
 r t	 } Pq Xqk qk W| sX PqX qX W|  j
 S(   Ns   <!--s   <metas   </s   <!s   <?R   (   t   handleCommentt
   handleMetat   handlePossibleEndTagt   handleOthert   handlePossibleStartTagR)   Rc   R   R   R5   R<   (   R   t   methodDispatcht   bytet   keepParsingt   keyt   method(    (    sq   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/inputstream.pyR     s&    	c         C` s   |  j  j d  S(   u   Skip over commentss   -->(   R)   R   (   R   (    (    sq   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/inputstream.pyR     s    c         C` sK  |  j  j t k r t St } d  } x"t rF|  j   } | d  k rG t S| d d k r | d d k } | rC| d  k	 rC| |  _ t Sq% | d d k r | d } t |  } | d  k	 rC| |  _ t Sq% | d d k r% t	 t
 | d   } | j   } | d  k	 rCt |  } | d  k	 r@| r4| |  _ t S| } q@qCq% q% Wd  S(   Ni    s
   http-equivi   s   content-typet   charsett   content(   R)   R   R   Rc   R5   R7   t   getAttributeR<   R   t   ContentAttrParserR   t   parse(   R   t	   hasPragmat   pendingEncodingt   attrt   tentativeEncodingt   codect   contentParser(    (    sq   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/inputstream.pyR     s:    		
		c         C` s   |  j  t  S(   N(   t   handlePossibleTagR5   (   R   (    (    sq   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/inputstream.pyR     s    c         C` s   t  |  j  |  j t  S(   N(   R   R)   R   Rc   (   R   (    (    sq   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/inputstream.pyR     s    c         C` s   |  j  } | j t k r9 | r5 | j   |  j   n  t S| j t  } | d k ra | j   n+ |  j   } x | d  k	 r |  j   } qp Wt S(   NR   (
   R)   R   t   asciiLettersBytesR   R   Rc   R   t   spacesAngleBracketsR   R7   (   R   t   endTagR)   Rx   R   (    (    sq   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/inputstream.pyR     s    	
c         C` s   |  j  j d  S(   NR   (   R)   R   (   R   (    (    sq   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/inputstream.pyR     s    c         C` s  |  j  } | j t t d g  B } | d k sI t |  d k sI t  | d	 k rY d Sg  } g  } x t r| d k r | r Pnz | t k r | j   } Pn^ | d
 k r d j |  d f S| t	 k r | j
 | j    n | d k r d S| j
 |  t |  } qh W| d k r7| j   d j |  d f St |  | j   } | d k r| } x t rt |  } | | k rt |  d j |  d j |  f S| t	 k r| j
 | j    qb| j
 |  qbWn^ | d k rd j |  d f S| t	 k r| j
 | j    n | d k r-d S| j
 |  x} t rt |  } | t k rwd j |  d j |  f S| t	 k r| j
 | j    q=| d k rd S| j
 |  q=Wd S(   u_   Return a name,value pair for the next attribute in the stream,
        if one is found, or Nonet   /i   R   t   =R*   t   't   "N(   R   N(   R   R   (   R   R   (   R)   Rn   R   t	   frozensetR7   R   R   Rc   R+   t   asciiUppercaseBytesR(   R   R   R   R   (   R   R)   Rx   t   attrNamet	   attrValuet	   quoteChar(    (    sq   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/inputstream.pyR     sh    	$	

	
	(   R   R   R2   R   R   R   R   R   R   R   R   R   (    (    (    sq   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/inputstream.pyR     s   				$				R   c           B` s   e  Z d    Z d   Z RS(   c         C` s"   t  | t  s t  | |  _ d  S(   N(   R3   R$   R   R)   (   R   R)   (    (    sq   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/inputstream.pyR   U  s    c         C` s:  y!|  j  j d  |  j  j d 7_ |  j  j   |  j  j d k sH d  S|  j  j d 7_ |  j  j   |  j  j d k r |  j  j } |  j  j d 7_ |  j  j } |  j  j |  r |  j  | |  j  j !Sd  SnP |  j  j } y( |  j  j t  |  j  | |  j  j !SWn t k
 r|  j  | SXWn t k
 r5d  SXd  S(   NR   i   R   R   R   (   R   R   (	   R)   R   R   Rn   R   R7   R   R   R   (   R   t	   quoteMarkt   oldPosition(    (    sq   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/inputstream.pyR   Y  s.    (   R   R   R   R   (    (    (    sq   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/inputstream.pyR   T  s   	c         C` sp   t  |  t  r: y |  j d  }  Wq: t k
 r6 d SXn  |  rh t j d |   j   } t j	 | d  Sd Sd S(   u{   Return the python codec name corresponding to an encoding or None if the
    string doesn't correspond to a valid encoding.u   asciiu    N(
   R3   R$   t   decodet   UnicodeDecodeErrorR7   t   ascii_punctuation_reRa   R   R	   R   (   R<   t   canonicalName(    (    sq   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/inputstream.pyR   {  s    (4   t
   __future__R    R   R   t   pip._vendor.sixR   t   pip._vendor.six.movesR   R   RE   t	   constantsR   R   R   R   R	   R
   R*   R   t   ioR   R   R   R   t   objectR   R'   t   encodeR   R   R   R   t   invalid_unicode_no_surrogateRA   RF   RG   Rf   t   setRm   R   Rr   R   R7   Rc   R@   R9   R:   R$   R   R   R   R   (    (    (    sq   /private/var/folders/3n/6h2rwf155rn1m71wwyxn79n80000gn/T/pip-build-IcAT_k/pip/pip/_vendor/html5lib/inputstream.pyt   <module>   sT   "
(((		Jg'