Ë
    £ëie:  ã                   ór  — d Z ddlmZ ddlmZmZ ddlmZ ddlmZ ddl	Z	ddl
Z
ddlZdxZZi dd“d	d“d
d“dd“dd“dd“dd“dd“dd“dd“dd“dd“dd“dd“dd“dd“dd“dddœ¥Zg d¢ZddlmZmZmZ ddlmZmZ d„ Z G d „ d!«      Z G d"„ d#«      Z G d$„ d%«      Zdd&lmZ dd'lmZmZm Z m!Z! dd(l"m#Z#m$Z$ y))z~The Awesome Document Factory.

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

é    )Údatetime)ÚgetctimeÚgetmtime)ÚPath)ÚurljoinNz68.1ÚstylesheetsÚattachmentsÚattachment_relationshipsÚpdf_identifierÚpdf_variantÚpdf_versionÚ	pdf_formsÚpdf_tagsFÚuncompressed_pdfÚxmp_metadataÚ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é   )Ú
URLFetcherr#   Úselect_source)ÚLOGGERÚPROGRESS_LOGGERc                 ó®   — t        t        | j                  d«      «      d«      }|�.|j                  dd«      j                  «       }|rt	        ||«      S |S )zlReturn 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       úS/var/www/html/chat/reports/venv/lib/python3.12/site-packages/weasyprint/__init__.pyÚ_find_base_urlr5   e   sY   € ô œd =×#5Ñ#5°fÓ#=Ó>ÀÓEÐØÐ%Ø!×%Ñ% f¨bÓ1×7Ñ7Ó9ˆÙÜÐ,¨dÓ3Ð3ØÐó    c                   óF   — e Zd ZdZ	 	 	 d	d„Zd
d„Zd„ Zd„ Zdd„Z	 	 dd„Z	y)r   a3  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:
        An instance of :class:`urls.URLFetcher`. (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.

    Nc
           	      ó  — t        j                  d|xs |xs |xs t        |dd«      «       t        |t        «      rt        |«      }|€
t        «       }t        |||||||«      }
|
5 \  }}}}ddi}|�||d<   |�||d<   t        j                  |fi |¤Ž}
d d d «       t        |
|«      | _        || _        |	| _        t        j                  j!                  |
d ¬«      | _        | j"                  j$                  | _        y # 1 sw Y   ŒjxY w)	Nz'Step 1 - Fetching and parsing HTML - %sÚnamezHTML stringÚnamespace_html_elementsFÚtransport_encodingÚoverride_encoding)Úcontent_language)r(   ÚinfoÚgetattrÚ
isinstancer   Ústrr%   r&   Ú	tinyhtml5Úparser5   Úbase_urlÚurl_fetcherÚ
media_typeÚ
cssselect2ÚElementWrapperÚfrom_html_rootÚwrapper_elementÚetree_element)ÚselfÚguessÚfilenameÚurlÚfile_objÚstringÚencodingrD   rE   rF   ÚresultÚprotocol_encodingÚ_Úkwargss                 r4   Ú__init__zHTML.__init__Ÿ   s-  € ô 	×ÑØ5Øò 5�Xò 5 ò 5Ü�H˜f mÓ4ô	6ô �h¤Ô%Ü˜8“}ˆHØÐÜ$›,ˆKÜØ�8˜S (¨F°H¸kóKˆàð 	9ÑA˜ (Ð,=¸qØ/°Ð7ˆFØ Ð,Ø/@�Ð+Ñ,ØÐ#Ø.6�Ð*Ñ+Ü—_‘_ XÑ8°Ñ8ˆF÷	9ô ' v¨xÓ8ˆŒØ&ˆÔØ$ˆŒÜ)×8Ñ8×GÑGØ Tð  Hó  +ˆÔà!×1Ñ1×?Ñ?ˆÕ÷	9ð 	9ús   Á(.C?Ã?Dc                 ó,   — |rt         t        gS t         gS ©N)ÚHTML5_UA_STYLESHEETÚHTML5_UA_FORM_STYLESHEET)rL   Úformss     r4   Ú_ua_stylesheetszHTML._ua_stylesheetsº   s   € ÙÜ'Ô)AÐBÐBÜ#Ð$Ð$r6   c                 ó,   — t        j                  «       gS rY   )ÚHTML5_UA_COUNTER_STYLEÚcopy©rL   s    r4   Ú_ua_counter_stylezHTML._ua_counter_style¿   s   € Ü&×+Ñ+Ó-Ð.Ð.r6   c                 ó   — t         gS rY   )ÚHTML5_PH_STYLESHEETra   s    r4   Ú_ph_stylesheetszHTML._ph_stylesheetsÂ   s   € Ü#Ð$Ð$r6   c                 óî   — t        |«      t        t        «      z
  D ]  }t        j                  d|«       Œ t        j	                  «       }|j                  |«       |}t        j                  | ||||«      S )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'   Úwarningr`   Úupdater    Ú_render)rL   Úfont_configÚcounter_styleÚcolor_profilesÚoptionsÚunknownÚnew_optionss          r4   ÚrenderzHTML.renderÅ   ss   € ô( ˜7“|¤c¬/Ó&:Ñ:ò 	EˆGÜ�N‰NÐ:¸GÕDð	Eä%×*Ñ*Ó,ˆØ×Ñ˜7Ô#ØˆÜ×ÑØ�+˜}¨n¸góGð 	Gr6   c                 ó    — t         j                  «       }|j                  |«       |}  | j                  |||fi |¤Žj                  |||fi |¤ŽS )aE  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   r`   ri   rq   Ú	write_pdf)	rL   ÚtargetÚzoomÚfinisherrk   rl   rm   rn   rp   s	            r4   rs   zHTML.write_pdfá   s^   € ôJ &×*Ñ*Ó,ˆØ×Ñ˜7Ô#ØˆðˆKˆD�K‰K˜ ]°NÑNÀgÑNß‰Y�v˜t Xñ:Ø18ñ:ð	;r6   )	NNNNNNNNÚprint)F)NNN)Nr$   NNNN)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__rW   r]   rb   re   rq   rs   © r6   r4   r   r   s   s=   „ ñ*ðV FJØ6:Ø.5ó@ó6%ò
