
    h.                        S r / SQrSSKrSSKrSSKJrJr  SSKJr  SSK	J
r
  SSKJr  S	S
KJr  S	SKJr  S rSr\R$                  " SS\0S9r\R$                  " SS\0S9r\R$                  " SS\0S9r\R$                  " S5      r\R$                  " S5      r\R$                  " S5      r\R2                  " S\R4                  5      R6                  r\R2                  " S5      R6                  r\R$                  " SS\0S9r\R2                  " S5      r\R2                  " S\R4                  5      R@                  r!S r"S r#S r$ " S S\5      r% " S  S!5      r& " S" S#5      r'\'" S$S%S&9r(\'" S'S%S&9r)\'" S(S)S&9r*\'" S*S)S&9r+\'" S+S%S&9r,\'" S,S)S&9r- " S- S.\&\R\                  5      r/ " S/ S0\&\R`                  5      r1 " S1 S2\&\Rd                  5      r3 " S3 S4\&\Rh                  5      r5 " S5 S6\Rl                  5      r7\R2                  " S7\R4                  5      Rp                  r9\R2                  " S8\R4                  5      Rp                  r:SjS9 jr;  SkS: jr<  SkS; jr=SlS< jr>SlS= jr?S> r@S? rA " S@ SA\15      rB\B\7R                  SB'   SlSC jrDSD rE " SE SF\5      rF " SG SH5      rG " SI SJ5      rH " SK SL\H\15      rI\I\7R                  SM'    " SN SO\H\15      rJ\J\7R                  SP'    " SQ SR\5      rK " SS ST\L5      rM " SU SV\L5      rN " SW SX\5      rO " SY SZ\H\15      rP\P\7R                  S['    " S\ S]\15      rQ\Q\7R                  S^'   S_ rRS` rS\R2                  " Sa5      R                  rU\R2                  " Sb5      R                  rV  SmSc jrW\" \WR                   5      \Wl         SnSd jrX " Se Sf\R                  5      rY " Sg Sh\R                  5      r[Si r\\Y" 5       r]\[" 5       r^g)oz.The ``lxml.html`` tool set for HTML handling.
)document_fromstringfragment_fromstringfragments_fromstring
fromstringtostringElementdefsopen_in_browsersubmit_formfind_rel_links
find_classmake_links_absoluteresolve_base_href	iterlinksrewrite_linksparse    N)MutableMapping
MutableSet)partialurljoin   )etree   )r   )SetMixinc                     U (       d  U $ [         R                  " S[         R                  5      R                  nU" SU 5      $ )Nz^(\s*)u'z\1')recompileMsub)sr    s     D/var/www/html/env/lib/python3.13/site-packages/lxml/html/__init__.py__fix_docstringr#   6   s0    
**["$$
'
+
+Cvq>    zhttp://www.w3.org/1999/xhtmlz9descendant-or-self::a[@rel]|descendant-or-self::x:a[@rel]x
namespacesz7descendant-or-self::option|descendant-or-self::x:optionz3descendant-or-self::form|descendant-or-self::x:formztdescendant-or-self::*[@class and contains(concat(' ', normalize-space(@class), ' '), concat(' ', $class_name, ' '))]zdescendant-or-self::*[@id=$id]zstring()z&url\((["][^"]*["]|['][^']*[']|[^)]*)\)z@import "(.*?)"z%//label[@for=$id]|//x:label[@for=$id]z[^ ]+z%[^;=]*;\s*(?:url\s*=\s*)?(?P<url>.*)$c                 d    U S S S:X  a	  U SS  S:X  d  U S S S:X  a  U SS  S:X  a
  U SS US-   4$ X4$ )Nr   "' )r!   poss     r"   _unquote_matchr.   S   sN    !u|"##2A#!BC&C-2wA~ur$   c                     [        U [        5      (       a
  [        USS9$ [        U [        5      (       a
  [        USS9$ U$ )z1Convert the result back into the input type.
    zutf-8)encodingunicode)
issubclassbytesr   str)typresults     r"   _transform_resultr7   Z   s=     #u11	C		33r$   c                     [        U [        5      (       a:  U S   S:X  a1  U S[        [        5      S-    [        :X  a  U R	                  S5      S   $ U $ )Nr   {r   }r*   )
isinstancer4   lenXHTML_NAMESPACEsplit)tags    r"   _nonsr@   e   sJ    #sq6S=S3#7#9:oM99S>"%%Jr$   c                   \   ^  \ rS rSrSrS rS rS rU 4S jrS r	S r
S	 rS
 rS rSrU =r$ )Classesl   a  Provides access to an element's class attribute as a set-like collection.
Usage::

    >>> el = fromstring('<p class="hidden large">Text</p>')
    >>> classes = el.classes  # or: classes = Classes(el.attrib)
    >>> classes |= ['block', 'paragraph']
    >>> el.get('class')
    'hidden large block paragraph'
    >>> classes.toggle('hidden')
    False
    >>> el.get('class')
    'large block paragraph'
    >>> classes -= ('some', 'classes', 'block')
    >>> el.get('class')
    'large paragraph'
c                 H    Xl         [        UR                  SS5      U l        g )Nclass )_attributesr   get_get_class_value)self
attributess     r"   __init__Classes.__init__}   s    % '
 Dr$   c                    U(       a  [         R                  " SU5      (       a  [        SU-  5      eU R                  5       R	                  5       nX;   a  gUR                  U5        SR                  U5      U R                  S'   g)zC
Add a class.

This has no effect if the class is already present.
\sInvalid class name: %rN rE   )r   search
ValueErrorrI   r>   appendjoinrG   )rJ   valueclassess      r"   addClasses.add   sm     		%//5=>>'')//1u$'HHW$5!r$   c                 b   U(       a  [         R                  " SU5      (       a  [        SU-  5      eU R                  5       R	                  5        Vs/ s H  nX!:w  d  M
  UPM     nnU(       a  SR                  U5      U R                  S'   gSU R                  ;   a  U R                  S	 ggs  snf )zV
Remove a class if it is currently present.

If the class is not present, do nothing.
rO   rP   rQ   rE   N)r   rR   rS   rI   r>   rU   rG   )rJ   rV   namerW   s       r"   discardClasses.discard   s     		%//5=>>$($9$9$;$A$A$C %$CDm $C %(+(9DW%(((  ) )	%s   	B,B,c                    > U(       a  [         R                  " SU5      (       a  [        SU-  5      e[        TU ]  U5        g)z_
Remove a class; it must currently be present.

If the class is not present, raise a KeyError.
rO   rP   N)r   rR   rS   superremove)rJ   rV   	__class__s     r"   r`   Classes.remove   s5     		%//5=>>ur$   c                 \    U R                  5       nX;   =(       a    XR                  5       ;   $ N)rI   r>   )rJ   r[   rW   s      r"   __contains__Classes.__contains__   s&    ''):4==?#::r$   c                 P    [        U R                  5       R                  5       5      $ rd   )iterrI   r>   rJ   s    r"   __iter__Classes.__iter__   s    D))+11344r$   c                 P    [        U R                  5       R                  5       5      $ rd   )r<   rI   r>   ri   s    r"   __len__Classes.__len__   s    4((*00233r$   c                     U R                  5       R                  5       nSnU H  nXB;  d  M
  UR                  U5        SnM     U(       a  SR                  U5      U R                  S'   gg)z
Add all names from 'values'.
FTrQ   rE   N)rI   r>   rT   rU   rG   )rJ   valuesrW   extendedrV   s        r"   updateClasses.update   sd     '')//1E#u%  (+(9DW% r$   c                 z   U(       a  [         R                  " SU5      (       a  [        SU-  5      eU R                  5       R	                  5       n UR                  U5        SnU(       a   SR                  U5      U R                  S'   U$ U R                  S	 U$ ! [         a    UR                  U5        Sn NUf = f)z
Add a class name if it isn't there yet, or remove it if it exists.

Returns true if the class was added (and is now enabled) and
false if it was removed (and is now disabled).
rO   rP   FTrQ   rE   )	r   rR   rS   rI   r>   r`   rT   rU   rG   )rJ   rV   rW   enableds       r"   toggleClasses.toggle   s     		%//5=>>'')//1	NN5!G (+(9DW%    )  	NN5!G	s   B B:9B:)rG   rI   )__name__
__module____qualname____firstlineno____doc__rL   rX   r\   r`   re   rj   rm   rr   rv   __static_attributes____classcell__ra   s   @r"   rB   rB   l   s;     E6*;54
: r$   rB   c                   R  ^  \ rS rSrSU 4S jjr\S 5       r\R                  S 5       r\S 5       r\S 5       r	\S 5       r
\S 5       r\S	 5       r\R                  S
 5       r\R                  S 5       rS rS rS rS rS rS rSS jr  SS jrSS jrS r  SS jrSrU =r$ )	HtmlMixin   c                 $   > [         TU ]  X5        g)zset(self, key, value=None)

