
    BhD              	          S r SSKrSSKJr  SSKJrJr  SSKJr  SSKJ	r	  SSK
r
SSKrSSKrS=rr0 SS_S	S
_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_r/ SQrSSKJrJrJrJrJr  SSKJrJr  S r " S  S!5      r " S" S#5      r " S$ S%5      r\R<                  SSSSSS\S4S& j5       rSS'K J!r!  SS(K"J#r#J$r$J%r%J&r&  SS)K'J(r(J)r)  g)*z~The Awesome Document Factory.

The public API is what is accessible from this "root" packages without
importing sub-modules.

    N)datetime)getctimegetmtime)Path)urljoinz65.1stylesheets
media_typeprintattachmentspdf_identifierpdf_variantpdf_version	pdf_formsuncompressed_pdfFcustom_metadatapresentational_hintssrgboptimize_imagesjpeg_qualitydpi
full_fontshintingcache)	CSSDEFAULT_OPTIONSHTMLVERSION
AttachmentDocumentPage__version__default_url_fetcher   )fetchr"   path2url
ensure_urlurl_is_absolute)LOGGERPROGRESS_LOGGERc                     [        [        U R                  S5      5      S5      nUb2  UR                  SS5      R                  5       nU(       a  [	        X5      $ U$ )zdReturn the base URL for the document.

See https://www.w3.org/TR/html5/urls.html#document-base-url

baseNhref )nextitergetstripr   )html_documentfallback_base_urlfirst_base_elementr,   s       E/var/www/html/env/lib/python3.13/site-packages/weasyprint/__init__.py_find_base_urlr6   c   sW     d=#5#5f#=>E%!%%fb1779,33    c            	       b    \ rS rSrSrSSSSSSS\S4	S jrSS jrS rS r	SS	 jr
  SS
 jrSrg)r   q   a  HTML document parsed by tinyhtml5.

You can just create an instance with a positional argument:
``doc = HTML(something)``
The class will try to guess if the input is a filename, an absolute URL,
or a :term:`file object`.

Alternatively, use **one** named argument so that no guessing is involved:

:type filename: str or pathlib.Path
:param filename:
    A filename, relative to the current directory, or absolute.
:param str url:
    An absolute, fully qualified URL.
:type file_obj: :term:`file object`
:param file_obj:
    Any object with a ``read`` method.
:param str string:
    A string of HTML source.

Specifying multiple inputs is an error:
``HTML(filename="foo.html", url="localhost://bar.html")``
will raise a :obj:`TypeError`.

You can also pass optional named arguments:

:param str encoding:
    Force the source character encoding.
:type base_url: str or pathlib.Path
:param base_url:
    The base used to resolve relative URLs (e.g. in
    ``<img src="../foo.png">``). If not provided, try to use the input
    filename, URL, or ``name`` attribute of
    :term:`file objects <file object>`.
:type url_fetcher: :term:`callable`
:param url_fetcher:
    A function or other callable with the same signature as
    :func:`default_url_fetcher` called to fetch external resources such as
    stylesheets and images. (See :ref:`URL Fetchers`.)
:param str media_type:
    The media type to use for ``@media``. Defaults to ``'print'``.
    **Note:** In some cases like ``HTML(string=foo)`` relative URLs will be
    invalid if ``base_url`` is not provided.

