
    BhF-                        S r SSKrSSKJr  SSKJr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SKJr  \
" 5       r\" \5      S-  R)                  S5      r\" \5      S-  R)                  S5      r\" \5      S-  R)                  S5      r\" \\S9r\" \\S9r\" \S9rSr\R8                  " S\ S35      rS rS r0 r S r!S r"S r#\"" S5      S 5       r$\"" S5      S 5       r%\"" S5      S 5       r&\"" S 5      S! 5       r'\"" S"5      S# 5       r(\"" S$5      S% 5       r)S& r*S' r+\R8                  " S(\RX                  5      r-S) r.g)*aV  Specific handling for some HTML elements, especially replaced elements.

Replaced elements (eg. <img> elements) are rendered externally and behave as an
atomic opaque box in CSS. In general, they may or may not have intrinsic
dimensions. But the only replaced elements currently supported in WeasyPrint
are images with intrinsic dimensions.

    N)files   )CSS
Attachmentcss)get_child_text)CounterStyle)boxes)SVGImage)LOGGER)get_url_attributezhtml5_ua.csszutf-8zhtml5_ua_form.csszhtml5_ph.css)stringcounter_styler   z 	
z[^z]+c                 Z    U R                  5       R                  5       R                  5       $ )a  Transform (only) ASCII letters to lower case: A-Z is mapped to a-z.

This is used for `ASCII case-insensitive
<https://whatwg.org/C#ascii-case-insensitive>`_ matching.

This is different from the :meth:`str.lower` method of Unicode strings
which also affect non-ASCII characters,
sometimes mapping them into the ASCII range:

>>> keyword = 'Bac\N{KELVIN SIGN}ground'
>>> assert keyword.lower() == 'background'
>>> assert ascii_lower(keyword) != keyword.lower()
>>> assert ascii_lower(keyword) == 'bac\N{KELVIN SIGN}ground'

)encodelowerdecoder   s    A/var/www/html/env/lib/python3.13/site-packages/weasyprint/html.pyascii_lowerr   $   s"    " ==?  "))++    c                 x   ^ [         R                  U R                  SS5      5      n[        U4S jU 5       5      $ )zDReturn whether element has a ``rel`` attribute with given link type.rel c              3   @   >#    U  H  n[        U5      T:H  v   M     g 7f)N)r   ).0token	link_types     r   	<genexpr>(element_has_link_type.<locals>.<genexpr>;   s     CF5{5!Y.Fs   )HTML_SPACE_SEPARATED_TOKENS_REfindallgetany)elementr   tokenss    ` r   element_has_link_typer'   8   s/    +33GKKr4JKFCFCCCr   c                 d    UR                   [        ;   a  [        U R                     " XX#5      $ U/$ )zZHandle HTML elements that need special care.

