
    )Jf                         d dgZ ddlmZ ddlZddlZddlZddlmZ dZ	 G d de
          Z G d	 de
          Zej        ej        z  ej        z  Zd
Z ej        ee          Zd Zd Z G d de          Zd ZdS )findHTMLMetaMetaNotFound    )
HTMLParserN)YADIS_HEADER_NAMEi @  c                       e Zd ZdZdS )	ParseDonezException to hold the URI that was located when the parse is
    finished. If the parse finishes without finding the URI, set it to
    None.N__name__
__module____qualname____doc__     Y/home/alex/cs2snipeproduction/venv/lib/python3.11/site-packages/openid/yadis/parsehtml.pyr   r      s           r   r   c                       e Zd ZdZdS )r   z[Exception to hold the content of the page if we did not find
    the appropriate <meta> tagNr	   r   r   r   r   r      s        " " " "r   zO
&

(?: \#x (?P<hex> [a-f0-9]+ )
|   \# (?P<dec> \d+ )
|   (?P<word> \w+ )
)

;c                    | j         dk    r$t          |                     d          d          }nr| j         dk    r#t          |                     d                    }nD| j         dk    sJ t          j        j                            |                     d                    }||                                 S t          |          S )Nhex   decword)	lastgroupintgrouphtmlentitiesname2codepointgetchr)mo	codepoints     r   substituteMOr!   (   s    	|u,,					((		|v%%%%M044RXXf5E5EFF	xxzz9~~r   c                 B    t                               t          |           S N)ent_resubr!   )ss    r   substituteEntitiesr'   7   s    ::lA&&&r   c                   R     e Zd ZdZdZdZdZdZdZ fdZ	d Z
d	 Zd
 Z fdZ xZS )YadisHTMLParserax  Parser that finds a meta http-equiv tag in the head of a html
    document.

    When feeding in data, if the tag is matched or it will never be
    found, the parser will raise ParseDone with the uri as the first
    attribute.

    Parsing state diagram
    =====================

    Any unlisted input does not affect the state::

                1, 2, 5                       8
               +--------------------------+  +-+
               |                          |  | |
            4  |    3       1, 2, 5, 7    v  | v
        TOP -> HTML -> HEAD ----------> TERMINATED
        | |            ^  |               ^  ^
        | | 3          |  |               |  |
        | +------------+  +-> FOUND ------+  |
        |                  6         8       |
        | 1, 2                               |
        +------------------------------------+

      1. any of </body>, </html>, </head> -> TERMINATE
      2. <body> -> TERMINATE
      3. <head> -> HEAD
      4. <html> -> HTML
      5. <html> -> TERMINATE
      6. <meta http-equiv='X-XRDS-Location'> -> FOUND
      7. <head> -> TERMINATE
      8. Any input -> TERMINATE
    r               c                     t           j        j        dk    r*t          t          |                               d           n't          t          |                                            | j        | _        d S )Nr+   F)strict)sysversion_infominorsuperr)   __init__TOPphase)self	__class__s    r   r4   zYadisHTMLParser.__init__c   sc    "a'' /4((111????/4((11333X


r   c                 8    | j         | _        t          d           r#   )
TERMINATEDr6   r   )r7   s    r   
_terminatezYadisHTMLParser._terminatem   s    _
oor   c                 :    |dv r|                                   d S d S )N)headbodyr   )r;   )r7   tags     r   handle_endtagzYadisHTMLParser.handle_endtagq   s.     ***OO +*r   c                    |dk    r|                                   | j        | j        k    r*|dk    r| j        | _        d S |dk    r| j        | _        d S d S | j        | j        k    r2|dk    r| j        | _        d S |dk    r|                                   d S d S | j        | j        k    r|dk    rt          |          }|                    dd                                          }|t          j                    k    r?|                    d          }t          |          }| j
        | _        t          |          d S |dv r|                                   d S d S d S )	Nr>   r=   r   metaz
http-equiv content)r=   r   )r;   r6   r5   HEADHTMLdictr   lowerr   r'   FOUNDr   )r7   r?   attrsattrs_d
http_equivraw_attr	yadis_locs          r   handle_starttagzYadisHTMLParser.handle_starttagw   s|    &==OO:!! f}}!Y


!Y


  Z49$$ f}}!Y


!!!!!  Z49$$ f}}u++$[[r::@@BB
!2!8!:!:::&{{955H 28 < <I!%DJ#I... ;: (((!!!!! %$ )(r   c                     | j         | j        | j        fv r|                                  t	          t
          |                               |          S r#   )r6   r:   rI   r;   r3   r)   feed)r7   charsr8   s     r   rQ   zYadisHTMLParser.feed   sG    :$/4:666OO_d++00777r   )r
   r   r   r   r5   rF   rE   rI   r:   r4   r;   r@   rO   rQ   __classcell__)r8   s   @r   r)   r)   ;   s           B CDDEJ        +" +" +"Z8 8 8 8 8 8 8 8 8r   r)   c                    t                      }g }	 |                     t                    }|sn|                    |           	 |                    |           nT# t
          $ rG}|j        d         }|,|                    |                                            Y d}~n|cY d}~S d}~ww xY wd                    |          }t          |          )aw  Look for a meta http-equiv tag with the YADIS header name.

    @param stream: Source of the html text
    @type stream: Object that implements a read() method that works
        like file.read

    @return: The URI from which to fetch the XRDS document
    @rtype: str

    @raises MetaNotFound: raised with the content that was
        searched as the first parameter.
    r*   r   NrC   )	r)   read
CHUNK_SIZEappendrQ   r   argsjoinr   )streamparserchunkschunkwhyurirD   s          r   r   r      s     FFJ'' 	e		KK 	 	 	(1+C{fkkmm,,,





	$ ggfooG
w

s$   A 
B,%6B' B'!B,'B,)__all__html.parserr   html.entitiesr   rer0   openid.yadis.constantsr   rV   	Exceptionr   r   
IGNORECASEUNICODEVERBOSEre_flagsent_patcompiler$   r!   r'   r)   r   r   r   r   <module>rl      sI  >
* " " " " " "     				 



 4 4 4 4 4 4 
    	   " " " " "9 " " "
 =2:%
2 
GX	&	&  ' ' 'n8 n8 n8 n8 n8j n8 n8 n8b#  #  #  #  # r   