Nr
   c
           	      t   [         R                  " SU=(       d    U=(       d    U=(       d    [        USS5      5        [        U[        5      (       a  [        U5      n[        XX4XWU5      n
U
 u  pp}[        U[
        5      (       a  [        R                  " USS9n
O)SS0nUb  XS'   Ub  XnS'   [        R                  " U40 UD6n
S S S 5        [        X5      U l
        Xl        Xl        [        R                  R                  U
S S	9U l        U R                   R"                  U l        g ! , (       d  f       Ni= f)
Nz'Step 1 - Fetching and parsing HTML - %snamezHTML stringF)namespace_html_elementsr<   transport_encodingoverride_encoding)content_language)r)   infogetattr
isinstancer   str_select_source	tinyhtml5parser6   base_urlurl_fetcherr	   
cssselect2ElementWrapperfrom_html_rootwrapper_elementetree_element)selfguessfilenameurlfile_objstringencodingrG   rH   r	   resultsource_typesourceprotocol_encodingkwargss                  r5   __init__HTML.__init__   s#    	5 5X 5 5Hfm4	6 h%%8}HSFkKIX&#&&"O3U;$03D/0'2:./":6:  'v8&$)88GGT  H  +!11?? Vs   .AD))
D7c                 6    U(       a  [         [        /$ [         /$ N)HTML5_UA_STYLESHEETHTML5_UA_FORM_STYLESHEET)rN   formss     r5   _ua_stylesheetsHTML._ua_stylesheets   s    ')ABB#$$r7   c                 .    [         R                  " 5       /$ r]   )HTML5_UA_COUNTER_STYLEcopyrN   s    r5   _ua_counter_styleHTML._ua_counter_style   s    &++-..r7   c                     [         /$ r]   )HTML5_PH_STYLESHEETrf   s    r5   _ph_stylesheetsHTML._ph_stylesheets   s    #$$r7   c                     [        U5      [        [        5      -
   H  n[        R                  " SU5        M     [        R	                  5       nUR                  U5        Un[        R                  " XX#5      $ )a  Lay out and paginate the document, but do not (yet) export it.

This returns a :class:`document.Document` object which provides
access to individual pages and various meta-data.
See :meth:`write_pdf` to get a PDF directly.

:type font_config: :class:`text.fonts.FontConfiguration`
:param font_config:
    A font configuration handling ``@font-face`` rules.
:type counter_style: :class:`css.counters.CounterStyle`
:param counter_style:
    A dictionary storing ``@counter-style`` rules.
:param options:
    The ``options`` parameter includes by default the
    :data:`DEFAULT_OPTIONS` values.
:returns: A :class:`document.Document` object.

zUnknown rendering option: %s.)setr   r(   warningre   updater   _render)rN   font_configcounter_styleoptionsunknownnew_optionss         r5   renderHTML.render   s_    & 7|c/&::GNN:GD ;%**,7#=JJr7   c                     [         R                  5       nUR                  U5        UnU R                  " XE40 UD6R                  " XU40 UD6$ )aM  Render the document to a PDF file.

This is a shortcut for calling :meth:`render`, then
:meth:`Document.write_pdf() <document.Document.write_pdf>`.

:type target:
    :class:`str`, :class:`pathlib.Path` or :term:`file object`
:param target:
    A filename where the PDF file is generated, a file object, or
    :obj:`None`.
:param float zoom:
    The zoom factor in PDF units per CSS units.  **Warning**:
    All CSS units are affected, including physical units like
    ``cm`` and named sizes like ``A4``.  For values other than
    1, the physical CSS units will thus be "wrong".
:type finisher: :term:`callable`
:param finisher:
    A finisher function or callable that accepts the document and a
    :class:`pydyf.PDF` object as parameters. Can be passed to perform
    post-processing on the PDF right before the trailer is written.
:type font_config: :class:`text.fonts.FontConfiguration`
:param font_config:
    A font configuration handling ``@font-face`` rules.
:type counter_style: :class:`css.counters.CounterStyle`
:param counter_style:
    A dictionary storing ``@counter-style`` rules.
:param options:
    The ``options`` parameter includes by default the
    :data:`DEFAULT_OPTIONS` values.
:returns:
    The PDF as :obj:`bytes` if ``target`` is not provided or
    :obj:`None`, otherwise :obj:`None` (the PDF is written to
    ``target``).

)r   re   rp   rw   	write_pdf)rN   targetzoomfinisherrr   rs   rt   rv   s           r5   rz   HTML.write_pdf   sX    J &**,7#KK>g>YX:18:	;r7   )rG   rM   r	   rH   rL   )F)NN)Nr#   NNN)__name__
__module____qualname____firstlineno____doc__r"   rZ   ra   rg   rk   rw   rz   __static_attributes__ r7   r5   r   r   q   sG    ,Z "DdTtd0W@8%
/%K4 7;26*;r7   r   c                   >    \ rS rSrSrSSSSSSS\SSSSSS4S jrSrg)r   i  a  CSS stylesheet parsed by tinycss2.

An instance is created in the same way as :class:`HTML`, with the same
arguments.

An additional argument called ``font_config`` must be provided to handle
``@font-face`` rules. The same ``text.fonts.FontConfiguration`` object
must be used for different ``CSS`` objects applied to the same document.

``CSS`` objects have no public attributes or methods. They are only meant
to be used in the :meth:`HTML.write_pdf` and :meth:`HTML.render` methods
of :class:`HTML` objects.

NFr
   c                 <   [         R                  " SU=(       d    U=(       d    [        USS5      5        [        XX4UXxU	S9nU u  nnnnUS:X  a  UR	                  5       n[        U[        5      (       a  [        R                  " U5      nO[        R                  " UUUS9u  nnS S S 5        Xpl
        U=(       d    [        R                  " 5       U l        Uc  / OUU l        Uc  0 OUn[        XWXR                  U R                  X5        g ! , (       d  f       Nn= f)Nz&Step 2 - Fetching and parsing CSS - %sr;   z
CSS stringrG   rH   check_css_mime_typerR   )environment_encodingrX   )r)   r@   rA   rD   readrB   rC   tinycss2parse_stylesheetparse_stylesheet_bytesrG   rI   Matchermatcher
page_rulespreprocess_stylesheet)rN   rO   rP   rQ   rR   rS   rT   rG   rH   _check_mime_typer	   rr   rs   r   r   rU   rV   rW   rX   
stylesheets                       r5   rZ   CSS.__init__  s   
 	4FFwxF	H  SF 02 IVX7Hj(&#&&%66v>
'/'F'F&7(9$
H  !6*"4"4"6 * 2"
+3*k<<OO[	9 Vs   A!D
D)rG   r   r   r   r   r   r   r   r"   rZ   r   r   r7   r5   r   r     s/     "DdTtd05#T$	9r7   r   c                   :    \ rS rSrSrSSSSSS\SSSSS4S jrSrg)r   i;  ao  File attachment for a PDF document.

An instance is created in the same way as :class:`HTML`, except that the
HTML specific arguments (``encoding`` and ``media_type``) are not
supported.

:param str name:
    The name of the attachment to be included in the PDF document.
    May be :obj:`None`.
:param str description:
    A description of the attachment to be included in the PDF document.
    May be :obj:`None`.
:type created: :obj:`datetime.datetime`
:param created:
    Creation date and time. Default is current date and time.
:type modified: :obj:`datetime.datetime`
:param modified:
    Modification date and time. Default is current date and time.
:param str relationship:
    A string that represents the relationship between the attachment and
    the PDF it is embedded in. Default is 'Unspecified', other common
    values are defined in ISO-32000-2:2020, 7.11.3.

NUnspecifiedc           
      l   [        XX4XVUS9U l        Xl        Xl        Xl        S U l        U
c<  U(       a   [        R                  " [        U5      5      n
O[        R                  " 5       n
Uc<  U(       a   [        R                  " [        U5      5      nO[        R                  " 5       nXl        Xl        g )N)rG   rH   )rD   rW   r;   descriptionrelationshipmd5r   fromtimestampr   nowr   createdmodified)rN   rO   rP   rQ   rR   rS   rG   rH   r;   r   r   r   r   s                r5   rZ   Attachment.__init__T  s     %SF#% 	&(?"00(1CD",,.#11(82DE#<<> r7   )r   r   r   r   r;   r   rW   r   r   r7   r5   r   r   ;  s+    0 "DdTt9LdT+!r7   r   c              #     #    Ub  [        U5      nXX#U4 Vs/ s H
  nUc  M  UPM     n	n[        U	5      S:w  a(  SR                  U	5      =(       d    Sn
[        SU
 35      eU b`  [	        U S5      (       a  SnO-[        U [        5      (       a  SnO[        U 5      (       a  S	nOSn[        SXVUS
.X0D6nU nUv   SSS5        gUb+  Uc  [        U5      n[        US5       nSX5S4v   SSS5        gUb  [        Xb5       nU(       a0  US   S:w  a'  [        R                  " SUS   US   5        SSUS4v   OBUR                  S5      nUc  UR                  SU5      nSU;   a  SUS   X]4v   OSUS   UU4v   SSS5        gUb@  Uc5  [        USS5      nU(       a!  UR!                  S5      (       d  [        U5      nSX5S4v   gUc   eSXES4v   gs  snf ! , (       d  f       g= f! , (       d  f       g= f! , (       d  f       g= f7f)zCIf only one input is given, return it with normalized ``base_url``.Nr#   z, nothingz!Expected exactly one source, got r   rR   rP   rQ   r   rb	mime_typeztext/cssz%Unsupported stylesheet type %s for %sredirected_urlrS   r-   rT   r;   <r   )r&   lenjoin	TypeErrorhasattrrB   r   r'   rD   r%   openr$   r(   errorr0   rA   
startswith)rO   rP   rQ   rR   rS   rG   rH   r   paramselected_paramsrW   type_rU   proto_encodingr;   s                  r5   rD   rD   n  sO    
 h' "SFCC% 	C   ?q ?+8y;F8DEE		5&!!Et$$EU##EE  3 n vL V		)H(D!Xh$66 "!	;$"vk':j'H;;'0@)AC Hd22!'J!7#%zz*:C@Hv%"F8$4hNN #F:$6&( ( %$  
	8VT2DDOOC00%d+(d22!!!$..k& V
 "! %$s_   HGGBH7G<&H"G**HA:G;;AH
G'#H*
G84H;
H	H)r   )rd   r^   r_   rj   )r   r    )*r   
contextlibr   os.pathr   r   pathlibr   urllib.parser   rI   r   rE   r   r!   r   __all__urlsr$   r"   r%   r&   r'   loggerr(   r)   r6   r   r   r   contextmanagerrD   cssr   htmlrd   r^   r_   rj   documentr   r    r   r7   r5   <module>r      s     &       +`4' 4 d	
 4 4   u E E u D 
4 %  u!" T#(*G G +
Y; Y;x+9 +9\0! 0!f $;N',</ </~ '  % $r7   