:returns: a (possibly empty) list of boxes.
)element_tagHTML_HANDLERStag)r%   boxget_image_from_uribase_urls       r   handle_elementr/   B   s5    
 -'W[[),8 	8 ur   c                    ^  U 4S jnU$ )zDReturn a decorator registering a function handling ``tag`` elements.c                    > U [         T'   U $ )z;Decorator registering a function handling ``tag`` elements.)r*   )functionr+   s    r   	decoratorhandler.<locals>.decoratorP   s    %cr    )r+   r3   s   ` r   handlerr6   N   s     r   c                     SUR                   S   ;   a  [        R                  O[        R                  nU" U R                  UR                   X5      nUR
                  Ul        UR                  Ul        U$ )z|Wrap an image in a replaced box.

That box is either block-level or inline-level, depending on what the
element should be.

blockdisplay)styler
   BlockReplacedBoxInlineReplacedBoxr+   
string_setbookmark_label)r%   r,   imagetype_new_boxs        r   make_replaced_boxrB   W   sd     #*SYYy-A"A$$ 
 GKKG;G G //GNr   imgc                 p   [        U SU5      nU R                  S5      nU(       aa  U" XAR                  S   S9nUb  [        XU5      /$ U(       a(  [        R
                  R                  X5      /Ul        U/$ US:X  a  / $ Ub   e/ $ U(       a(  [        R
                  R                  X5      /Ul        U/$ / $ )zHandle ``<img>`` elements.

Return either an image or the alt-text.

See: https://www.w3.org/TR/html5/embedded-content-1.html#the-img-element

srcaltimage_orientation)urlorientationr   )r   r#   r:   rB   r
   TextBoxanonymous_fromchildren)r%   r,   r-   r.   rE   rF   r?   s          r   
handle_imgrM   i   s     GUH
5C
++e
C
"+>!?A%gE:;;  % < <S FGu	{"{ 	!MM88BCCL5LIr   embedc                     [        U SU5      nU R                  SS5      R                  5       nU(       a$  U" XEUR                  S   S9nUb  [	        XU5      /$ / $ )zHandle ``<embed>`` elements, return either an image or nothing.

See: https://www.w3.org/TR/html5/embedded-content-0.html#the-embed-element

rE   typer   rG   rH   forced_mime_typerI   r   r#   stripr:   rB   )r%   r,   r-   r.   rE   r@   r?   s          r   handle_embedrU      se     GUH
5CKK#))+E
"		"568 %gE:;;Ir   objectc                     [        U SU5      nU R                  SS5      R                  5       nU(       a$  U" XEUR                  S   S9nUb  [	        XU5      /$ U/$ )zHandle ``<object>`` elements, return either an image or the fallback.

See: https://www.w3.org/TR/html5/embedded-content-0.html#the-object-element

datarP   r   rG   rQ   rS   )r%   r,   r-   r.   rX   r@   r?   s          r   handle_objectrY      sg     Wfh7DKK#))+E"		"568 %gE:;;5Lr   colgroupc                    [        U[        R                  5      (       a`  [        S U  5       5      (       dI  [	        UR
                  5       Vs/ s H#  n[        R                  R                  U/ 5      PM%     snUl        U/$ s  snf )Handle the ``span`` attribute.c              3   >   #    U  H  oR                   S :H  v   M     g7f)colN)r+   )r   childs     r   r   "handle_colgroup.<locals>.<genexpr>   s     ;7%99%7s   )	
isinstancer
   TableColumnGroupBoxr$   rangespanTableColumnBoxrK   rL   )r%   r,   _get_image_from_uri	_base_url_s        r   handle_colgroupri      sr     #u0011;7;;; sxx*(A $$33C<(*CL 5L*s   *Br^   c                     [        U[        R                  5      (       aC  UR                  S:  a3  [	        UR                  5       Vs/ s H  oAR                  5       PM     sn$ U/$ s  snf )r\   r   )ra   r
   re   rd   rc   copy)r%   r,   rf   rg   _is        r   
handle_colrm      sP     #u++,,A &+388_5_r
_555L 6s   A&z{http://www.w3.org/2000/svg}svgc                     UR                   S   nUR                   S   n [        XXE5      n[        XU5      /$ ! [         a8  n[        R
                  " SU5        [        R                  " SUS9  / s SnA$ SnAff = f)zMHandle ``<svg>`` elements.

Return either an image or the fallback content.

url_fetchercontextzFailed to load inline SVG: %szError while loading inline SVG:)exc_infoN)keywordsr   rB   	Exceptionr   errordebug)r%   r,   r-   r.   ro   rp   r?   	exceptions           r   
handle_svgrw      s|     %--m<K )))4G8KA "'677  4i@6K	s   9 
A;-A60A;6A;c                 b   SnSnSn/ n/ nSnSn/ n0 n	U R                   R                  R                  SS5      n
U R                  R	                  SSS5       GH  nUR                   nUR
                  S:X  a  Uc  [        U5      nM0  UR
                  S:X  a  [        UR                  SS5      5      nUR                  SS5      nUS	:X  a@  [        [        UR                  S
5      5       H  nX;  d  M
  UR                  U5        M     M  US:X  a  UR                  U5        M  US:X  a	  Uc  UnM  M  US:X  a	  Uc  UnM  M  US:X  a  Uc  [        X5      nGM  GM  US:X  a  Uc  [        X5      nGM  GM  U(       a  X;  a  XU'   GM1  GM4  GM7  UR
                  S:X  d  GMJ  [        US5      (       d  GM^  [        USU R                  5      nUR                  SS5      nUc  [         R"                  " S5        GM  [%        UUU R&                  S9nUR                  U5        GM     UUUUUUUUU
U	S.
$ )a  Get metadata dictionary out of HTML object.

Relevant specs:

https://www.whatwg.org/html#the-title-element
https://www.whatwg.org/html#standard-metadata-names
https://wiki.whatwg.org/wiki/MetaExtensions
https://microformats.org/wiki/existing-rel-values#HTML5_link_type_extensions

Nlangtitlemetalinknamer   contentrr   ,authordescription	generatorzdcterms.createdzdcterms.modified
attachmenthrefz'Missing href in <link rel="attachment">)rH   r   ro   )
rz   r   r   rr   authorscreatedmodifiedattachmentsry   custom)etree_elementattribr#   wrapper_element	query_allr+   r   r   mapstrip_whitespacesplitappendparse_w3c_dater'   r   r.   r   rt   r   ro   )htmlrz   r   r   rr   r   r   r   r   r   ry   r%   r}   r~   keywordrH   attachment_titler   s                     r   get_html_metadatar      s:    EKIHGGHKF$$((6D''11'66J'';;'!em"7+E[[F"w{{6267Dkk)R0Gz!"#3W]]35GHG. 0  I !w'&&")K '$$ 'I %**?,T;G #++#-d<H $$,&t -[[F"'<(' ('#GVT]]CC&{{7D9{FG')9 $ 0 02
 "":.K KN "" r   c                 ,    U R                  [        5      $ )zUse the HTML definition of "space character",
not all Unicode Whitespace.

https://www.whatwg.org/html#strip-leading-and-trailing-whitespace
https://www.whatwg.org/html#space-character

)rT   HTML_WHITESPACEr   s    r   r   r   &  s     <<((r   aG  
    ^
    [ 	
]*
    (?P<year>\d\d\d\d)
    (?:
        -(?P<month>0\d|1[012])
        (?:
            -(?P<day>[012]\d|3[01])
            (?:
                T(?P<hour>[01]\d|2[0-3])
                :(?P<minute>[0-5]\d)
                (?:
                    :(?P<second>[0-5]\d)
                    (?:\.\d+)?  # Second fraction, ignored
                )?
                (?:
                    Z |  # UTC
                    (?P<tz_hour>[+-](?:[01]\d|2[0-3]))
                    :(?P<tz_minute>[0-5]\d)
                )
            )?
        )?
    )?
    [ 	
]*
    $
c                 j    [         R                  U5      (       a  U$ [        R                  " SX5        g)zQParse datetimes as defined by the W3C.

See https://www.w3.org/TR/NOTE-datetime

z#Invalid date in <meta name="%s"> %rN)W3C_DATE_REmatchr   warning)	meta_namer   s     r   r   r   T  s,       19	Fr   )/__doc__reimportlib.resourcesr   r   r   r   r   r   css.countersr	   formatting_structurer
   imagesr   loggerr   urlsr   HTML5_UA_COUNTER_STYLE	read_textHTML5_UAHTML5_UA_FORMHTML5_PHHTML5_UA_STYLESHEETHTML5_UA_FORM_STYLESHEETHTML5_PH_STYLESHEETr   compiler!   r   r'   r*   r/   r6   rB   rM   rU   rY   ri   rm   rw   r   r   VERBOSEr   r   r5   r   r   <module>r      s   
 % " "  & '   #% #J'227;s11<<WE#J'227;#9; (>@ *  !#b0A,D!E ,(D 	$ 	! !H 	 $ 	 $ 	  	  		*+8 ,8&FR)$ jj 2 ZZ38
Fr   