+
     hz  c                  sJ   R t ^ RIHt ^ RIHt ^RIHt ^ RIt^RIHt ^ RI	t	^ RI
t
^ RIHtHtHtHtHtHtHt ]P$                  ! R4      t]P$                  ! R4      tR	tR
tRtRtRtRtRtRtRtRt]P>                  ]P@                  ,          t!]PD                  ]PF                  ,          t$R]P>                  R]P@                  R^ /t%]P$                  ! R4      t&]P$                  ! R4      t']P$                  ! R4      t(]P$                  ! R4      t)]P$                  ! R4      t*]P$                  ! R4      t+]P$                  ! R4      t,R't-^t.^t/^t0^t1^t2^t3 ! R R4      t4 ! R R 4      t5 ! R! R"4      t6 ! R# R$]54      t7 ! R% R&]Pp                  4      t9]Pt                  ! ]94       R# )(zCSS matcher.)annotations)datetime)utilN)	css_types)IteratorIterableAnyCallableSequencer   castz[^ 	
]z	[^ 	
]+ Z>Z~Z+z: z:>z:~z:+zhttp://www.w3.org/1999/xhtmlz$http://www.w3.org/XML/1998/namespaceZltrZrtlZautoz0^(?P<value>-?(?:[0-9]{1,}(\.[0-9]+)?|\.[0-9]+))$z*^(?P<hour>[0-9]{2}):(?P<minutes>[0-9]{2})$z)^(?P<year>[0-9]{4,})-(?P<month>[0-9]{2})$z)^(?P<year>[0-9]{4,})-W(?P<week>[0-9]{2})$z;^(?P<year>[0-9]{4,})-(?P<month>[0-9]{2})-(?P<day>[0-9]{2})$zd^(?P<year>[0-9]{4,})-(?P<month>[0-9]{2})-(?P<day>[0-9]{2})T(?P<hour>[0-9]{2}):(?P<minutes>[0-9]{2})$z(?:(?:-\*-)(?:\*(?:-|$))*|-\*$)c                  s2    ] tR t^;tRtR R ltR R ltRtR# )_FakeParentz
Fake parent class.

When we have a fragment with no `BeautifulSoup` document object,
we can't evaluate `nth` selectors properly.  Create a temporary
fake parent so we can traverse the root element as a child.
c                    V ^8  d   QhRRRR/# )   elementbs4.TagreturnNone Zformat   "8/usr/lib/python3.14/site-packages/soupsieve/css_match.py__annotate___FakeParent.__annotate__D   s     " " "D "    c                s    V.V n         R# )Initialize.Ncontents)selfr      &&r   __init__Z_FakeParent.__init__D   s     !	r   c                   V ^8  d   QhRR/# )r   r   intr   r   r   r   r   r   I   s     " " "r   c                s,    \        V P                  4      # )zLength.)lenr   r      &r   __len__Z_FakeParent.__len__I   s     4==!!r   r   N)__name__
__module____qualname____firstlineno____doc__r   r$   __static_attributes__r   r   r   r   r   ;   s    "
" "r   r   c                  s   ] tR t^OtRt]R R l4       t]R R l4       t]R R l4       t	]R R	 l4       t
]R
 R l4       t]R R l4       t]R R l4       t]R R l4       t]R R l4       t]R R l4       t]R R l4       tR R ltR R ltRHR R lltRIR R  lltRJR! R" lltRHR# R$ lltRKR% R& lltRHR' R( llt]R) R* l4       t]R+ R, l4       t]R- R. l4       t]R/ R0 l4       t]RHR1 R2 ll4       t]RLR3 R4 ll4       t]RHR5 R6 ll4       t ]R7 R8 l4       t!]R9 R: l4       t"]R; R< l4       t#]RMR= R> ll4       t$]R? R@ l4       t%]RA RB l4       t&RHRC RD llt'RHRE RF llt(RGt)R# )N_DocumentNavz#Navigate a Beautiful Soup document.c               r   )r   tagr   r   r   r   r   r   r   r   _DocumentNav.__annotate__S   s     f fS fT fr   c                sb    V P                  V4      '       g   \        R\        V4       24      hR# )z%Check if valid input tag or document.z:Expected a BeautifulSoup 'Tag', but instead received type N)is_tagZ	TypeErrortype)clsr,   r   r   assert_valid_inputZ_DocumentNav.assert_valid_inputR   s1    
 zz#XY]^aYbXcdee r   c               r   r   objbs4.element.PageElement | Noner   boolr   r   r   r   r   r-   [   s     2 22 2t 2r   c                6    \        V \        P                  4      # )zIs `BeautifulSoup` object.)
isinstancebs4ZBeautifulSoupr3   r#   r   is_docZ_DocumentNav.is_docZ   s     #s0011r   c               r   r2   r   r   r   r   r   r-   `   s     ( (2 (t (r   c                r6   )zIs tag.)r7   r8   Tagr9   r#   r   r.   Z_DocumentNav.is_tag_   s     #sww''r   c               r   r2   r   r   r   r   r   r-   e   s     0 0: 0t 0r   c                r6   )zIs declaration.)r7   r8   Declarationr9   r#   r   is_declarationZ_DocumentNav.is_declarationd   s     #s//r   c               r   r2   r   r   r   r   r   r-   j   s     * *4 * *r   c                r6   )z	Is CDATA.)r7   r8   CDatar9   r#   r   is_cdataZ_DocumentNav.is_cdatai   s     #syy))r   c               r   r2   r   r   r   r   r   r-   o   s     : :'E :$ :r   c                r6   )zIs processing instruction.)r7   r8   ProcessingInstructionr9   r#   r   is_processing_instructionZ&_DocumentNav.is_processing_instructionn   s     #s8899r   c               r   r2   r   r   r   r   r   r-   t   s     < <!? <D <r   c                sJ    \        V \        P                  P                  4      # )zIs navigable string.)r7   r8   r   ZNavigableStringr9   r#   r   is_navigable_stringZ _DocumentNav.is_navigable_strings   s     #s{{::;;r   c               r   r2   r   r   r   r   r   r-   y   s     r r= r$ rr   c                s    \        V \        P                  \        P                  \        P                  \        P
                  \        P                  34      # )zIs special string.)r7   r8   ZCommentr<   r>   r@   ZDoctyper9   r#   r   is_special_stringZ_DocumentNav.is_special_stringx   s5     #S__ciiIbIbdgdodopqqr   c               r   r2   r   r   r   r   r   r-   ~   s     O O$B Ot Or   c                s`    V P                  V4      ;'       d    V P                  V4      '       * # )z Check if node is content string.)rB   rC   )r0   r3   r   r   is_content_stringZ_DocumentNav.is_content_string}   s+     &&s+NNC4I4I#4N0NNr   c               r   )r   elr   r   r   r   r   r   r   r   r-      s      w ; r   c                s    \        V 4      # )z'Create fake parent for a given element.)r   rE   r#   r   create_fake_parentZ_DocumentNav.create_fake_parent   s     2r   c               r   r   rE   bs4.Tag | Noner   r5   r   r   r   r   r   r-      s     3 3 34 3r   c                sD    V RJ;'       d    \        V P                  4      # )z2Check if element (or document) is from a XML tree.N)r5   _is_xmlrF   r#   r   is_xml_treeZ_DocumentNav.is_xml_tree   s     ~22$rzz"22r   c               r   rH   r   r   r   r   r   r-      s     	
 	
N 	
t 	
r   c                s    Vf   R# \        V P                  V4      '       d   VP                  M\        P                  ! VP                  4      R8H  ;'       d    V P                  V4      4      # )z Check if element is an `iframe`.Fiframe)r5   rK   namer   loweris_html_tagr   rE   r   r   	is_iframeZ_DocumentNav.is_iframe   s\     :))"--bgg4::bgg3F8S ! !R 
 	
r   c               r   r   rE   r   r   r5   r   r   r   r   r   r-      s      ' d r   c                s    V P                   ;'       d    V P                   VJ pV'       gC   V P                  V4      pVRJ;'       d&    V P                  ;'       d    V P                  V4      pV# )z
Return whether element is a root element.