Sets an element attribute.  If no value is provided, or if the value is None,
creates a 'boolean' attribute without value, e.g. "<form novalidate></form>"
for ``form.set('novalidate')``.
N)r_   set)rJ   keyrV   ra   s      r"   r   HtmlMixin.set   s     	Cr$   c                 ,    [        U R                  5      $ )z2
A set-like wrapper around the 'class' attribute.
)rB   attribri   s    r"   rW   HtmlMixin.classes   s    
 t{{##r$   c                     [        U[        5      (       d   eUR                  5       nU(       a  U R                  SU5        g U R	                  S5      b  U R
                  S	 g g )NrE   )r;   rB   rI   r   rH   r   )rJ   rW   rV   s      r"   rW   r      sT    '7++++((*HHWe$XXg*G$ +r$   c                 J    U R                  5       R                  R                  $ )z
Returns the base URL, given when the page was parsed.

Use with ``urlparse.urljoin(el.base_url, href)`` to get
absolute URLs.
)getroottreedocinfoURLri   s    r"   base_urlHtmlMixin.base_url   s     !))---r$   c                     [        U 5      $ )z 
Return a list of all the forms
)_forms_xpathri   s    r"   formsHtmlMixin.forms   s    
 D!!r$   c                 4    U R                  SS[        0S9S   $ )z\
Return the <body> element.  Can be called from a child element
to get the document's head.
z//body|//x:bodyr%   r&   r   xpathr=   ri   s    r"   bodyHtmlMixin.body  "     zz+_8MzNqQQr$   c                 4    U R                  SS[        0S9S   $ )z]
Returns the <head> element.  Can be called from a child
element to get the document's head.
z//head|//x:headr%   r&   r   r   ri   s    r"   headHtmlMixin.head  r   r$   c                 `    U R                  S5      nU(       d  g[        XS9nU(       d  gUS   $ )z>
Get or set any <label> element associated with this element.
idNr   r   )rH   _label_xpath)rJ   r   r6   s      r"   labelHtmlMixin.label  s1    
 XXd^d*!9r$   c                     U R                  S5      nU(       d  [        SU -  5      e[        UR                  5      S:w  a  [        SU-  5      eUR	                  SU5        g )Nr   z9You cannot set a label for an element (%r) that has no idr   z5You can only assign label to a label element (not %r)for)rH   	TypeErrorr@   r?   r   )rJ   r   r   s      r"   r   r   "  se    XXd^K  w&G  			%r$   c                 >    U R                   nUb  UR                  S	 g g )Nr   )r   r   )rJ   r   s     r"   r   r   /  s"    

