
    3vjS:                     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69.0stylesheetsattachmentsattachment_relationshipspdf_identifierpdf_variantpdf_version	pdf_formspdf_tagsFuncompressed_pdfxmp_metadatacustom_metadatapresentational_hintsoutput_intent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       F/root/.hermes/venv/lib/python3.12/site-packages/weasyprint/__init__.py_find_base_urlr5   d   sY     d=#5#5f#=>E%!%%fb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 5X 5 5Hfm4	6 h%8}H$,K8S(FHkK 	9A(,=q/7F ,/@+,#.6*+__X88F	9 'vx8&$)88GGT  H  +!11??	9 	9s   (.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NN:GD	E%**,7#+}ng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#KDKK]NNgNYvtX:18:	;r6   )	NNNNNNNNprint)F)NNN)Nr$   NNNN)
__name__
__module____qualname____doc__rW   r]   rb   re   rq   rs    r6   r4   r   r   r   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FwxF	H $,K8S(FX#9IK  	9I(,=y--/C#s#%66s;
 ( ? ?h&7!9
A	9 !6*"4"4"6 * 2"
"Nb+3-5>*k4<<OOT[[+}n		9 	9s   AD%%D.)NNNNNNNNFrw   NNNNNNNrx   ry   rz   r{   rW   r|   r6   r4   r   r     s     SWRWEILP	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__V  s     $,K#8S(FX#% 	&(?"00(1CD",,.#11(82D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    &       +b44  d	
 4 4    D u E T u D  
4!" %#$ ',* A @ +
X; X;v- -`2! 2!l '  % $r6   