We check that the element is the root of the tree (which we have already pre-calculated),
and we check if it is the root element under an `iframe`.
N)root
get_parentis_htmlrQ   )r   rE   rS   parent   &&  r   is_rootZ_DocumentNav.is_root   sZ     yy,,TYY"___R(F%QQ$,,QQ4>>&;QDr   c               $    V ^8  d   QhRRRRRR/# )r   rE   rI   	no_iframer5   r   !Iterator[bs4.element.PageElement]r   r   r   r   r   r-      s"     ' '~ '$ 'Kl 'r   c              #  s   "   Ve8   V'       d   V P                  V4      '       g   VP                   Rj  xL
  R# R# R#  L
5i)z$Get contents or contents in reverse.N)rQ   r   r   rE   rZ      &&&r   get_contentsZ_DocumentNav.get_contents   s7      >DNN2$6$6;;&& %7 &s   AAAA ANc          
     s,    V ^8  d   QhRRRRRRRRRR	/# )
r   rE   rI   start
int | Nonereverser5   rZ   r   Iterator[bs4.Tag]r   r   r   r   r   r-      sC     	F 	F	F 	F 		F
 	F 
	Fr   c                s*    V P                  WVRV4      # )zGet tag children.T)get_children)r   rE   r_   ra   rZ   s   &&&&&r   get_tag_childrenZ_DocumentNav.get_tag_children   s       GT9EEr   c               s0    V ^8  d   QhRRRRRRRRRRR	R
/# )r   rE   rI   r_   r`   ra   r5   tagsrZ   r   r[   r   r   r   r   r   r-      sF     # ## # 	#
 # # 
+#r   c              #  s  "   Ve   V'       d   V P                  V4      '       g   \        VP                  4      ^,
          pVf   V'       d   TM^ pMTpV'       d   RMV^,           pV'       d   RM^p	^ Tu;8:  d   V8:  dO   M R# Wx8w  dC   VP                  V,          p
Wy,          pV'       d   V P                  V
4      '       g   KB  V
x  KH  R# R# R# R# 5i)zGet children.N)rQ   r!   r   r.   )r   rE   r_   ra   re   rZ   lastindexZendZincrnodes   &&&&&&     r   rc   Z_DocumentNav.get_children   s      >9DNN24F4Fr{{#a'D} 'Q"TAXC 2aDE!T!!l;;u-DME4;;t#4#4"
	 # " 5G>s(   CC'CCC0AC	Cc               rY   )r   rE   rI   rZ   r5   r   rb   r   r   r   r   r   r-      s-     L LL L 
	Lr   c              #  sJ   "   V P                  VRVR7       Rj  xL
  R#  L5i)z!Specifically get tag descendants.T)re   rZ   N)get_descendantsr\   r]   r   get_tag_descendantsZ _DocumentNav.get_tag_descendants   s"      '''KKKs   #!#c               s(    V ^8  d   QhRRRRRRRR/# )r   rE   rI   re   r5   rZ   r   r[   r   r   r   r   r   r-      s2     "  " "  "  	" 
 
+" r   c              #  sB  "   VEe   V'       d   V P                  V4      '       g   RpVP                   F  pVe
   WTJd   K  Rp\        V\        P                  4      '       d   V'       d   V P                  V4      '       d~   VP
                  e   VP
                  pMUTp\        V\        P                  4      '       d(   VP                  '       d   VP                  R,          pKG  VP                  pVx  Vf    R# K  Vx  K  V'       d   K  Vx  K  	  R# R# R# 5i)zGet descendants.Nrf   )rQ   Zdescendantsr7   r8   r;   next_siblingr   Znext_element)r   rE   re   rZ   Z	next_goodchildZ
last_child   &&&&   r   rj   Z_DocumentNav.get_descendants   s      >9DNN24F4FI(-  $IeSWW-- T^^E%:%: --9(-(:(:I).J",Z"A"AjFYFYFY-7-@-@-D
(2(?(?I#$,! KK1 ( 5G>s)   DDAD-DAD9DDc               s$    V ^8  d   QhRRRRRR/# )r   rE   rI   rZ   r5   r   r   r   r   r   r   r-     s!      ^   r   c                st    Ve   VP                   MRpV'       d   Ve   V P                  V4      '       d   RpV# )zGet parent.N)rV   rQ   )r   rE   rZ   rV      &&& r   rT   Z_DocumentNav.get_parent  s3     !n$+v0F0FFr   c               r   r   rE   rI   r   
str | Noner   r   r   r   r   r-   
  s     3 3 3J 3r   c                &    V e   V P                   # R# )Get tag.N)rM   rF   r#   r   get_tag_nameZ_DocumentNav.get_tag_name	  s     .rww2d2r   c               r   r   rE   r   r   rq   r   r   r   r   r   r-     s      G 
 r   c                s    V P                   # zGet prefix.)prefixrF   r#   r   get_prefix_nameZ_DocumentNav.get_prefix_name  s     yyr   c               r   rp   r   r   r   r   r   r-     s     8 8N 8z 8r   c                rr   )zGet namespace `URI`.N)	namespacerF   r#   r   get_uriZ_DocumentNav.get_uri  s      "~r||747r   c               r   r   rE   r   r   rI   r   r   r   r   r   r-     s     + +g +. +r   c                s(    V P                  VRR7      # )Get next sibling tag.T)re   )get_next)r0   rE   r   r   get_next_tagZ_DocumentNav.get_next_tag  s     ||BT|**r   c               rY   r   rE   r   re   r5   r   r4   r   r   r   r   r   r-   "  s"     
 
' 
 
:X 
r   c                    VP                   pV'       d3   \        V\        P                  4      '       g   Ve   VP                   pK:  V'       d#   \        V\        P                  4      '       g   RpV# )r|   N)rl   r7   r8   r;   r0   rE   re   siblingro   r   r}   Z_DocumentNav.get_next!  sM     //:gsww77G<O**G
7CGG44Gr   c               rY   )r   rE   r   re   r5   r   rI   r   r   r   r   r   r-   /  s!     * *' * * *r   c                s&    V P                  VR4      # )Get previous sibling tag.T)get_previous)r0   rE   re   r]   r   get_previous_tagZ_DocumentNav.get_previous_tag.  s     D))r   c               rY   r   r   r   r   r   r   r-   5  s"     
 
g 
T 
>\ 
r   c                r   )r   N)Zprevious_siblingr7   r8   r;   r   ro   r   r   Z_DocumentNav.get_previous4  sO     %%:gsww77G<O..G
7CGG44Gr   c               r   rH   r   r   r   r   r   r-   B  s     	+ 	+ 	+4 	+r   c                s^    V e   \        V R4      MRp\        T;'       d
    V\        8H  4      # )z
Check if element has an HTML namespace.

This is a bit different than whether a element is treated as having an HTML namespace,
like we do in the case of `is_html_tag`.
Nry   )getattrr5   NS_XHTML)rE   ns   & r   has_html_nsZ_DocumentNav.has_html_nsA  s-     *,WR%TB))2>**r   c               rY   )r   rE   rI   	attr_namestrr   ztuple[str | None, str | None]r   r   r   r   r   r-   N  s'     W WN Ws W?\ Wr   c                sB    V f   R# \        VRR4      \        VRR4      3# )z7Return namespace and attribute name without the prefix.Nry   rM   )NN)r   )rE   r   r   r   split_namespaceZ_DocumentNav.split_namespaceM  s-     :y+t4giQU6VVVr   c               r   )r   valuer   r   zstr | Sequence[str]r   r   r   r   r   r-   W  s      C ,? r   c           	     s   Vf   R# \        V\        4      '       d   V# \        V\        4      '       d   VP                  R4      # \        V\        4      '       d   . pV F  p\        V\        \        34      '       g3   \        V\        4      '       d   VP                  \        V4      4       KQ  VP                  \        \        V P                  V4      4      4       K  	  V# \        V4      # )z6Normalize the value to be a string or list of strings. Zutf8)r7   r   ZbytesZdecoder   appendr	   normalize_value)r0   r   Z	new_valuevrW   r   r   Z_DocumentNav.normalize_valueV  s    
 = uc""L eU##<<'' eX&&I!!c5\22z!X7N7N $$SV, $$T#s/B/B1/E%FG   5zr   c               (    V ^8  d   QhRRRRRRRR/# )r   rE   r   rM   r   defaultstr | Sequence[str] | Noner   r   r   r   r   r   r-   x  s2        ,	
 