U# r$   c                 6   U R                  5       nUc   eU R                  (       ab  U R                  5       nUc(  UR                  =(       d    SU R                  -   Ul        O'UR                  =(       d    SU R                  -   Ul        UR	                  U 5        g)z
Removes this element from the tree, including its children and
text.  The tail text is joined to the previous element or
parent.
NrF   )	getparenttailgetprevioustextr`   )rJ   parentpreviouss      r"   	drop_treeHtmlMixin.drop_tree5  su     !!!!99'')H%{{0bDII=!)!4"		 Adr$   c                    U R                  5       nUc   eU R                  5       nU R                  (       aq  [        U R                  [
        5      (       aR  Uc(  UR                  =(       d    SU R                  -   Ul        O'UR                  =(       d    SU R                  -   Ul        U R                  (       a  [        U 5      (       a-  U S   nUR                  =(       d    SU R                  -   Ul        ORUc(  UR                  =(       d    SU R                  -   Ul        O'UR                  =(       d    SU R                  -   Ul        UR                  U 5      nU SS XUS-   & g)a  
Remove the tag, but not its children or text.  The children and text
are merged into the parent.

Example::

    >>> h = fragment_fromstring('<div>Hello <b>World!</b></div>')
    >>> h.find('.//b').drop_tag()
    >>> print(tostring(h, encoding='unicode'))
    <div>Hello World!</div>
NrF   r*   r   )	r   r   r   r;   r?   r4   r   r<   index)rJ   r   r   lastr   s        r"   drop_tagHtmlMixin.drop_tagE  s    !!!!##%99DHHc22%{{0bDII=!)!4"		 A994yyBx!YY_"		9	!%{{0bDII=!)!4"		 AT" $QU1Wr$   c                     UR                  5       n[        U 5       Vs/ s H*  nUR                  S5      R                  5       U:X  d  M(  UPM,     sn$ s  snf )zM
Find any links like ``<a rel="{rel}">...</a>``; returns a list of elements.
rel)lower_rel_links_xpathrH   )rJ   r   els      r"   r   HtmlMixin.find_rel_linkse  sR     iik-d3 13r66%=&&(C/ 3 1 	1 1s   'A	Ac                     [        XS9$ )z.
Find any elements with the given class name.
)
class_name)_class_xpath)rJ   r   s     r"   r   HtmlMixin.find_classm  s     D88r$   c                 j     [        XS9S   $ ! [         a    U(       a  US   s $ [        U5      ef = f)aT  
Get the first element in a document with the given id.  If none is
found, return the default argument if provided or raise KeyError
otherwise.

Note that there can be more than one element with the same id,
and this isn't uncommon in HTML documents found in the wild.
Browsers return only the first match, and this function does
the same.
r   r   )	_id_xpath
IndexErrorKeyError)rJ   r   defaults      r"   get_element_by_idHtmlMixin.get_element_by_ids  s?    	# T)!,, 	#qz!rl"		#s    22c                     [        U 5      $ )zD
Return the text content of the tag (and the text in any children).
)_collect_string_contentri   s    r"   text_contentHtmlMixin.text_content  s     't,,r$   c                 &    SSK Jn  U" XS9" U 5      $ )z
Run the CSS expression on this element and its children,
returning a list of the results.

Equivalent to lxml.cssselect.CSSSelect(expr, translator='html')(self)
-- note that pre-compiling the expression can provide a substantial
speedup.
r   )CSSSelector)
translator)lxml.cssselectr   )rJ   exprr   r   s       r"   	cssselectHtmlMixin.cssselect  s     	/47==r$   c                    ^ Tc  U R                   mTc  [        S5      eU(       a  U R                  5         US:X  a  U4S jnO%US:X  a  U4S jnOUc  U4S jnO[        SU-  5      eU R	                  U5        g)	a-  
Make all links in the document absolute, given the
``base_url`` for the document (the full URL where the document
came from), or if no ``base_url`` is given, then the ``.base_url``
of the document.

If ``resolve_base_href`` is true, then any ``<base href>``
tags in the document are used *and* removed from the document.
If it is false then any such tag is ignored.

If ``handle_failures`` is None (default), a failure to process
a URL will abort the processing.  If set to 'ignore', errors
are ignored.  If set to 'discard', failing URLs will be removed.
Nz3No base_url given, and the document has no base_urlignorec                 B   >  [        TU 5      $ ! [         a    U s $ f = frd   r   rS   hrefr   s    r"   	link_repl0HtmlMixin.make_links_absolute.<locals>.link_repl  s)     "8T22!  K s    r\   c                 >   >  [        TU 5      $ ! [         a     g f = frd   r   r   s    r"   r   r     s'     "8T22!   s    
c                    > [        TU 5      $ rd   r   r   s    r"   r   r     s    x..r$   z(unexpected value for handle_failures: %r)r   r   r   rS   r   )rJ   r   r   handle_failuresr   s    `   r"   r   HtmlMixin.make_links_absolute  s      }}HIK K""$h& 
 	) 
 $/ :_LN N 	9%r$   c                     SnU R                  SS[        0S9nU H$  nUR                  S5      nUR                  5         M&     U(       d  gU R	                  USUS9  g)aU  
Find any ``<base href>`` tag in the document, and apply its
values to all links found in the document.  Also remove the
tag once it has been applied.

If ``handle_failures`` is None (default), a failure to process
a URL will abort the processing.  If set to 'ignore', errors
are ignored.  If set to 'discard', failing URLs will be removed.
Nz//base[@href]|//x:base[@href]r%   r&   r   F)r   r   )r   r=   rH   r   r   )rJ   r   	base_hrefbasetagsbs        r"   r   HtmlMixin.resolve_base_href  sk     	::=*-)?  AAfIKKM    e1@ 	! 	Br$   c           
   #     #    [         R                  nU R                  [        R                  5       GHH  nUR
                  n[        UR                  5      nUS:X  a  SnSU;   a  UR                  S5      nUSUS4v   S H0  nXc;   d  M
  UR                  U5      nUb  [        XW5      nX&US4v   M2     SU;   a_  [        R                  UR                  S5      5       H7  nUR                  S5      nUb  [        XW5      nUSXxR                  5       4v   M9     OU H  nXc;   d  M
  X&X6   S4v   M     US:X  a  UR                  SS	5      R                  5       n	U	S
:X  a  UR                  SS	5      n
[        U
5      nU(       a  UR                  S5      OU
R!                  5       nU(       a;  [#        X(       a  UR                  S5      OU
R%                  U5      5      u  pUSX4v   GO&US:X  aF  UR                  S5      =(       d    S	nUR                  5       S:X  a  USUR                  S5      S4v   OUS:X  a  UR&                  (       a  [)        UR&                  5       Vs/ s H3  n[#        UR                  S5      UR                  S5      5      SSS2   PM5     sn[+        UR&                  5       Vs/ s H%  nUR                  S5      UR                  S5      4PM'     sn-   nU(       a!  UR-                  SS9  U H  u  pUSX4v   M     SU;   d  GM  [/        [)        US   5      5      nU(       d  GM  USSS2    H6  n[#        UR                  S5      UR                  S5      5      u  pUSX4v   M8     GMK     gs  snf s  snf 7f)a  
Yield (element, attribute, link, pos), where attribute may be None
(indicating the link is in the text).  ``pos`` is the position
where the link occurs; often 0, but sometimes something else in
the case of links in stylesheets or style tags.

Note: <base href> is *not* taken into account in any way.  The
link you get is exactly the link in the document.

Note: multiple links inside of a single text string or
attribute value are returned in reversed order.  This makes it
possible to replace or delete them from the text string value
based on their reported text positions.  Otherwise, a
modification at one text position can change the positions of
links reported later on.
objectNcodebaser   )classiddataarchivemetaz
http-equivrF   refreshcontenturlparam	valuetyperefrV   styler   r*   T)reverse)r   
link_attrsrh   r   r   r   r@   r?   rH   r   _archive_refinditergroupstartr   _parse_meta_refresh_urlstripr.   findr   _iter_css_urls_iter_css_importssortlist)rJ   r   r   attribsr?   r   r   rV   match
http_equivr   r   r-   r   urlsr   s                   r"   r   HtmlMixin.iterlinks  s2    " __
))EMM*BiiG-Ch (!vvj1Hz8Q771F( "v#/$+H$<E!5!44 2 '!,!5!5bffY6G!H %A#/$+H$<E!9e[[]CC	 "I )F(!7?A>> ) f}$[[r:@@B
*%kk)R8G3G<E165;;u-GJJLC #1uU!3',,sBS$U!9c77FF;/52	??$- ww;;BGG "0!8 "9 #5;;q>5;;q>B4R4H!8 "3277!;!; [[^U[[^4!;	  IIdI+&*
!444 '+'!N77+;<=4!%dd%3EKKNEKKPQN%S
!7C77 ",I +bs9   BN

BN
&D<N
":N N
5,N!1N
N
8AN
c                 ,   Ub  U R                  X2S9  OU(       a  U R                  5         U R                  5        H  u  pEpgU" UR                  5       5      nX:X  a  M#  Uc  Uc  SUl        OUR
                  U	 M@  Uc6  UR                  SU U-   UR                  U[        U5      -   S -   n	Xl        My  UR                  U5      n
U(       d  [        U
5      [        U5      :X  a  Un	OU
SU U-   X[        U5      -   S -   n	UR                  XY5        M     g)a%  
Rewrite all the links in the document.  For each link
``link_repl_func(link)`` will be called, and the return value
will replace the old link.

Note that links may not be absolute (unless you first called
``make_links_absolute()``), and may be internal (e.g.,
``'#anchor'``).  They can also be values like
``'mailto:email'`` or ``'javascript:expr'``.

If you give ``base_href`` then all links passed to
``link_repl_func()`` will take that into account.

If the ``link_repl_func`` returns None, the attribute or
tag text will be removed completely.
N)r   rF   )	r   r   r   r   r   r   r<   rH   r   )rJ   link_repl_funcr   r   r   r   linkr-   new_linknewcurs              r"   r   HtmlMixin.rewrite_links;  s
   $   $$ % @""$%)^^%5!B%djjl3H> BG		&)~ggdsmh.SY1HHffVns3x3t94"Cds)h.T]^1DDCv#+ &6r$   r,   rd   )html)NTN)TN)rx   ry   rz   r{   r   propertyrW   setterr   r   r   r   r   deleterr   r   r   r   r   r   r   r   r   r   r   r}   r~   r   s   @r"   r   r      s      $ $ ^^% % . . " " R R R R   \\
 
 ]]$ $
 (@19#*->" DH,0+&ZB*X8t ?C $/$ /$r$   r   c                   ,    \ rS rSrSrS\4S jrS rSrg)_MethodFuncim  a  
An object that represents a method on an element as a function;
the function takes either an element or an HTML string.  It
returns whatever the function normally returns, or if the function
works in-place (and so returns None) it returns a serialized form
of the resulting document.
Fc                 d    Xl         X l        [        X0R                   5      R                  U l        g rd   )r[   copygetattrr|   )rJ   r[   r  source_classs       r"   rL   _MethodFunc.__init__u  s"    		|YY7??r$   c                    [        U5      n[        U[        [        45      (       a+  SU;   a  [	        SU R
                  -  5      e[        U40 UD6nOASU;   a  UR                  S5      nOU R                  nU(       a  [        R                  " U5      n[        XR
                  5      nU" U0 UD6nUc  [        XA5      $ U$ )Nr  zQThe keyword 'copy' can only be used with element inputs to %s, not a string input)typer;   r4   r3   r   r[   r   popr  deepcopyr  r7   )rJ   docargskwresult_typemake_a_copymethr6   s           r"   __call___MethodFunc.__call__y  s    3icC<((|gjnjsjssu uS'B'C| ffVn"iimmC(sII&t"r">$[66Mr$   )r|   r  r[   N)	rx   ry   rz   r{   r|   r   rL   r  r}   r,   r$   r"   r  r  m  s     #(i @r$   r  r   F)r  r   r   Tr   r   r   c                       \ rS rSrSrg)HtmlCommenti  r,   Nrx   ry   rz   r{   r}   r,   r$   r"   r"  r"        r$   r"  c                       \ rS rSrSrg)HtmlElementi  r,   Nr#  r,   r$   r"   r&  r&    r$  r$   r&  c                       \ rS rSrSrg)HtmlProcessingInstructioni  r,   Nr#  r,   r$   r"   r(  r(    r$  r$   r(  c                       \ rS rSrSrg)
HtmlEntityi  r,   Nr#  r,   r$   r"   r*  r*    r$  r$   r*  c                   ,    \ rS rSrSr0 rSS jrS rSrg)HtmlElementClassLookupi  a^  A lookup scheme for HTML Element classes.

To create a lookup instance with different Element classes, pass a tag
name mapping of Element classes in the ``classes`` keyword argument and/or
a tag name mapping of Mixin classes in the ``mixins`` keyword argument.
The special key '*' denotes a Mixin class that should be mixed into all
Element classes.
Nc                    [         R                  R                  U 5        Uc  U R                  R	                  5       nU(       a  0 nU Hf  u  pEUS:X  a:  UR                  5        H$  nUR                  U/ 5      R                  U5        M&     ME  UR                  U/ 5      R                  U5        Mh     UR                  5        HB  u  pGUR                  U[        5      n[        Xx/-   5      n	[        UR                  U	0 5      X'   MD     Xl        g )N*)r   CustomElementClassLookuprL   _default_element_classesr  keys
setdefaultrT   itemsrH   r&  tupler  rx   _element_classes)
rJ   rW   mixinsmixersr[   rV   n	mix_basesr  basess
             r"   rL   HtmlElementClassLookup.__init__  s    &&//5?3388:GF%3;$\\^))!R077> , %%dB/66u=  & $*<<>kk$4i%/0 $S\\5" = $2 !(r$   c                     US:X  a.  U R                   R                  UR                  5       [        5      $ US:X  a  [        $ US:X  a  [
        $ US:X  a  [        $ g )NelementcommentPIentity)r5  rH   r   r&  r"  r(  r*  )rJ   	node_typedocument	namespacer[   s        r"   lookupHtmlElementClassLookup.lookup  sV    	!((,,TZZ\;GG)#$,,("r$   )r5  NN)	rx   ry   rz   r{   r|   r0  rL   rD  r}   r,   r$   r"   r,  r,    s      "($
r$   r,  z^\s*<(?:html|!doctype)s   ^\s*<(?:html|!doctype)c                 F   Uc  [         n[        R                  " X40 UD6nUc  [        R                  " S5      eU(       a-  UR	                  S5      c  UR                  S[        S5      5        U(       a,  UR	                  S5      c  UR                  [        S5      5        U$ )NzDocument is emptyr   r   r   )html_parserr   r   ParserErrorr   insertr   rT   )r
  parserensure_head_bodyr  rV   s        r"   r   r     s    ~T0R0E}! 	!EJJv.6Q(EJJv.6WV_%Lr$   c                 
   Uc  [         n[        U [        5      (       a  [        U 5      (       d  SU -   S-   n O[	        U 5      (       d  SU -  n [        U 4X2S.UD6n[        UR                  5      S:X  d   eU Vs/ s H   n[        UR                  5      S:X  d  M  UPM"     nn[        U5      S:X  d   SU< S	U < 35       eUS
   n/ n	U(       aS  UR                  (       aB  UR                  R                  5       (       a#  [        R                  " SUR                  -  5      eUR                  (       a:  UR                  R                  5       (       a  U	R                  UR                  5        U	R                  U5        U	$ s  snf )a:  Parses several HTML elements, returning a list of elements.

The first item in the list may be a string.
If no_leading_text is true, then it will be an error if there is
leading text, and it will always be a list of only elements.

base_url will set the document's base_url attribute
(and the tree's docinfo.URL).
s   <html><body>s   </body></html>z<html><body>%s</body></html>rK  r   r
  r   r   ztoo many bodies: z in r   zThere is leading text: %r)rH  r;   r3   _looks_like_full_html_bytes_looks_like_full_html_unicoder   r@   r?   r<   r   r   r   rI  rT   extend)
r
  no_leading_textr   rK  r  r  ebodiesr   elementss
             r"   r   r     s>    ~$*400#d*%&D -T221D8D
d
K6
K
KC>V###7Aaee 6aF7v;!KVTJK!9DH499):):'$))35 	5yyTYY__&&		"OOD O 8s   :F F c                    Uc  [         n[        U5      n[        U 4X5(       + US.UD6nU(       aa  [        U[        5      (       d  Sn[        U5      nU(       a6  [        US   [        5      (       a  US   Ul        US	 UR                  U5        U$ U(       d  [        R                  " S5      e[        U5      S:  aB  [        R                  " SSR                  U Vs/ s H  n[        U5      PM     sn5      -  5      eUS   n	U	R                  (       aB  U	R                  R                  5       (       a#  [        R                  " S	U	R                  -  5      eSU	l        U	$ s  snf )
a  
Parses a single HTML element; it is an error if there is more than
one element, or if anything but whitespace precedes or follows the
element.

If ``create_parent`` is true (or is a tag name) then a parent node
will be created to encapsulate the HTML in a single element.  In this
case, leading or trailing text is also allowed, as are multiple elements
as result of the parsing.

Passing a ``base_url`` will set the document's ``base_url`` attribute
(and the tree's docinfo.URL).
N)rK  rR  r   divr   zNo elements foundr   zMultiple elements found (%s), zElement followed by text: %r)rH  boolr   r;   r4   r   r   rQ  r   rI  r<   rU   _element_namer   r   )
r
  create_parentr   rK  r  accept_leading_textrU  new_rootrS  r   s
             r"   r   r     s@    ~}-#!-D!!H ---!M=)(1+s++ (QKOOH% 344
8}q*ii8<8aq)8<=>? 	? 
!B	ww277==??*RWW46 	6BGI =s   E c                    Uc  [         n[        U [        5      (       a  [        U 5      nO[	        U 5      n[        U 4X!S.UD6nU(       a  U$ UR                  S5      nU(       d  UR                  S[        -  5      nU(       a  US   n[        U5      S:  a  USS  H  nUR                  (       ae  [        U5      (       a.  US   R                  =(       d    SUR                  -   US   l
        O'UR                  =(       d    SUR                  -   Ul	        UR                  U5        UR                  5         M     OSnUR                  S	5      n	U	(       d  UR                  S
[        -  5      n	U	(       aC  U	S   n
[        U	5      S:  a-  U	SS  H$  nU
R                  U5        UR                  5         M&     U$ Uc  U$ [        U5      S:X  ak  UR                  (       a  UR                  R                  5       (       d;  US   R                  (       a"  US   R                  R                  5       (       d  US   $ [        U5      (       a	  SUl        U$ SUl        U$ )z
Parse the html, returning a single element/document.

This tries to minimally parse the chunk of text, without knowing if it
is a fragment or a document.

base_url will set the document's base_url attribute (and the tree's docinfo.URL)
NrN  r   z{%s}bodyr   r   r*   rF   r   z{%s}headrW  span)rH  r;   r3   rO  rP  r   findallr=   r<   r   r   rQ  r   r   _contains_block_level_tagr?   )r
  r   rK  r  is_full_htmlr  rT  r   
other_bodyheadsr   
other_heads               r"   r   r   C  s    ~$2484T:
d
K6
K
KC
[[ FZ/9:ayv;? %QRj
??4yy)-b)<"
(OR%)YY_"
$G	J' $$& ) KKEJ89Qxu:>#ABi
J'$$& ( 
|
D	Q		1B1Bbd2hmm&9&9&;&; Aw !&& K Kr$   c                 F    Uc  [         n[        R                  " X4SU0UD6$ )a%  
Parse a filename, URL, or file-like object into an HTML document
tree.  Note: this returns a tree, not an element.  Use
``parse(...).getroot()`` to get the document root.

You can override the base URL with the ``base_url`` keyword.  This
is most useful when parsing from a file-like object.
r   )rH  r   r   )filename_or_urlrK  r   r  s       r"   r   r     s'     ~;;HHRHHr$   c                     U R                  [        R                  5       H,  n [        U R                  5      [
        R                  ;   d  M,    g   gNTF)rh   r   r   r@   r?   r   
block_tagsr   s    r"   ra  ra    s7     ggemm$=DOO+ % r$   c                     [        U [        R                  5      (       a  g[        U [        5      (       a  g[	        U R
                  5      $ )Nr>  string)r;   r   CommentBaser4   r@   r?   rk  s    r"   rZ  rZ    s6    "e''((	B		RVV}r$   c                       \ rS rSrSr\S 5       r\S 5       r\R                  S 5       rS r	S r
\S 5       r\R                  S	 5       r\R                  S
 5       r\S 5       r\R                  S 5       rSrg)FormElementi  z
Represents a <form> element.
c                     [        U 5      $ )zw
Returns an accessor for all the input elements in the form.

See `InputGetter` for more information about the object.
)InputGetterri   s    r"   inputsFormElement.inputs  s     4  r$   c                 ,    [        U R                  5      $ )z
Dictionary-like object that represents all the fields in this
form.  You can set values in this dictionary to effect the
form.
)
FieldsDictrs  ri   s    r"   fieldsFormElement.fields  s     $++&&r$   c                     U R                   nUR                  5       nUR                  5        H  u  pAXC;   a  UR                  U5        XU'   M!     U H  nUc  M  S X$'   M     g rd   )rw  r1  r3  r`   )rJ   rV   rw  	prev_keysr   s        r"   rw  rx    s`    KKM	++-JC  %3K ( C{ FK r$   c                 d   U R                  S5      (       a  U R                  S5      $ U R                  S5      (       a  SU R                  S5      -   $ U R                  R                  n[        U" S5      5      nU(       d  [        U" S[        -  5      5      n[        UR                  U 5      5      $ )Nr[   r   #formz{%s}form)rH   r   rh   r   r=   r4   r   )rJ   	iter_tagsr   s      r"   _nameFormElement._name  s    88F88F##XXd^^$''IINN	Yv&':#?@AE5;;t$%%r$   c                    / nU R                    GH:  nUR                  nU(       a  SUR                  ;   a  M)  [        UR                  5      nUS:X  a  UR                  X2R                  45        Mb  US:X  a]  UR                  nUR                  (       a  U H  nUR                  X645        M     M  Ub  UR                  X2R                  45        M  M  US:X  d
   SU-  5       eUR                  (       a  UR                  (       d  M  UR                  S;   a  GM  UR                  nUc  GM  UR                  X2R                  45        GM=     U$ )zt
Return a list of tuples of the field values for the form.
This is suitable to be passed to ``urllib.urlencode()``.
disabledtextareaselectinputzUnexpected tag: %r)submitimageresetfile)rs  r[   r   r@   r?   rT   rV   multiple	checkablecheckedr  )rJ   resultsr   r[   r?   rV   vs          r"   form_valuesFormElement.form_values  s   
 ++B77D:2-Cj hh/0;;"y1 #&NND((#34 ' g~ /(2-/~<<

77BB$NND((#34/ 0 r$   c                 j    U R                   nU R                  S5      nU(       a  Ub  [        X5      $ U$ )z*
Get/set the form's ``action`` attribute.
action)r   rH   r   )rJ   r   r  s      r"   r  FormElement.action  s3    
 ==(#*8,,Mr$   c                 (    U R                  SU5        g Nr  r   rJ   rV   s     r"   r  r    s    5!r$   c                 0    U R                   nSU;   a  US	 g g r  r   rJ   r   s     r"   r  r    s     vx  r$   c                 B    U R                  SS5      R                  5       $ )z\
Get/set the form's method.  Always returns a capitalized
string, and defaults to ``'GET'``
methodGET)rH   upperri   s    r"   r  FormElement.method  s     xx%(..00r$   c                 D    U R                  SUR                  5       5        g )Nr  )r   r  r  s     r"   r  r    s    5;;=)r$   r,   N)rx   ry   rz   r{   r|   r  rs  rw  r  r  r  r  r  r  r}   r,   r$   r"   rp  rp    s     ! ! ' ' ]] 	&@ 	 	 ]]" " ^^! !
 1 1 ]]* *r$   rp  r}  c                     U R                  5       nU(       a2  [        US5      (       a  UR                  5       nUR                  U5        Uc  [        nU R
                  (       a  U R
                  nOU R                  nU" U R                  XC5      $ )a  
Helper function to submit a form.  Returns a file-like object, as from
``urllib.urlopen()``.  This object also has a ``.geturl()`` function,
which shows the URL if there were any redirects.

You can use this like::

    form = doc.forms[0]
    form.inputs['foo'].value = 'bar' # etc
    response = form.submit()
    doc = parse(response)
    doc.make_links_absolute(response.geturl())

To change the HTTP requester, pass a function as ``open_http`` keyword
argument that opens the URL for you.  The function must have the following
signature::

    open_http(method, URL, values)

The action is one of 'GET' or 'POST', the URL is the target URL as a
string, and the values are a sequence of ``(name, value)`` tuples with the
form data.
r3  )r  hasattrr3  rQ  open_http_urllibr  r   r  )r}  extra_values	open_httprp   r   s        r"   r
   r
   "  sq    0 F<))'--/Ll#$	{{kkmmT[[#..r$   c                 $   U(       d  [        S5      e SSKJnJn  U S:X  a  SU;   a  US-  nOUS-  nX" U5      -  nS nO.U" U5      n[        U[        5      (       d  UR                  S	5      nU" X5      $ ! [         a    SSKJn  SSKJn   Nrf = f)
Nzcannot submit, no URL providedr   )	urlencodeurlopen)r  )r  r  ?&ASCII)
rS   urllibr  r  ImportErrorurllib.requesturllib.parser;   r3   encode)r  r   rp   r  r  r   s         r"   r  r  H  s    9::+- #:3JC3JCy   $&&;;w'D3  +**+s   A6 6BBc                   J    \ rS rSrS rS rS rS rS rS r	S r
S	 rS
 rSrg)rv  i_  c                     Xl         g rd   rs  )rJ   rs  s     r"   rL   FieldsDict.__init__a      r$   c                 4    U R                   U   R                  $ rd   rs  rV   rJ   items     r"   __getitem__FieldsDict.__getitem__c  s    {{4 &&&r$   c                 *    X R                   U   l        g rd   r  )rJ   r  rV   s      r"   __setitem__FieldsDict.__setitem__e  s    "'Dr$   c                     [        S5      e)Nz'You cannot remove keys from ElementDict)r   r  s     r"   __delitem__FieldsDict.__delitem__g  s    57 	7r$   c                 6    U R                   R                  5       $ rd   )rs  r1  ri   s    r"   r1  FieldsDict.keysj  s    {{!!r$   c                     XR                   ;   $ rd   r  r  s     r"   re   FieldsDict.__contains__l  s    {{""r$   c                 H    [        U R                  R                  5       5      $ rd   )rh   rs  r1  ri   s    r"   rj   FieldsDict.__iter__n  s    DKK$$&''r$   c                 ,    [        U R                  5      $ rd   )r<   rs  ri   s    r"   rm   FieldsDict.__len__p  s    4;;r$   c                     SU R                   R                  < SU R                  R                  R	                  5       < S3$ N<z
 for form >)ra   rx   rs  r}  r  ri   s    r"   __repr__FieldsDict.__repr__s  s/    NN##KK""$& 	&r$   r  N)rx   ry   rz   r{   rL   r  r  r  r1  re   rj   rm   r  r}   r,   r$   r"   rv  rv  _  s/    '(7"#( &r$   rv  c                   H    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rSrg)rr  iy  a/  
An accessor that represents all the input fields in a form.

You can get fields by name from this, with
``form.inputs['field_name']``.  If there are a set of checkboxes
with the same name, they are returned as a list (a `CheckboxGroup`
which also allows value setting).  Radio inputs are handled
similarly.  Use ``.keys()`` and ``.items()`` to process all fields
in this way.

You can also iterate over this to get all input elements.  This
won't return the same thing as if you get all the names, as
checkboxes and radio elements are returned individually.
c                     Xl         g rd   r}  )rJ   r}  s     r"   rL   InputGetter.__init__  s    	r$   c                 p    SU R                   R                  < SU R                  R                  5       < S3$ r  )ra   rx   r}  r  ri   s    r"   r  InputGetter.__repr__  s'    NN##IIOO 	r$   c                 N   U  Vs/ s H  o"R                   U:X  d  M  UPM     nnU(       d  [        SU-  5      eUS   R                  S5      nUS:X  a"  [        U5      S:  a  [	        U5      nXl         U$ US:X  a"  [        U5      S:  a  [        U5      nXl         U$ US   $ s  snf )Nz!No input element with the name %rr   r  radior   checkbox)r[   r   rH   r<   
RadioGroupCheckboxGroup)rJ   r[   fieldrw  
input_typer   s         r"   r  InputGetter.__getitem__  s    %)@TEZZ4-?%T@>EFFAY]]6*
 S[1_v&EJL:%#f+/!&)EJL !9 As
   B"B"c                 :    U  H  nUR                   U:X  d  M    g   gri  )r[   )rJ   r[   r  s      r"   re   InputGetter.__contains__  s     EzzT!  r$   c                     / nS1nU  H8  nUR                   nXB;  d  M  UR                  U5        UR                  U5        M:     U$ )z`
Returns all unique field names, in document order.

:return: A list of all unique field names.
N)r[   rT   rX   )rJ   namesseenr   r[   s        r"   r1  InputGetter.keys  sG     vB77DT"	 
 r$   c                     / n[        5       nU  H<  nUR                  nXB;  d  M  UR                  U5        UR                  X@U   45        M>     U$ )zi
Returns all fields with their names, similar to dict.items().

:return: A list of (name, field) tuples.
)r   r[   rX   rT   )rJ   r3  r  r   r[   s        r"   r3  InputGetter.items  sN     uB77DdJ/0	 
 r$   c                 <    U R                   R                  SSS5      $ )Nr  r  r  )r}  rh   ri   s    r"   rj   InputGetter.__iter__  s    yy~~h<<r$   c                 &    [        S U  5       5      $ )Nc              3   &   #    U  H  nS v   M	     g7f)r   Nr,   ).0_s     r"   	<genexpr>&InputGetter.__len__.<locals>.<genexpr>  s     #d1ds   )sumri   s    r"   rm   InputGetter.__len__  s    #d###r$   r  N)rx   ry   rz   r{   r|   rL   r  r  re   r1  r3  rj   rm   r}   r,   r$   r"   rr  rr  y  s/    $=$r$   rr  c                   v    \ rS rSrSr\S 5       r\R                  S 5       r\R                  S 5       rS r	Sr
g)	
InputMixini  z=
Mix-in for all input elements (input, select, and textarea)
c                 $    U R                  S5      $ )z!
Get/set the name of the element
r[   rH   ri   s    r"   r[   InputMixin.name  s    
 xxr$   c                 (    U R                  SU5        g Nr[   r  r  s     r"   r[   r        r$   c                 0    U R                   nSU;   a  US	 g g r  r  r  s     r"   r[   r    s    Vv r$   c                     [        U SS 5      nU(       a  SU-  nOSnSU R                  R                  [        U 5      U R                  U4-  $ )Nr  z type=%rrF   z<%s %x name=%r%s>)r  ra   rx   r   r[   )rJ   	type_names     r"   r  InputMixin.__repr__  sR    D&$/	"Y.II"NN##RXtyy)&E E 	Er$   r,   N)rx   ry   rz   r{   r|   r  r[   r  r  r  r}   r,   r$   r"   r  r    sQ         
[[    
\\ 
Er$   r  c                   p    \ rS rSrSr\S 5       r\R                  S 5       r\R                  S 5       rSr	g)TextareaElementi  zd
``<textarea>`` element.  You can get the name with ``.name`` and
get/set the value with ``.value``
c                     U R                   =(       d    SnU R                  R                  S[        -  5      (       a  SnOSnU  H  nU[        R
                  " X2SS9-  nM     U$ )z;
Get/set the value (which is the contents of this element)
rF   {%s}xmlr
  r1   r  r0   )r   r?   
startswithr=   r   r   )rJ   r   serialisation_methodr   s       r"   rV   TextareaElement.value  sd    
 ))/r88v788#( #) Bu~~)E EG  r$   c                     U S S 2	 Xl         g rd   r   r  s     r"   rV   r    s    G	r$   c                     SU l         U S S 2	 g )NrF   r  ri   s    r"   rV   r    s    	Gr$   r  N)
rx   ry   rz   r{   r|   r  rV   r  r  r}   r,   r$   r"   r  r    sK       \\  ]] r$   r  r  c                       \ rS rSrSr\S 5       r\R                  S 5       r\R                  S 5       r\S 5       r	\S 5       r
\
R                  S 5       r
S	rg
)SelectElementi  ab  
``<select>`` element.  You can get the name with ``.name``.

``.value`` will be the value of the selected option, unless this
is a multi-select element (``<select multiple>``), in which case
it will be a set-like object.  In either case ``.value_options``
gives the possible values.

The boolean attribute ``.multiple`` shows if this is a
multi-select.
c                 b   U R                   (       a  [        U 5      $ [        U 5      n [        S [	        U5       5       5      nUR                  S5      nUc#  UR                  =(       d    SR                  5       nU$ ! [
         a'     [        S U 5       5      n NX! [
         a      gf = ff = f)z
Get/set the value of this select (the selected option).

If this is a multi-select, this is a set-like object that
represents all the selected options.
c              3   L   #    U  H  oR                  S 5      c  M  Uv   M     g7f)selectedNr  r  r   s     r"   r  &SelectElement.value.<locals>.<genexpr>-  s     "d0A"VVJEW220A   $	$c              3   L   #    U  H  oR                  S 5      b  M  Uv   M     g7f)r  Nr  r  s     r"   r  r  0  s     &ZGbvvj?QrrGr  NrV   rF   )	r  MultipleSelectOptions_options_xpathnextreversedStopIterationrH   r   r   )rJ   optionsselected_optionrV   s       r"   rV   SelectElement.value   s     ==(.. &	""d0A"ddO  ##G,=$))/R668E  	"&&ZG&Z"Z  	s)   A= =
B.B
B*&B.)B**B.c                    U R                   (       aN  [        U[        5      (       a  [        S5      eU R                  nUR                  5         UR                  U5        g S nUb`  [        U 5       HC  nUR                  S5      nUc#  UR                  =(       d    SR                  5       nXQ:X  d  MA  Un  O   [        SU-  5      e[        U 5       H"  nSUR                  ;   d  M  UR                  S	 M$     Ub  UR                  SS5        g g )NzYou must pass in a sequencerV   rF   z'There is no option with the value of %rr  )r  r;   r4   r   rV   clearrr   r  rH   r   r   rS   r   r   )rJ   rV   rp   checked_optionr   	opt_values         r"   rV   r  8  s    ==%%% =>>ZZFLLNMM% $T*FF7O	$!#B 5 5 7I%%'N + !=EG G &BRYY&IIj) ' %z2. &r$   c                 j    U R                   (       a  U R                  R                  5         g S U l        g rd   )r  rV   r  ri   s    r"   rV   r  S  s"     ==JJDJr$   c                     / n[        U 5       HK  nUR                  S5      nUc#  UR                  =(       d    SR                  5       nUR	                  U5        MM     U$ )zi
All the possible values this select can have (the ``value``
attribute of all the ``<option>`` elements.
rV   rF   )r  rH   r   r   rT   )rJ   r  r   rV   s       r"   value_optionsSelectElement.value_options[  sS      &BFF7OE}B--/NN5!	 '
 r$   c                      SU R                   ;   $ )zG
Boolean attribute: is there a ``multiple`` attribute on this element.
r  r  ri   s    r"   r  SelectElement.multiplei  s    
 T[[((r$   c                 t    U(       a  U R                  SS5        g SU R                  ;   a  U R                  S	 g g )Nr  rF   )r   r   r  s     r"   r  r"  p  s0    HHZ$4;;&J' 'r$   rV   N)rx   ry   rz   r{   r|   r  rV   r  r  r  r  r}   r,   r$   r"   r	  r	    s    
  . \\/ /4 ]]    ) ) __( (r$   r	  r  c                   F    \ rS rSrSrS r\S 5       rS rS r	S r
S rS	rg
)r  i{  z
Represents all the selected options in a ``<select multiple>`` element.

You can add to this set-like option to select an option, or remove
to unselect the option.
c                     Xl         g rd   r  )rJ   r  s     r"   rL   MultipleSelectOptions.__init__  r  r$   c                 >    [        [        U R                  5      5      $ )z,
Iterator of all the ``<option>`` elements.
)rh   r  r  ri   s    r"   r  MultipleSelectOptions.options  s    
 N4;;/00r$   c              #      #    U R                    HP  nSUR                  ;   d  M  UR                  S5      nUc#  UR                  =(       d    SR	                  5       nUv   MR     g 7f)Nr  rV   rF   )r  r   rH   r   r   )rJ   optionr  s      r"   rj   MultipleSelectOptions.__iter__  sO     llFV]]*"JJw/	$!'!2 9 9 ;I #s   A$A A$c                     U R                    HS  nUR                  S5      nUc#  UR                  =(       d    SR                  5       nX1:X  d  MA  UR	                  SS5          g    [        SU-  5      e)NrV   rF   r  z$There is no option with the value %r)r  rH   r   r   r   rS   rJ   r  r,  r  s       r"   rX   MultipleSelectOptions.add  si    llF

7+I #[[.B557	 

:r* # 6=? ?r$   c                    U R                    Hm  nUR                  S5      nUc#  UR                  =(       d    SR                  5       nX1:X  d  MA  SUR                  ;   a  UR                  S	 O[        SU-  5      e  g    [        SU-  5      e)NrV   rF   r  z'The option %r is not currently selectedz%There is not option with the value %r)r  rH   r   r   r   rS   r/  s       r"   r`   MultipleSelectOptions.remove  s    llF

7+I #[[.B557	 .j1$ADHJ J # 7$>@ @r$   c                     SU R                   R                  < SSR                  U  Vs/ s H  n[        U5      PM     sn5      < SU R                  R
                  < S3$ s  snf )Nr   {rX  z} for select name=r  )ra   rx   rU   reprr  r[   rJ   r  s     r"   r  MultipleSelectOptions.__repr__  sH    NN##II-1tAw-.KK 	-   A!r'  N)rx   ry   rz   r{   r|   rL   r  r  rj   rX   r`   r  r}   r,   r$   r"   r  r  {  s5     1 1 
?@ r$   r  c                       \ rS rSrSr\S 5       r\R                  S 5       r\R                  S 5       r\S 5       r	S r
Srg	)
r  i  z
This object represents several ``<input type=radio>`` elements
that have the same name.

You can use this like a list, but also use the property
``.value`` to check/uncheck inputs.  Also you can use
``.value_options`` to get the possible values.
c                 \    U  H&  nSUR                   ;   d  M  UR                  S5      s  $    g)z[
Get/set the value, which checks the radio with that value (and
unchecks any other value).
r  rV   N)r   rH   rJ   r   s     r"   rV   RadioGroup.value  s-     BBII%vvg&  r$   c                     S nUb0  U  H  nUR                  S5      U:X  d  M  Un  O   [        SU-  5      eU  H"  nSUR                  ;   d  M  UR                  S	 M$     Ub  UR                  SS5        g g )NrV   z)There is no radio input with the value %rr  rF   )rH   rS   r   r   )rJ   rV   r  r   s       r"   rV   r<    s    66'?e+%'N 
 !!Lu!TUUBBII%IIi(  %y"- &r$   c                     S U l         g rd   r$  ri   s    r"   rV   r<    s	    
r$   c                 N    U  Vs/ s H  oR                  S5      PM     sn$ s  snf z,
Returns a list of all the possible values.
rV   r  r;  s     r"   r  RadioGroup.value_options  "    
 +//$Bw$///   "c                 d    U R                   R                  < S[        R                  U 5      < S3$ N()ra   rx   r   r  ri   s    r"   r  RadioGroup.__repr__  s%    NN##MM$! 	!r$   r$  Nrx   ry   rz   r{   r|   r  rV   r  r  r  r  r}   r,   r$   r"   r  r    sd       \\. . ]]  0 0!r$   r  c                       \ rS rSrSr\S 5       r\R                  S 5       r\R                  S 5       r\S 5       r	S r
Srg	)
r  i  a7  
Represents a group of checkboxes (``<input type=checkbox>``) that
have the same name.

In addition to using this like a list, the ``.value`` attribute
returns a set-like object that you can add to or remove from to
check and uncheck checkboxes.  You can also use ``.value_options``
to get the possible values.
c                     [        U 5      $ )zs
Return a set-like object that can be modified to check or
uncheck individual checkboxes according to their value.
)CheckboxValuesri   s    r"   rV   CheckboxGroup.value  s     d##r$   c                     U R                   nUR                  5         [        US5      (       d!  [        SU S   R                  < SU< S35      eUR                  U5        g )Nrj   zA CheckboxGroup (name=r   z!) must be set to a sequence (not rG  )rV   r  r  rS   r[   rr   )rJ   rV   rp   s      r"   rV   rN    sN    uj))7<<() ) 	er$   c                 8    U R                   R                  5         g rd   )rV   r  ri   s    r"   rV   rN  	  s    

r$   c                 N    U  Vs/ s H  oR                  S5      PM     sn$ s  snf r@  r  r;  s     r"   r  CheckboxGroup.value_options  rB  rC  c                 d    U R                   R                  < S[        R                  U 5      < S3$ rE  rH  ri   s    r"   r  CheckboxGroup.__repr__  s$    NN##T]]4%8: 	:r$   r,   NrJ  r,   r$   r"   r  r    sd     $ $ \\  ]]  0 0:r$   r  c                   6    \ rS rSrSrS rS rS rS rS r	Sr
g	)
rM  i  z^
Represents the values of the checked checkboxes in a group of
checkboxes with the same name.
c                     Xl         g rd   r   )rJ   r   s     r"   rL   CheckboxValues.__init__  s    
r$   c                     [        U R                   Vs/ s H&  nSUR                  ;   d  M  UR                  S5      PM(     sn5      $ s  snf )Nr  rV   )rh   r   r   rH   r;  s     r"   rj   CheckboxValues.__iter__"  sI    jj' BII% BFF7O ' ( 	( 's
   AAc                     U R                    H,  nUR                  S5      U:X  d  M  UR                  SS5          g    [        SU-  5      e)NrV   r  rF   No checkbox with value %r)r   rH   r   r   rJ   rV   r   s      r"   rX   CheckboxValues.add(  sD    **Bvvg%'y"% 
 6>??r$   c                     U R                    HF  nUR                  S5      U:X  d  M  SUR                  ;   a  UR                  S	 O[        SU-  5      e  g    [        SU-  5      e)NrV   r  z0The checkbox with value %r was already uncheckedr\  )r   rH   r   r   r]  s      r"   r`   CheckboxValues.remove0  si    **Bvvg%'		)		),"JURT T  +e35 5r$   c                     SU R                   R                  < SSR                  U  Vs/ s H  n[        U5      PM     sn5      < SU R                  R
                  < S3$ s  snf )Nr  r4  rX  z} for checkboxes name=r  )ra   rx   rU   r5  r   r[   r6  s     r"   r  CheckboxValues.__repr__=  sF    NN##II-1tAw-.JJOO 	-r8  rW  N)rx   ry   rz   r{   r|   rL   rj   rX   r`   r  r}   r,   r$   r"   rM  rM    s!    
(@5r$   rM  c                       \ rS rSrSr\S 5       r\R                  S 5       r\R                  S 5       r\S 5       r	\	R                  S 5       r	\S 5       r
\S	 5       r\R                  S
 5       rSrg)InputElementiD  a:  
Represents an ``<input>`` element.

You can get the type with ``.type`` (which is lower-cased and
defaults to ``'text'``).

Also you can get and set the value with ``.value``

Checkboxes and radios have the attribute ``input.checkable ==
True`` (for all others it is false) and a boolean attribute
``.checked``.

c                     U R                   (       a,  U R                  (       a  U R                  S5      =(       d    S$ gU R                  S5      $ )z
Get/set the value of this element, using the ``value`` attribute.

Also, if this is a checkbox and it has no value, this defaults
to ``'on'``.  If it is a checkbox or radio that is not
checked, this returns None.
rV   onN)r  r  rH   ri   s    r"   rV   InputElement.valueT  s8     >>||xx(0D0xx  r$   c                     U R                   (       a?  U(       d  SU l        g SU l        [        U[        5      (       a  U R	                  SU5        g g U R	                  SU5        g )NFTrV   )r  r  r;   r4   r   r  s     r"   rV   rg  d  sJ    >>$#eS))HHWe, * HHWe$r$   c                 r    U R                   (       a  SU l        g SU R                  ;   a  U R                  S	 g g )NFrV   )r  r  r   ri   s    r"   rV   rg  p  s-    >> DL$++%KK( &r$   c                 B    U R                  SS5      R                  5       $ )z=
Return the type of this element (using the type attribute).
r  r   )rH   r   ri   s    r"   r  InputElement.typex  s    
 xx'--//r$   c                 (    U R                  SU5        g )Nr  r  r  s     r"   r  rk    r  r$   c                      U R                   S;   $ )z'
Boolean: can this element be checked?
)r  r  )r  ri   s    r"   r  InputElement.checkable  s    
 yy111r$   c                 X    U R                   (       d  [        S5      eSU R                  ;   $ )zz
Boolean attribute to get/set the presence of the ``checked``
attribute.

You can only use this on checkable input types.
Not a checkable input typer  )r  AttributeErrorr   ri   s    r"   r  InputElement.checked  s&     ~~ !=>>DKK''r$   c                     U R                   (       d  [        S5      eU(       a  U R                  SS5        g U R                  nSU;   a  US	 g g )Nrp  r  rF   )r  rq  r   r   )rJ   rV   r   s      r"   r  rr    sD    ~~ !=>>HHY#[[FF"9% #r$   )r  N)rx   ry   rz   r{   r|   r  rV   r  r  r  r  r  r}   r,   r$   r"   rd  rd  D  s     ! ! \\	% 	% ]]) ) 0 0 
[[    2 2 	( 	( ^^& &r$   rd  r  c                   p    \ rS rSrSr\S 5       r\R                  S 5       r\R                  S 5       rSr	g)LabelElementi  z
Represents a ``<label>`` element.

Label elements are linked to other elements with their ``for``
attribute.  You can access this element with ``label.for_element``.
c                 j    U R                  S5      nU(       d  gU R                  R                  U5      $ )zN
Get/set the element this label points to.  Return None if it
can't be found.
r   N)rH   r   r   )rJ   r   s     r"   for_elementLabelElement.for_element  s,     XXe_yy**2..r$   c                 t    UR                  S5      nU(       d  [        SU-  5      eU R                  SU5        g )Nr   zElement %r has no id attributer   )rH   r   r   )rJ   otherr   s      r"   rw  rx    s5    YYt_058: :r$   c                 0    U R                   nSU;   a  US	 g g )Nr   r  r  s     r"   rw  rx    s    6>t r$   r,   N)
rx   ry   rz   r{   r|   r  rw  r  r  r}   r,   r$   r"   ru  ru    sO     / /    r$   ru  r   c                      U R                  5       n S[        -  nU R                  [        R
                  5       H#  nUR                  nUS   S:w  d  M  X-   Ul        M%     g! [         a     N\f = f)zQConvert all tags in an HTML tree to XHTML by moving them to the
XHTML namespace.
r  r   r9   N)getrootrq  r=   rh   r   r   r?   )r
  prefixr   r?   s       r"   html_to_xhtmlr    sf    ||~ o%Fii&ffq6S=\BF '  s   A" "
A/.A/c                      U R                  5       n S[        -  n[        U5      nU R	                  US-   5       H  nUR
                  US Ul        M     g! [         a     NPf = f)zMConvert all tags in an XHTML tree to HTML by removing their
XHTML namespace.
r  r.  N)r}  rq  r=   r<   rh   r?   )xhtmlr~  
prefix_lenr   s       r"   xhtml_to_htmlr    sd     o%FVJjj#&
$ '	  s   A 
A#"A#z%<meta http-equiv="Content-Type"[^>]*>s%   <meta http-equiv="Content-Type"[^>]*>c           	          [         R                  " XUX5US9nUS:X  a6  U(       d/  [        U[        5      (       a  [	        SU5      nU$ [        SU5      nU$ )ap	  Return an HTML string representation of the document.

Note: if include_meta_content_type is true this will create a
``<meta http-equiv="Content-Type" ...>`` tag in the head;
regardless of the value of include_meta_content_type any existing
``<meta http-equiv="Content-Type" ...>`` tag will be removed

The ``encoding`` argument controls the output encoding (defaults to
ASCII, with &#...; character references for any characters outside
of ASCII).  Note that you can pass the name ``'unicode'`` as
``encoding`` argument to serialise to a Unicode string.

The ``method`` argument defines the output method.  It defaults to
'html', but can also be 'xml' for xhtml output, or 'text' to
serialise to plain text without markup.

To leave out the tail text of the top-level element that is being
serialised, pass ``with_tail=False``.

The ``doctype`` option allows passing in a plain string that will
be serialised before the XML tree.  Note that passing in non
well-formed content here will make the XML output non well-formed.
Also, an existing doctype in the document tree will not be removed
when serialising an ElementTree instance.

Example::

    >>> from lxml import html
    >>> root = html.fragment_fromstring('<p>Hello<br>world!</p>')

    >>> html.tostring(root)
    b'<p>Hello<br>world!</p>'
    >>> html.tostring(root, method='html')
    b'<p>Hello<br>world!</p>'

    >>> html.tostring(root, method='xml')
    b'<p>Hello<br/>world!</p>'

    >>> html.tostring(root, method='text')
    b'Helloworld!'

    >>> html.tostring(root, method='text', encoding='unicode')
    u'Helloworld!'

    >>> root = html.fragment_fromstring('<div><p>Hello<br>world!</p>TAIL</div>')
    >>> html.tostring(root[0], method='text', encoding='unicode')
    u'Helloworld!TAIL'

    >>> html.tostring(root[0], method='text', encoding='unicode', with_tail=False)
    u'Helloworld!'

    >>> doc = html.document_fromstring('<p>Hello<br>world!</p>')
    >>> html.tostring(doc, method='html', encoding='unicode')
    u'<html><body><p>Hello<br>world!</p></body></html>'

    >>> print(html.tostring(doc, method='html', encoding='unicode',
    ...          doctype='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"'
    ...                  ' "http://www.w3.org/TR/html4/strict.dtd">'))
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html><body><p>Hello<br>world!</p></body></html>
)r  pretty_printr0   	with_taildoctyper
  rF   r$   )r   r   r;   r4   __str_replace_meta_content_type!__bytes_replace_meta_content_type)r  r  include_meta_content_typer0   r  r  r  r
  s           r"   r   r     s]    ~ >>#<#+")+D  9dC  22t<D K 5S$?DKr$   c                    SSK nSSKnSSKn[        U [        R
                  5      (       d  [        R                  " U 5      n UR                  SS9u  pVUR                  US5      n U R                  USU=(       d    U R                  R                  =(       d    SS9  UR                  5         S	UR                  UR                  R                  S
5      -   n[!        U5        UR#                  U5        g! UR                  5         f = f)z
Open the HTML document in a web browser, saving it to a temporary
file to open it.  Note that this does not delete the file after
use.  This is mainly meant for debugging.
r   Nz.html)suffixwbr
  zUTF-8r  zfile:///)os
webbrowsertempfiler;   r   _ElementTreeElementTreemkstempfdopenwriter   r0   closereplacepathsepprintopen)	r  r0   r  r  r  handlefnfr   s	            r"   r	   r	   ?  s     c5--..$!!!1JF
		&$A		!FX-X9M9M-XQX	Y 	
	
bjjc2
2C	#JOOC 	
	s   &7C3 3Dc                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )
HTMLParseriZ  zGAn HTML parser that is configured to return lxml.html Element
objects.
c                 X   > [         TU ]  " S0 UD6  U R                  [        5       5        g Nr,   r_   rL   set_element_class_lookupr,  rJ   kwargsra   s     r"   rL   HTMLParser.__init__^  %    "6"%%&<&>?r$   r,   rx   ry   rz   r{   r|   rL   r}   r~   r   s   @r"   r  r  Z  s    @ @r$   r  c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )XHTMLParseric  a   An XML parser that is configured to return lxml.html Element
objects.

Note that this parser is not really XHTML aware unless you let it
load a DTD that declares the HTML entities.  To do this, make sure
you have the XHTML DTDs installed in your catalogs, and create the
parser like this::

    >>> parser = XHTMLParser(load_dtd=True)

If you additionally want to validate the document, use this::

    >>> parser = XHTMLParser(dtd_validation=True)

For catalog support, see http://www.xmlsoft.org/catalog.html.
c                 X   > [         TU ]  " S0 UD6  U R                  [        5       5        g r  r  r  s     r"   rL   XHTMLParser.__init__t  r  r$   r,   r  r   s   @r"   r  r  c  s     @ @r$   r  c                  2    [         R                  " U 0 UD6nU$ )zGCreate a new HTML Element.

This can also be used for XHTML documents.
)rH  makeelement)r  r  r  s      r"   r   r   y  s    
 	,,AHr$   )NF)FNNrF  )FFNr
  TNrd   )_r|   __all__r  r   collections.abcr   r   	functoolsr   r  r   rF   r   r   	_setmixinr   r#   r=   XPathr   r  r   r   r   r   r   Ir   r   r   r   r   rR   r   r.   r7   r@   rB   r   r  r   r   r   r   r   r   rn  r"  ElementBaser&  PIBaser(  
EntityBaser*  r/  r,  r   rP  rO  r   r   r   r   r   ra  rZ  rp  r0  r
   r  rv  rr  r  r  r	  r  r   r  r  rM  rd  ru  r  r  r    r  r  r   r	   r  	XMLParserr  r   rH  xhtml_parserr,   r$   r"   <module>r     sN  >@  	 6       1;;Z+.*?A V),_(=?{{P'*?&;= {{  R  SKK89	++j1 OQSQUQUV__JJ12;; {{B'*?&;=jj"**,bdd44:F ij iXR$ R$j! !H -E:E2
!"7dC  3$? %0	O$7	)U.. 		)U.. 			5<< 		E,, 	'U;; '\ !#

rtt!%%*U  jj&&+e  @D $$N =A#.bAHIq*+ q*h ;F  / / 7#/L.& &4V$ V$rE E>j+ @ ?N  / /
 ;a(J a(H =J  / / 9:H :z2! 2!j):D ):X(X (V[&:{ [&| <H  / / 8; B <H  / / 8"%  #%**,#..1c  $&JJ-%//2s " AFCGGT #8#3#34 6@!! @@%// @, l}r$   