/ò%óGð8 7;ØGKô*;r6   r   c                   ó"   — e Zd ZdZ	 	 	 	 	 dd„Zy)r   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.

    Nc                 ób  — t        j                  d|xs |xs t        |dd«      «       |€
t        «       }t	        ||||||||	¬«      }|5 \  }}}}|j                  «       }t        |t        «      rt        j                  |«      }nt        j                  |||¬«      \  }}d d d «       || _        |xs t        j                  «       | _        |€g n|| _        |€g n|| _        |€i n|}|€i n|}t#        |
||| j                  | j                  | j                   ||||¬«       y # 1 sw Y   Œ„xY w)Nz&Step 2 - Fetching and parsing CSS - %sr9   z
CSS string)rD   rE   Úcheck_css_mime_type)Úenvironment_encodingrT   )Úlayer)r(   r>   r?   r%   r&   Úreadr@   rA   Útinycss2Úparse_stylesheetÚparse_stylesheet_bytesrD   rG   ÚMatcherÚmatcherÚ
page_rulesÚlayersÚpreprocess_stylesheet)rL   rM   rN   rO   rP   rQ   rR   rD   rE   Ú_check_mime_typerF   rk   rl   rm   r‡   rˆ   r‰   r�   rS   rT   Ú	mime_typeÚcssÚ
stylesheetrU   s                           r4   rW   zCSS.__init__  s>  € ô
 	×ÑØ4ØÒF˜ÒFœw x°¸ÓFô	Hð ÐÜ$›,ˆKÜØ�8˜S (¨F¸XØ#Ð9IôKˆð ð 	9ÑI˜ (Ð,=¸yØ—-‘-“/ˆCÜ˜#œsÔ#Ü%×6Ñ6°sÓ;‘
ä (× ?Ñ ?Ø¨hØ&7ô!9‘�
˜A÷	9ð !ˆŒØÒ6¤*×"4Ñ"4Ó"6ˆŒØ *Ð 2™"¸
ˆŒØ"˜N‘b°ˆŒØ+Ð3™¸ˆØ-Ð5™¸>ˆÜØ˜ *¨k¸4¿<¹<Ø�O‰O˜TŸ[™[¨+°}ÀnØö	÷	9ð 	9ús   ÁAD%Ä%D.)NNNNNNNNFrw   NNNNNNN©rx   ry   rz   r{   rW   r|   r6   r4   r   r     s   „ ñð SWØRWØEIØLPØô	r6   r   c                   ó    — e Zd ZdZ	 	 	 	 dd„Zy)r   a¿  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.

    Nc           	      óz  — |€
t        «       }t        |||||||¬«      | _        || _        |	| _        || _        d | _        |
€5|rt        j                  t        |«      «      }
nt        j                  «       }
|€5|rt        j                  t        |«      «      }nt        j                  «       }|
| _        || _        y )N)rD   rE   )r%   r&   Úsourcer9   ÚdescriptionÚrelationshipÚmd5r   Úfromtimestampr   Únowr   ÚcreatedÚmodified)rL   rM   rN   rO   rP   rQ   rD   rE   r9   r“   r˜   r™   r”   s                r4   rW   zAttachment.__init__W  s¬   € ð ÐÜ$›,ˆKÜ#Ø�8˜S (¨F¸XØ#ô%ˆŒð ˆŒ	Ø&ˆÔØ(ˆÔØˆŒàˆ?ÙÜ"×0Ñ0´¸(Ó1CÓD‘ä"Ÿ,™,›.�ØÐÙÜ#×1Ñ1´(¸8Ó2DÓE‘ä#Ÿ<™<›>�ØˆŒØ ˆ�r6   )NNNNNNNNNNNÚUnspecifiedr�   r|   r6   r4   r   r   >  s   „ ñð0 FJØDHØ:>Ø+ô!r6   r   )rŠ   )r_   rZ   r[   rd   )r    r!   )%r{   r   Úos.pathr   r   Úpathlibr   Úurllib.parser   rG   rƒ   rB   r   r"   r   Ú__all__Úurlsr%   r#   r&   Úloggerr'   r(   r5   r   r   r   r�   rŠ   Úhtmlr_   rZ   r[   rd   Údocumentr    r!   r|   r6   r4   ú<module>r£      sZ  ðñõ ß &Ý Ý  ã Û Û àÐ €ˆ+ðdØ�4ðà�4ðð  ðð �dð	ð
 �4ðð �4ðð �ðð �ðð ˜ðð �Dðð �uðð ˜Eðð ˆEðð �uðð �Dðð  
ˆ4ð!ð" �%ð#ð$ Øò'€ò,*€÷ AÑ @ß +ò
÷X;ñ X;÷v-ñ -÷`2!ñ 2!õl '÷ó ÷ %Ð $r6   