$r   c                s@   TpVP                   '       d&    V P                  VP                  V,          4      pV# VP                  P	                  4        F4  w  rV\
        P                  ! V4      V8X  g   K"  V P                  V4      p V# 	  V#   \         d     T# i ; i)zGet attribute by name.)rJ   r   attrsZKeyErroritemsr   rN   )r0   rE   rM   r   r   kr   rn   r   get_attribute_by_nameZ"_DocumentNav.get_attribute_by_namew  s     :::++BHHTN; 	 (::a=D(//2E	 )    s   "B BBc               r   )r   rE   rI   r   z0Iterator[tuple[str, str | Sequence[str] | None]]r   r   r   r   r   r-     s     0 0 04d 0r   c              #  s   "   Ve:   VP                   P                  4        F  w  r#W P                  V4      3x  K  	  R# R# 5i)zIterate attributes.N)r   r   r   )r0   rE   r   r   rW   r   iter_attributesZ_DocumentNav.iter_attributes  s<      >(,,Q/// ) s   A Ac               r   )r   rE   r   r   zSequence[str]r   r   r   r   r   r-     s     , ,W , ,r   c                s    V P                  VR. 4      p\        V\        4      '       d   \        P	                  V4      p\        \        \        ,          V4      # )zGet classes.Zclass)r   r7   r   	RE_NOT_WSZfindallr	   r   )r0   rE   classes   && r   get_classesZ_DocumentNav.get_classes  sF     ++B<gs##''0GHSM7++r   c               rY   )r   rE   r   rZ   r5   r   r   r   r   r   r   r   r-     s!     
 
7 
t 
 
r   c                s    RP                  V P                  WR7       Uu. uF  pV P                  V4      '       g   K  VNK   	  up4      # u upi )z	Get text.r   rZ   )joinrj   rD   r   rE   rZ   ri   ro   r   get_textZ_DocumentNav.get_text  sS     ww!%!5!5b!5!N!N))$/ !N
 	
s
   AAc               rY   )r   rE   r   rZ   r5   r   z	list[str]r   r   r   r   r   r-     s!     
 
w 
4 
I 
r   c                s    V P                  WR7       Uu. uF  q0P                  V4      '       g   K  VNK  	  up# u upi )zGet Own Text.r   )r^   rD   r   ro   r   get_own_textZ_DocumentNav.get_own_text  sB     "..r.G
GTKaKabfKgDDG
 	
 
s   ;;r   F)NFF)NFFF)FF)TN)*r%   r&   r'   r(   r)   classmethodr1   staticmethodr:   r.   r=   r?   rA   rB   rC   rD   rG   rK   rQ   rX   r^   rd   rc   rk   rj   rT   rt   rx   rz   r~   r}   r   r   r   r   r   r   r   r   r   r   r*   r   r   r   r+   r+   O   s&   -f f 2 2 ( ( 0 0 * * : : < < r r O O
  
 3 3
	
'	F#4L" H 3 3
  
 8 8
 + +
 
 
 * *
 
 
 	+ 	+ W W  @  * 0 0 , ,

 
r   r+   c                  s    ] tR tRtRt]R R l4       t]R R l4       t]R R l4       t]R	 R
 l4       t	]R R l4       t
]R R l4       t]R R l4       tRtR# )Inputsi  z-Class for parsing and validating input items.c               s(    V ^8  d   QhRRRRRRRR/# )r   yearr    monthdayr   r5   r   r   r   r   r   Inputs.__annotate__  s(     $ $3 $s $ $ $r   c                s    \         pV\        8X  d8   V ^,          ^ 8X  d   V ^d,          ^ 8w  g   V R,          ^ 8X  d   \        M\        pMV\        9   d   \
        p^Tu;8*  ;'       d    V8*  # u # )zValidate day.i  )
LONG_MONTHFEBFEB_LEAP_MONTH	FEB_MONTH	MONTHS_30SHORT_MONTH)r   r   r   Zmax_daysro   r   validate_dayZInputs.validate_day  sa     C<+/!8q=tczQUY\_U_cdUd~ktHi"HC##8####r   c               $    V ^8  d   QhRRRRRR/# )r   r   r    weekr   r5   r   r   r   r   r   r     s!     % %C %s %t %r   c                s    \         P                  ! ^ R^ RV  2R4      P                  4       ^,          pV^8X  d   ^5p^Tu;8*  ;'       d    V8*  # u # )zValidate week.-z%m-%d-%Y)r   ZstrptimeZisocalendar)r   r   Zmax_weekr   r   validate_weekZInputs.validate_week  s[     $$t1RD$%8*EQQSTUVq=HD$$H$$$$r   c               r   )r   r   r    r   r5   r   r   r   r   r   r     s        c  d  r   c                s.    ^T u;8*  ;'       d    ^8*  # u # )zValidate month.r   )r   r#   r   validate_monthZInputs.validate_month  s     ERr   c               r   )r   r   r    r   r5   r   r   r   r   r   r     s      C D r   c                s    ^V 8*  # )zValidate year.r   )r   r#   r   validate_yearZInputs.validate_year  s     Dyr   c               r   )r   hourr    r   r5   r   r   r   r   r   r     s      C D r   c                s.    ^ T u;8*  ;'       d    ^8*  # u # )zValidate hour.r   )r   r#   r   validate_hourZInputs.validate_hour  s     DBr   c               r   )r   minutesr    r   r5   r   r   r   r   r   r     s     " "# "$ "r   c                s.    ^ T u;8*  ;'       d    ^;8*  # u # )zValidate minutes.r   )r   r#   r   validate_minutesZInputs.validate_minutes  s     G!!r!!!!r   c               rY   )r   ityper   r   rq   r   ztuple[float, ...] | Noner   r   r   r   r   r     s"     4 4 4J 4;S 4r   c                s   RpVf   V# VR8X  d   \         P                  V4      pV'       d   \        VP                  R4      ^
4      p\        VP                  R4      ^
4      p\        VP                  R4      ^
4      pV P	                  V4      '       d4   V P                  V4      '       d   V P                  WVV4      '       d   WVV3pV# VR8X  d   \        P                  V4      pV'       dh   \        VP                  R4      ^
4      p\        VP                  R4      ^
4      pV P	                  V4      '       d   V P                  V4      '       d   WV3pV# VR8X  d   \        P                  V4      pV'       dh   \        VP                  R4      ^
4      p\        VP                  R4      ^
4      pV P	                  V4      '       d   V P                  WX4      '       d   WX3pV# VR8X  d   \        P                  V4      pV'       dh   \        VP                  R4      ^
4      p	\        VP                  R	4      ^
4      p
V P                  V	4      '       d   V P                  V
4      '       d   W3pV# VR
8X  Ed!   \        P                  V4      pV'       Ed   \        VP                  R4      ^
4      p\        VP                  R4      ^
4      p\        VP                  R4      ^
4      p\        VP                  R4      ^
4      p	\        VP                  R	4      ^
4      p
V P	                  V4      '       dc   V P                  V4      '       dL   V P                  WVV4      '       d4   V P                  V	4      '       d   V P                  V
4      '       d   WVWyV
3pV# VR9   d9   \        P                  V4      pV'       d   \        VP                  R4      4      3pV# )zParse the input value.Ndater   r   r   r   timer   r   datetime-localr   )numberrange)RE_DATEmatchr    Zgroupr   r   r   RE_MONTHRE_WEEKr   RE_TIMEr   r   RE_DATETIMERE_NUMZfloat)r0   r   r   ZparsedZmr   r   r   r   r   r   s   &&&        r   parse_valueZInputs.parse_value  s-    =LF?e$A1776?B/AGGG,b1!''%."-$$T**s/A/A%/H/HSM]M]^bknMoMo"3/FN M gu%A1776?B/AGGG,b1$$T**s/A/A%/H/H"]F@ ? f_e$A1776?B/1776?B/$$T**s/@/@/L/L"\F2 1 f_e$A1776?B/aggi0"5$$T**s/C/CG/L/L"_F$ # &&!!%(Aq1776?B/AGGG,b1!''%."-1776?B/aggi0"5%%d++0B0B50I0IcN^N^_cloNpNp%%d++0D0DW0M0M"3g>F
 	 ))U#A 013r   r   N)r%   r&   r'   r(   r)   r   r   r   r   r   r   r   r   r   r*   r   r   r   r   r     s    7$ $ % %    
  
  
 " "
 4 4r   r   c                  s   ] tR tRtRtR R ltR R ltR R ltR	 R
 ltR R lt	R R lt
R R ltR R ltR R ltR R ltR R ltR R ltR R ltR R ltRQR R  lltR! R" ltR# R$ ltR% R& ltR' R( ltR) R* ltR+ R, ltR- R. ltR/ R0 ltR1 R2 ltR3 R4 ltR5 R6 ltR7 R8 ltR9 R: lt R; R< lt!R= R> lt"R? R@ lt#RA RB lt$RC RD lt%RE RF lt&RRRG RH llt'RI RJ lt(RK RL lt)RM RN lt*ROt+RP# )SCSSMatchi  zPerform CSS matching.c          
     ,    V ^8  d   QhRRRRRRRRR	R
/# )r   	selectorsct.SelectorListscoperI   
namespacesct.Namespaces | Noneflagsr    r   r   r   r   r   r   r   CSSMatch.__annotate__  sC     'B 'B"'B 'B )	'B
 'B 
'Br   c                s>   V P                  V4       W n        . V n        . V n        . V n        Wn        Vf   / MTV n        W@n        RV n        TpV P                  V4      pV'       d   TpV P                  V4      pK  RpV P                  V4      '       g   TpMV P                  V4       F  pTp M	  Wpn        W%Jd   TMTV n        V P                  V4      V n        V P!                  V4      V n        V P"                  '       * ;'       g    V P                  V n        R# )r   NF)r1   r,   cached_meta_langcached_default_formscached_indeterminate_formsr   r   r   iframe_restrictrT   r:   rd   rS   r   r   has_html_namespacerK   is_xmlrU   )	r   r   r   r   r   ZdocrV   rS   rm   s	   &&&&&    r   r   ZCSSMatch.__init__  s    	& "$&!*,'" * 2"

$ %C__S)F{{3D..s3 4 	#.UD
"&"2"24"8 &&s+;;AA$*A*Ar   c               r   )r   r   r5   r   r   r   r   r   r   C  s     6 6T 6r   c                sB    V P                   ;'       g    V P                  # )z3Check if namespaces are supported in the HTML type.)r   r   r"   r#   r   supports_namespacesZCSSMatch.supports_namespacesC  s     {{55d555r   c               r   )r   rE   rI   r   r   r   r   r   r   r   r   H  s      ^  r   c                s    RpVf   V# V P                  4       '       d   V P                  V4      pV'       d   TpV# \        pV# )zGet tag namespace.r   )r   rz   r   )r   rE   ry   r   rW   r   
get_tag_nsZCSSMatch.get_tag_nsH  sN     	:##%%b!B	  !Ir   c               r   rH   r   r   r   r   r   r   W  s     / /n / /r   c                s2    V P                  V4      \        8H  # )z"Check if tag is in HTML namespace.)r   r   rP   r   r   rO   ZCSSMatch.is_html_tagW  s     r"h..r   c               r   rp   r   r   r   r   r   r   \  s     R R. RZ Rr   c                    V P                  V4      pVe)   V P                  '       g   \        P                  ! V4      # T# )rs   )rt   r   r   rN   r   rE   rM   r   r   get_tagZCSSMatch.get_tag\  s5       $#'#3DKKKtzz$QTQr   c               r   ru   r   r   r   r   r   r   b  s     X XW X Xr   c                r   rv   )rx   r   r   rN   )r   rE   rw   r   r   
get_prefixZCSSMatch.get_prefixb  s6     %%b)%+%7tzz&!WQWWr   c               r   )r   rE   r   r   r`   r   r   r   r   r   r   h  s     # #G #
 #r   c           
     sb   V P                  V4       EF  pV P                  V4      '       d   \        P                  \        P
                  ! V P                  VRR4      4      R4      pV P                  V4      pV'       d   VR9   g   V P                  V4      '       d   Ve   K  V P                  V4      pVe   Vu # K  V P                  V4      '       d   K  V FK  p\        P                  ! V4      pVR9   g   K"  VR8X  d   \        P                  M\        P                  u u # 	  EK  	  R# )z%Get directionality from element text.dirr   NL)bdiZscriptZstyletextarearL   ZALZRr   )rc   r.   DIR_MAPgetr   rN   r   r   rO   	find_bidirC   unicodedatabidirectionalctSEL_DIR_LTRSEL_DIR_RTL)r   rE   ri   	directionrM   r   cbidis   &&      r   r   ZCSSMatch.find_bidih  s    %%b)D {{4   $KK

43M3MdTY[]3^(_aef	||D)d&VV((..) t,$ L  %%d++ "003++-1S[2>>bnnL 9 *@ r   c               r   )r   
lang_ranger   lang_tagr   r5   r   r   r   r   r   r     s!     6 63 6# 6$ 6r   c                s   Rp\         P                  RV4      P                  4       pVP                  R4      pVP                  4       P                  R4      p\	        V4      p\	        V4      p^ p^ p	WH,          p
WY,          pV^8X  d   V^8X  d   V
'       g	   W8X  d   R# V
R8w  d   W8w  g   V
R8X  d   V^8X  d   V'       g   RpV^,          pV	^,          p	V'       dS   W8  dM   WH,          p
 WY,          pT
'       g   RpK+  Y8X  d   T^,          pM\	        T4      ^8X  d   RpKO  T	^,          p	KZ  V#   \
         d    Rp Kl  i ; i)zFilter the language tags.Tr   *F)RE_WILD_STRIPZsubrN   Zsplitr!   Z
IndexError)r   r   r   r   ZrangesZsubtagsZlengthZslengthZrindexZsindexZrZss   &&&         r   extended_language_filterZ!CSSMatch.extended_language_filter  s8    "&&sJ7==?
!!#&.."((-Vg,NO Q;7a<af HQ#X'Q,qE!! AO  ! Q1 aKF1   	s   -D2 2EEc               s(    V ^8  d   QhRRRRRRRR/# )	r   rE   r   attrr   rw   rq   r   r   r   r   r   r   r   r     s2     3 33 3 	3
 
$3r   c                s&   RpV P                  4       '       Ed*   RpV'       d*   V P                  P                  V4      pVf
   VR8w  d   R# MRpV P                  V4       F  w  rgV P	                  W4      w  rVfa   V P
                  '       d   W&8X  gB   V P
                  '       g5   \        P                  ! V4      \        P                  ! V4      8X  d   Tp V# K|  Ve   WX8w  d
   VR8w  d   K  V P
                  '       g1   \        P                  ! V4      \        P                  ! V	4      8w  d
   MW)8w  d   K  Tp V# 	   V# V P                  V4       F9  w  rg\        P                  ! V4      \        P                  ! V4      8w  d   K6  Tp V# 	  V# )z3Match attribute name and return value if it exists.Nr   )r   r   r   r   r   r   r   rN   )
r   rE   r   rw   r   r   r   r   ry   rM   s
   &&&&      r   match_attribute_nameZCSSMatch.match_attribute_name  sf    ##%%E__((0:&C-,,R0 #'"6"6r"=	 :	4;;;4::VZK[_c_i_ijk_lKl !, %  $Vs] BFDJJt$

4(88SWS_ A 1@  ,,R0::d#tzz!}4 1
 r   c               rY   r   rE   r   r,   zct.SelectorTagr   r5   r   r   r   r   r   r     s!      '  4 r   c                s   RpV P                  V4      pV P                  P                  R4      pVP                  f   RM$V P                  P                  VP                  4      pVP                  f   Ve   WE8w  d   RpV# VP                  e   VP                  R8X  d   V'       d   RpV# VP                  '       d   VP                  R8w  d   Ve   WF8w  d   RpV# )z#Match the namespace of the element.Tr   Fr   )r   r   r   rw   )r   rE   r,   r   ry   Zdefault_namespaceZtag_nss   &&&    r   match_namespaceZCSSMatch.match_namespace  s     OOB'	 OO//3zz)t/B/B3::/N::#4#@YEcE  jj$r)9iE 	 JJJJJ#6>Y5HEr   c               rY   )r   rE   r   
attributesz tuple[ct.SelectorAttribute, ...]r   r5   r   r   r   r   r   r     s#      7 8X ]a r   c                s   RpV'       d   V F  pV P                  WP                  VP                  4      pV P                  '       d   VP                  '       d   VP                  MVP
                  pVf   Rp V# \        V\        4      '       d   TMRP                  V4      pVf   K  VP                  V4      e   K  Rp V# 	  V# )zMatch attributes.TFr
   )
r   Z	attributerw   r   Zxml_type_patternpatternr7   r   r   r   )r   rE   r   r   aZtempr   r      &&&     r   match_attributesZCSSMatch.match_attributes  s     00[[!((K04@R@R@R!,,XYXaXa<!E  !+4 5 5388D>?]]5)1!E   r   c               rY   r   r   r   r   r   r   r   "  s!     
 
 
n 
 
r   c                s    V P                   '       g/   VP                  e!   \        P                  ! VP                  4      MVP                  pVRJ;'       d    W0P	                  V4      R39  '       * # )zMatch tag name.Nr   )r   rM   r   rN   r   )r   rE   r,   rM   ro   r   match_tagnameZCSSMatch.match_tagname"  s`     -1KKKCHH<P

388$VYV^V^ 0 0b)3//
 	
r   c               rY   )r   rE   r   r,   zct.SelectorTag | Noner   r5   r   r   r   r   r   r   +  s"     
 
G 
*? 
D 
r   c                sv    RpVe3   V P                  W4      '       g   RpV P                  W4      '       g   RpV# )zMatch the tag.TF)r   r   )r   rE   r,   r   ro   r   	match_tagZCSSMatch.match_tag+  s?     ?''00%%b..r   c               rY   r   rE   r   relationr   r   r5   r   r   r   r   r   r   7  s!      w / d r   c                st   Rp\        V^ ,          \        P                  4      '       d   V# V^ ,          P                  \        8X  d^   V P                  WP                  R7      pV'       g8   V'       d0   V P                  WB4      pV P                  W@P                  R7      pK?  V# V^ ,          P                  \        8X  d8   V P                  WP                  R7      pV'       d   V P                  WB4      pV# V^ ,          P                  \        8X  dH   V P                  V4      pV'       g-   V'       d%   V P                  WR4      pV P                  V4      pK4  V# V^ ,          P                  \        8X  dB   V P                  V4      pV'       d)   V P                  V4      '       d   V P                  WR4      pV# )zMatch past relationship.Fr   )r7   r   SelectorNullrel_type
REL_PARENTrT   r   match_selectorsREL_CLOSE_PARENTREL_SIBLINGr   REL_CLOSE_SIBLINGr.   )r   rE   r  foundrV   r      &&&   r   match_past_relationsZCSSMatch.match_past_relations7  s]    hqk2??33LA;:-__R3G3G_HF,,V>;O;OP  a[!!%55__R3G3G_HF,,V>  a[!![0++B/G,,W?//8
 	 a[!!%66++B/G4;;w//,,W?r   c               r   )r   rV   r   r  r   	recursiver5   r   r   r   r   r   r   r   S  s*       O X\ im r   c                s    RpV'       d   V P                   pMV P                  pV! WP                  R7       F  pV P                  Wb4      pV'       g   K   V# 	  V# )zMatch future child.Fr   )rk   rd   r   r  )r   rV   r  r  r   Zchildrenrm   rn   r   match_future_childZCSSMatch.match_future_childS  s\     //H,,Hf0D0DEE((9Eu	 F r   c               rY   r  r   r   r   r   r   r   a  s"       O PT r   c                s   Rp\        V^ ,          \        P                  4      '       d   V# V^ ,          P                  \        8X  d   V P                  WR4      pV# V^ ,          P                  \        8X  d   V P                  W4      pV# V^ ,          P                  \        8X  dH   V P                  V4      pV'       g-   V'       d%   V P                  WB4      pV P                  V4      pK4  V# V^ ,          P                  \        8X  dB   V P                  V4      pV'       d)   V P                  V4      '       d   V P                  WB4      pV# )zMatch future relationship.FT)r7   r   r  r  REL_HAS_PARENTr  REL_HAS_CLOSE_PARENTREL_HAS_SIBLINGr~   r  REL_HAS_CLOSE_SIBLINGr.   )r   rE   r  r
  r      &&&  r   match_future_relationsZCSSMatch.match_future_relationsa  s    hqk2??33LA;>1++B$?E  a[!!%99++B9E  a[!!_4''+G,,W?++G4
 	 a[!!%::''+G4;;w//,,W?r   c               rY   r  r   r   r   r   r   r   x  s!      ' _  r   c                s   Rp\        V^ ,          \        P                  4      '       g   V^ ,          P                  f   V# V^ ,          P                  P	                  R4      '       d   V P                  W4      pV# V P                  W4      pV# )z%Match relationship to other elements.F:)r7   r   r  r  Z
startswithr  r  )r   rE   r  r
  ro   r   match_relationsZCSSMatch.match_relationsx  s{     hqk2??33x{7K7K7SLA;**3////=E  --b;Er   c               rY   )r   rE   r   idstuple[str, ...]r   r5   r   r   r   r   r   r     s!      7  T r   c                sT    RpV F  pW@P                  VRR4      8w  g   K  Rp V# 	  V# )zMatch element's ID.TZidr   F)r   )r   rE   r  r
  ir  r   match_idZCSSMatch.match_id  s<     A..r4<<	  r   c               rY   )r   rE   r   r   r  r   r5   r   r   r   r   r   r     s!     	 	 	/ 	d 	r   c                sT    V P                  V4      pRpV F  pWS9  g   K  Rp V# 	  V# )zMatch element's classes.TF)r   )r   rE   r   Zcurrent_classesr
  r   r  r   match_classesZCSSMatch.match_classes  s=     **2.A'	  r   c               r   rR   r   r   r   r   r   r     s      W  r   c                s   V P                  V4      pV'       d   V P                  V4      pV'       dw   Ves   V P                  V4      '       gE   V P                  V4      '       d   VP	                  4       '       g   V P                  V4      '       d   RpKk  V P                  V4      pK~  V'       d   V P                  V4      pV'       dw   Ves   V P                  V4      '       gE   V P                  V4      '       d   VP	                  4       '       g   V P                  V4      '       d   RpKk  V P                  V4      pK~  V# )zMatch element as root.F)rX   r   r.   rD   Zstripr?   r}   )r   rE   rX   r   rW   r   
match_rootZCSSMatch.match_root  s     ,,r"''+Gg1KK((T-C-CG-L-LQXQ^Q^Q`Q`MM'**#G"//8GmmB'Gg1KK((T-C-CG-L-LQXQ^Q^Q`Q`MM'**#G"mmG4Gr   c               r   rR   r   r   r   r   r   r     s        g  $  r   c                s    V P                   VJ # )zMatch element as scope.)r   rP   r   r   match_scopeZCSSMatch.match_scope  s     zzRr   c               r   )r   rE   r   rm   r   r5   r   r   r   r   r   r     s!     
 
W 
W 
 
r   c                s    V P                  V4      V P                  V4      8H  ;'       d$    V P                  V4      V P                  V4      8H  # )z!Match tag type for `nth` matches.)r   r   )r   rE   rm   r]   r   match_nth_tag_typeZCSSMatch.match_nth_tag_type  sG     \\% DLL$44 < <__U#tr'::	
r   c               rY   )r   rE   r   nthztuple[ct.SelectorNth, ...]r   r5   r   r   r   r   r   r     s'     c cG c*D c cr   c                sl   RpV EF*  pRpVP                   '       d%   V P                  WP                   4      '       g    V# V P                  V4      pVf   \        RV P	                  V4      4      pVP
                  p\        V4      ^,
          pV'       d   TM^ p^ p	VP                  p
VP                  pVP                  p^ p^pV'       d   RM^pV'       d   W,          V,           MT
;ppV'       Ed
   RpV^8  g   VV8  d   V^ 8  dN   ^ V,
          pVe	   V^8X  d   MRpW,          pV'       d   W,          V,           MT
;pp^ V,
          pVV8  d   MQKb  VV,
          pVe	   VR8X  d   M:^pW,          pV'       d   W,          V,           MT
;ppVV,
          pVV8  d   MTpK  TpV
^ 8  d1   V^8  d(   TpW,          pV'       d   W,          V,           MT
;ppK.  RpTpV'       d   W,          V,           MT
;pp^Tu;8:  d   V^,           8:  Ed   M EMRpV P                  WXV^ 8  R7       F  pW,          p\        V\        P                  4      '       g   K-  VP                   '       d%   V P                  VVP                   4      '       g   Kc  VP                  '       d   V P                  VV4      '       g   K  V	^,          p	V	V8X  d   VVJ d   RpM MVVJ g   K   M	  VVJ d   M6TpW,          pV^ 8  d   M$V'       d   W,          V,           MT
pVV8X  g   EK%   V'       d   EK*   V# 	  V# )zMatch `nth` elements.TFNr   )r_   ra   rf   )r   r  rT   r	   rG   rg   r!   r   bnrc   r7   r8   r;   Zof_typer  )r   rE   r  Zmatchedr!  rV   rg   Z
last_indexrh   Zrelative_indexr   r   ZvarZcountZ
count_incrZfactorZidxZlast_idxZadjustZdiff_lowZdiffZ	diff_highZlowestrm      &&&                     r   	match_nthZCSSMatch.match_nth  s    AG{{{4#7#7KK#H#Hv u __R(F~i)@)@)DE66DVqJ"&JAENAA##CEJRQF.1QY]q8C( s Agz!1Qw#$s7!-&A+!!#+:=Q1Dh 3w8+! , %(*$4	!-&B,!!"+:=Q1Dh"Z/9,!$(	
 q5(!&+:=Q1Dh!#J25Q1<h s,j1n,,!..vFUVJ.WEOE%eSWW55 {{{4+?+?q{{+S+S yyy)@)@U)K)K "a'N%, B;&*G!{# X$ B;#19'*ai!ms?7} | r   c               r   rR   r   r   r   r   r   r   (  s      g $ r   c                s    RpV P                  V4       FX  pV P                  V4      '       d   Rp V# V P                  V4      '       g   K8  \        P	                  V4      '       g   KU  Rp V# 	  V# )z)Check if element is empty (if requested).TF)rc   r.   rD   RE_NOT_EMPTYsearch)r   rE   Zis_emptyrm   rW   r   match_emptyZCSSMatch.match_empty(  ss     &&r*E{{5!!   ''..<3F3Fu3M3M  + r   c               rY   )r   rE   r   r   ztuple[ct.SelectorList, ...]r   r5   r   r   r   r   r   r   5  s#      W 9T Y] r   c                sR    RpV F  pV P                  W4      '       d   K  RpK   	  V# )zMatch selectors.TF)r  )r   rE   r   r   Zselr  r   match_subselectorsZCSSMatch.match_subselectors5  s0     C''00  r   c               rY   )r   rE   r   containsztuple[ct.SelectorContains, ...]r   r5   r   r   r   r   r   r   >  s#       4S X\ r   c                sv   RpRpV F  pVfL   VP                   '       d   V P                  WP                  R7      pMV P                  WP                  R7      pRpVP                   F>  pVP                   '       d    V F  pWx9   g   K  Rp M	  V'       d    MK4  Wt9   g   K<  Rp M	  V'       d   K  RpK  	  V# )z"Match element if it contains text.TNr   F)Zownr   rU   r   text)	r   rE   r(  r   contentZcontain_listr
  r)  r   	   &&&      r   match_containsZCSSMatch.match_contains>  s     $L###"//ll/KG"mmB,,mGGE$))###$9$(E! %    $ * 5) %* r   c               r   rR   r   r   r   r   r   r   Z  s     & & &D &r   c                sv   RpRpV P                  VRR7      pV'       dK   VfG   V P                  V4      R8X  d   V P                  V4      '       d   TpK=  V P                  VRR7      pKR  Ve   RpV P                   F  w  rgWcJ g   K  RpWqJ d   Rp M	  V'       g   V P	                  VRR7       F  pV P                  V4      p	V	R8X  d    V# V	R	9   g   K'  V P                  VRR4      p
V
'       g   KD  \        P                  ! V
4      R8X  g   Ka  V P                  P                  W834       WJ d   Rp V# 	  V# )
Match default.FNTr   formr/   r   Zsubmit)inputZbutton)	rT   r   rO   r   rk   r   r   rN   r   )r   rE   r   r.  rV   
found_formfZtrm   rM   r   s   &&         r   match_defaultZCSSMatch.match_defaultZ  s6     t4||F#v-$2B2B62J2J4@J119!%Jw $ 2 !55dd5KE<<.Dv~  22 66ufbI1A(!: 55<<d]K!{(,! L r   c               r   rR   r   r   r   r   r   r     s     < <g <$ <r   c                sX  a  Rp\        \        S P                  VR4      4      pR V 3R llpV! V4      pVEeq   RpS P                   F  w  rxp	WuJ g   K  W8X  g   K  RpV	RJ d   Rp M	  V'       Eg7   Rp
S P	                  VRR7       F  pWJ d   K
  S P                  V4      pVR8X  d   RpRpRpS P                  V4       F  w  pp\        P                  ! V4      R8X  d   \        P                  ! V4      R	8X  d   RpMB\        P                  ! V4      R8X  d   VV8X  d   RpM\        P                  ! V4      R
8X  d   RpV'       g   K  V'       g   K  V'       g   K  V! V4      VJ g   K  Rp
 M	  V
'       g   K   M	  V
'       g   RpS P                  P                  WSV34       V# )r-  FrM   c               r   r{   r   r   r   r   r   Z2CSSMatch.match_indeterminate.<locals>.__annotate__  s     	 	 	N 	r   c                s   < RpSP                  V RR7      pVfS   SP                  V4      R8X  d   SP                  V4      '       d   Tp V# TpSP                  VRR7      pVe   KQ  Tp V# V# )zFind this input's form.NTr   r.  )rT   r   rO   )rE   r.  rV   Zlast_parentr   s   &   r   get_parent_formZ5CSSMatch.match_indeterminate.<locals>.get_parent_form  s~    D__R4_8F,<<'61d6F6Fv6N6N!D K %4@>&DK4Kr   Tr   r/  r/   Zradiochecked)
r	   r   r   r   rk   r   r   r   rN   r   )r   rE   r   rM   r3  r.  r0  r1  r!  r  r4  rm   Ztag_nameZis_radioZcheckZhas_namer   r   s   f&                r   match_indeterminateZCSSMatch.match_indeterminate  s    C33B?@	 	 r" J::a9!%JDy $ ; :!55dd5KE{ #||E2H7*#( %#($($8$8$?DAq#zz!}64::a=G;S+/!%A&!8Q$Y+/!%A)!;(,'xEEhh?SXCY]aCa*. % %@ w' L(  E//66E7JKr   c               rY   )r   rE   r   langsztuple[ct.SelectorLang, ...]r   r5   r   r   r   r   r   r     s'     T TW T-H TT Tr   c           	     s   RpV P                  4       pV P                  pV P                  pTpRpRp	V'       Eg   V P                  V4      p
V P	                  V4       F  w  rV P                  W{4      w  rV'       d	   V
'       d0   V P                  '       g   \        P                  ! V4      MTR8X  gW   V'       g   Ka  V
'       d   Kk  V\        8X  g   Kx  V P                  '       g   Ve   \        P                  ! V4      MTR8X  g   K  Tp M	  Tp	V P                  WpP                  R7      pVe   EK  T	pV P                  V4      pT	p Vf=   V P                  '       d+   V P                   F  pW_^ ,          J g   K  V^,          pK  	  VEf   V P                  '       d%   V'       Ed   V'       Ed   VP                  R8X  Ed   RpR Fg  pRpV P                  WpP                  R7       F8  pV P                  V4      V8X  g   K  V P!                  V4      '       g   K4  RpTp M	  V'       d   Kg   M	  V'       EdU   VEeP   V EF  p\#        V\$        P&                  4      '       d   V P                  V4      R8X  d   V P!                  V4      '       d   RpRpV P	                  V4       F  w  r\        P                  ! V4      R8X  d   \        P                  ! V4      R	8X  d   Rp\        P                  ! V4      R
8X  d   TpV'       g   Kd  V'       g   Kn  TpV P                  P)                  \+        \,        V4      \+        \,        V4      34        M	  Vf   EK   M	  Vf,   V P                  P)                  \+        \,        V4      R34       VeJ   V FC  pRpV F-  pV P/                  V\+        \,        V4      4      '       g   K+  RpK/  	  V'       d   KB   V# 	  V# )zMatch languages.FNlangr   htmlTZmetaz
http-equivzcontent-languager*  r   )r8  Zhead)r   rS   r   r   r   r   r   r   rN   NS_XMLrT   rU   r   rM   rd   r   rO   r7   r8   r;   r   r	   r   r   )r   rE   r6  r   Zhas_nsrS   r   rV   Z
found_langrg   r   r   r   Zattr_nsr   Zcacher
  r,   rm   Zchild2Zc_langr*  Zpatternsr   r"  r   
match_langZCSSMatch.match_lang  sC    ))+yy!44 
***62K,,V4 $ 4 4V ? K4;;;djjm\]bh5h{{w&7H15AQD)W[`ff "#J 5 D__V||_DF~%)%5%5d%;" $"7"7"7..8#!&qJ /
 t{{{7I7IddW[W`W`djWjE'!226\\2RE||E*c1d6F6Fu6M6M $!&	 S
 u ( u+$F!&#''22t||F7Kv7UZ^ZjZjkqZrZr!&"&$($8$8$@DA#zz!}<ARdAd)-#zz!}	9*+%v''-4
 $ 5 5 < <d3otTWYcOd=e f % %A "- % %))00$sD/21FG !!'G44Wd3
>STT $  ( u " r   c               rY   )r   rE   rI   directionalityr    r   r5   r   r   r   r   r   r     s&     9S 9SN 9SC 9SD 9Sr   c           	     s  a  V\         P                  ,          '       d    V\         P                  ,          '       d   R# Ve   S P                  V4      '       g   R# \        P                  \        P                  ! S P                  VRR4      4      R4      pVR9  d   W28H  # S P                  V4      pV'       d   Vf   \         P                  V8H  # S P                  V4      pVR8H  pVR8H  pVR8H  pV'       d(   \        P                  ! S P                  VRR4      4      MRp	V'       d   V	R	8X  d   Vf   \         P                  V8H  # V'       d   V	R9   g
   V'       Ed   V^ 8X  Ed   V'       d.   RP                  V 3R
 lS P                  VRR7       4       4      p
M!\        \        S P                  VRR4      4      p
V
'       dg   V
 FM  p\        P                   ! V4      pVR9   g   K"  VR8X  d   \         P                  M\         P                  pW28H  u # 	  \         P                  V8H  # V'       d   \         P                  V8H  # S P#                  S P%                  VRR7      V4      # V'       d   Ve   V^ 8X  dX   S P'                  V4      pVe   W28H  # V'       d   \         P                  V8H  # S P#                  S P%                  VRR7      V4      # S P#                  S P%                  VRR7      V4      # )zCheck directionality.FNr   r   r/  r   r   r/   telc              3  sZ   <"   T F   pSP                  V4      '       g   K  Vx  K"  	  R # 5ir   )rD   )Z.0ri   r   s   & r   Z	<genexpr>Z%CSSMatch.match_dir.<locals>.<genexpr>6  s$     w1VZ^ZpZpquZv1Vs   +
+Tr   r   r   )N    )r)  r%  r<  ZurlZemailr   )r   r   r   rO   r   r   r   rN   r   rX   r   r   r^   r	   r   r   r   	match_dirrT   r   )r   rE   r;  r   rX   rM   Zis_inputZis_textareaZis_bdir   r   r   r   s   f&&          r   r>  ZCSSMatch.match_dir  sm    BNN**~/N/N:T--b11 KK

4+E+Eb%QS+T UW[\	I%.. ,,r"y(>>^33 ||B7?j(JR

455b&"EFXZ9+<>>^33 %#LLQ\Q\bkopbpw1B1B2QU1B1VwwS$"<"<R""MNA&44Q7D//6:ckBNNr~~	(::	  ~~77~~77>>$//"/"E~VV y(Y!^r*I$ 22~~77>>$//"/"E~VV ~~doobDoA>RRr   c               rY   )r   rE   r   	conditionr    r   r5   r   r   r   r   r   r   Q  s&     &Q &Qg &Q# &Q$ &Qr   c                s   Rp\         P                  ! V P                  VR4      4      p\        P	                  V\        \        V P                  VRR4      4      4      p\        P	                  V\        \        V P                  VRR4      4      4      pVf   Vf   R# \        P	                  V\        \        V P                  VRR4      4      4      pVem   VR	9   d"   Ve	   Wu8  d   RpV'       g   Ve	   Wv8  d   RpMDVR8X  d>   Ve   Ve   WV8  d   Wu8  d	   Wv8  d   RpM Ve	   Wu8  d   RpV'       g   Ve	   Wv8  d   RpV\        P                  ,          '       d   V'       * # T# )
a3  
Match range.

Behavior is modeled after what we see in browsers. Browsers seem to evaluate
if the value is out of range, and if not, it is in range. So a missing value
will not evaluate out of range; therefore, value is in range. Personally, I
feel like this should evaluate as neither in or out of range.
Fr/   ZminNZmaxr   Tr   )r   r   r   r   r   r   )	r   rN   r   r   r   r	   r   r   SEL_IN_RANGE)r   rE   r?  Zout_of_ranger   ZmnZmxr   r   r   match_rangeZCSSMatch.match_rangeQ  s;    

455b&ABtC1K1KBPUW[1\']^tC1K1KBPUW[1\']^ :"*""5$sD4N4NrSZ\`4a*bcVV>ej#'L#5:#'L&>bnzej'+~%*'+'BNuz'+#,r#>#><PLPr   c               r   rR   r   r   r   r   r   r   y  s     
 
 
D 
r   c                s    V P                  V4      pVRJ;'       dL    VP                  R4      R8H  ;'       g0    VP                  R4      R8g  ;'       g    V P                  V4      RJ# )a  
Match defined.

`:defined` is related to custom elements in a browser.

- If the document is XML (not XHTML), all tags will match.
- Tags that are not custom (don't have a hyphen) are marked defined.
- If the tag has a prefix (without or without a namespace), it will not match.

This is of course requires the parser to provide us with the proper prefix and namespace info,
if it doesn't, there is nothing we can do.
Nr   r  rf   )r   Zfindr   r   r   r   match_definedZCSSMatch.match_definedy  sn     ||B  		#"$ 0 0		#"$0 0#4/		
r   c               r   rR   r   r   r   r   r   r     s      ' d r   c                s>    RpV P                  V4      pVR9   d   RpV# )z
Match placeholder shown according to HTML spec.

- text area should be checked if they have content. A single newline does not count as content.

FT)r   Z
)r   )r   rE   r   r*  rW   r   match_placeholder_shownZ CSSMatch.match_placeholder_shown  s)     --#j Er   c               rY   )r   rE   r   r   r   r   r5   r   r   r   r   r   r     s&     R R' Ro R$ Rr   c                s	   RpVP                   pVP                  pV'       d-   V P                  pV P                  pR\        /V n        RV n        V'       d   V P                  '       EdB   V EF:  pTp\        V\        P                  4      '       d   K(  V P                  WP                  4      '       g   KK  VP                  \        P                  ,          '       d   V P                  V4      '       g   K  VP                  \        P                  ,          '       d   V P                  V4      '       g   K  VP                  \        P                  ,          '       d   V P!                  V4      '       g   EK  VP                  \        P"                  ,          '       d   V P%                  V4      '       g   EKM  V P'                  WP(                  4      '       g   EKq  VP                  \        P*                  ,          '       d   V P-                  V4      '       g   EK  VP.                  '       d%   V P1                  WP.                  4      '       g   EK  VP2                  '       d%   V P5                  WP2                  4      '       g   EK  V P7                  WP8                  4      '       g   EKB  VP                  \:        ,          '       d0   V P=                  WP                  \:        ,          4      '       g   EK  VP>                  '       d%   V PA                  WP>                  4      '       g   EK  VPB                  '       d%   V PE                  WPB                  4      '       g   EK  VPF                  '       d%   V PI                  WPF                  4      '       g   EK0  VP                  \        PJ                  ,          '       d   V PM                  V4      '       g   EKq  VP                  \        PN                  ,          '       d   V PQ                  V4      '       g   EK  VP                  \R        ,          '       d0   V PU                  WP                  \R        ,          4      '       g   EK  VPV                  '       d%   V PY                  WPV                  4      '       g   EK4  V'       * p M	  V'       d   XV n        XV n        V# )z.Check if element matches one of the selectors.Fr8  T)-is_notrU   r   r   r   r7   r   r  r   r,   r   ZSEL_DEFINEDrB  ZSEL_ROOTr  Z	SEL_SCOPEr  ZSEL_PLACEHOLDER_SHOWNrC  r#  r  Z	SEL_EMPTYr&  r  r  r   r  r   r   RANGESrA  r7  r:  r   r'  r  r  ZSEL_DEFAULTr2  ZSEL_INDETERMINATEr5  	DIR_FLAGSr>  r(  r,  )	r   rE   r   r   rD  rU   r   r   Zselectorr+  r   r  ZCSSMatch.match_selectors  s    !!## J"22O%x0DO#'D $,,,%h88~~b,,77>>BNN224;M;Mb;Q;Q>>BKK//8K8K>>BLL009I9I"9M9M>>B$<$<<<TEaEabdEeEe~~b,,77>>BLL009I9I"9M9M<<<b,,(G(G###D,>,>rCSCS,T,T,,R1D1DEE>>F**43C3CBY_H_3`3`===]])K)K%%%d.E.EbJ\J\.].]$$$T-A-A"FWFW-X-X>>BNN224;M;Mb;Q;Q >>B$8$888AYAYZ\A]A]>>I--dnnRZcIc6d6d$$$T-@-@EVEV-W-W"
y &~ (DO#2D r   c               r   )r   limitr    r   rb   r   r   r   r   r   r     s      C (9 r   c              #  s   "   V^8  d   RMTpV P                  V P                  4       F9  pV P                  V4      '       g   K  Vx  Vf   K&  V^,          pV^8  g   K8   R# 	  R# 5i)z&Match all tags under the targeted tag.N)rk   r,   r   )r   rG  Zlimrm   rW   r   selectZCSSMatch.select  sY      aidU--dhh7Ezz%  ?1HCQw 8s   >A(A(A(!A(c               r   )r   r   rI   r   r   r   r   r   r      s     
 
 
r   c                s    V P                   pRpVf3   Ve/   V P                  V4      '       d   TpK#  V P                  V4      pK6  V# )Match closest ancestor.N)r,   r   rT   )r   Zcurrentclosests   &  r   rJ  ZCSSMatch.closest   sC     ((o'"5zz'""!//'2r   c               r   )r   r   list[bs4.Tag]r   r   r   r   r   r     s     
 
 
r   c                s    V P                  V P                  4       Uu. uF@  p\        V\        P                  4      '       g   K%  V P                  V4      '       g   K>  VNKB  	  up# u upi )zFilter tag's children.)r^   r,   r7   r8   r;   r   r   r,   r   r   filterZCSSMatch.filter  sX      ,,TXX6
6C#sww' ,0JJsO C6
 	
 
s   "A'A'A'c               r   rR   r   r   r   r   r   r     s     d d dD dr   c                s    V P                  V4      '       * ;'       d5    V P                  V4      ;'       d    V P                  WP                  4      # zMatch.)r:   r.   r  r   rP   r   r   r   ZCSSMatch.match  s?     ;;r?"cct{{2cc4;O;OPRTbTb;ccr   )r   r   r   r   r   r   rU   r   r   rS   r   r   r,   Nr   r=  ),r%   r&   r'   r(   r)   r   r   r   rO   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r  r  r  r  r#  r&  r'  r,  r2  r5  r:  r>  rA  rB  rC  r  rH  rJ  rM  r   r*   r   r   r   r   r     s    'BR6
/
RX#J6p3j*&

8.	4 

cJ8&P<|Tl9Sv&QP
.Rh

d dr   r   c                  s   a  ] tR tRt$ RtR]R&   R]R&   R]R&   R	]R
&   R]R&   RtR V 3R lltR R ltR R lt	R R lt
R R ltRR R lltRR R lltR R lt]tRtV ;t# ) 	SoupSievei  z-Compiled Soup Sieve selector matching object.r   r   r   r   r   r   zdict[str, str]customr    r   c          
     r   )r   r   r   r   r   r   r   rQ  zct.CustomSelectors | Noner   r    r   r   r   r   r   SoupSieve.__annotate__%  s<     
 

 #
 )	

 *
 
r   c                s0   < \         SV `  VVVVVR7       R# )r   )r   r   r   rQ  r   N)Zsuperr   )r   r   r   r   rQ  r   	__class__s   &&&&&&r   r   ZSoupSieve.__init__%  s&     	! 	 	
r   c               r   )r   r,   r   r   r5   r   r   r   r   r   rR  7  s     U U UT Ur   c                sv    \        V P                  WP                  V P                  4      P	                  V4      # rN  )r   r   r   r   r   rL  r   r   r   ZSoupSieve.match7  s+     __djjIOOPSTTr   c               r   r   r,   r   r   rI   r   r   r   r   r   rR  <  s     T T7 T~ Tr   c                st    \        V P                  WP                  V P                  4      P	                  4       # )rI  )r   r   r   r   rJ  rL  r   r   rJ  ZSoupSieve.closest<  s(     __djjIQQSSr   c               r   )r   iterablezIterable[bs4.Tag]r   rK  r   r   r   r   r   rR  A  s     n n0 n] nr   c                sN   \        V\        P                  4      '       d:   \        V P                  WP
                  V P                  4      P                  4       # V Uu. uF;  p\        P                  V4      '       d   K   V P                  V4      '       g   K9  VNK=  	  up# u upi )aY  
Filter.

`CSSMatch` can cache certain searches for tags of the same document,
so if we are given a tag, all tags are from the same document,
and we can take advantage of the optimization.

Any other kind of iterable could have tags from different documents or detached tags,
so for those, we use a new `CSSMatch` for each item in the iterable.
)
r7   r8   r;   r   r   r   r   rM  rB   r   )r   rU  ri   r   r   rM  ZSoupSieve.filterA  sr     h((DNNHootzzRYY[[%-mXTX5Q5QRV5WD\`\f\fgk\lDDXmmms   B" B"B"c               r   rT  r   r   r   r   r   rR  R  s     ) )g ). )r   c                sN    V P                  V^R7      pV'       d
   V^ ,          # R# )zSelect a single tag.)rG  N)rH  )r   r,   re   r   r   
select_oneZSoupSieve.select_oneR  s'     {{3a{(tAw(D(r   c               rY   )r   r,   r   rG  r    r   rK  r   r   r   r   r   rR  X  s!     . .' .# .m .r   c                s6    \        V P                  W4      4      # )zSelect the specified tags.)Zlistiselectr   r,   rG  r]   r   rH  ZSoupSieve.selectX  s     DLL,--r   c               rY   )r   r,   r   rG  r    r   rb   r   r   r   r   r   rR  ]  s'     \ \7 \3 \7H \r   c              #  s   "   \        V P                  WP                  V P                  4      P	                  V4       Rj  xL
  R#  L5i)zIterate the specified tags.N)r   r   r   r   rH  rX  r]   r   rW  ZSoupSieve.iselect]  s1      DNNC$**MTTUZ[[[s   >A	 AA	c               r   )r   r   r   r   r   r   r   r   rR  b  s     
 
# 
r   c           	     sx    RV P                   : RV P                  : RV P                  : RV P                  : R2	# )zRepresentation.zSoupSieve(pattern=z, namespaces=z	, custom=z, flags=Z))r   r   rQ  r   r"   r#   r   __repr__ZSoupSieve.__repr__b  s@     ! 0doo=P Qkk_HTZZN!=	
r   r   )r   r   r   rQ  r   Z_hashrO  )r%   r&   r'   r(   r)   Z__annotations__Z	__slots__r   r   rJ  rM  rV  rH  rW  rY  Z__str__r*   Z__classcell__)rS  s   @r   rP  rP    s_    7L$$JRI
 
$U
T
n").
\

 Gr   rP  )i   i   i	   i   );r)   Z
__future__r    r   r   r   Zrer   r   r   r8   Ztypingr   r   r   r   r   r	   Zcompiler$  r   r  r  r  r	  r  r  r  r  r   r9  r   r   rF  r@  ZSEL_OUT_OF_RANGErE  r   r   r   r   r   r   r   r   r   r   r   r   r   r   ZDAYS_IN_WEEKr   r+   r   r   Z	ImmutablerP  Zpickle_registerr   r   r   <module>rZ     s    "   	   
 I I I zz.)JJ'	 
     )	/NNR^^+		2..	. 
2>>	2>>
A 
G	H
**B
C::BC
**A
B
**S
Tjjk 

=>	
	" "(^
 ^
Bd dN@d| @dF P Pf   9 r   