
    ,gD              	          d Z ddl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Zg dZddlmZmZ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ej<                  ddddddedf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.

    N)datetime)getctimegetmtime)Path)urljoinz65.0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                     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       k/home/viktor/gitlab-persoonlijk/factuur-applicatie/venv/lib/python3.12/site-packages/weasyprint/__init__.py_find_base_urlr6   c   sY     d=#5#5f#=>E%!%%fb1779,d33    c            	       R    e Zd ZdZdddddddedf	dZd
dZd Zd ZddZ		 	 dd	Z
y)r   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
           	      N   t        j                  d|xs |xs |xs t        |dd             t        |t              rt        |      }t        |||||||      }
|
5 \  }}}}t        |t
              rt        j                  |d      }
n(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 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encodingrF   rG   r	   resultsource_typesourceprotocol_encodingkwargss                  r5   __init__zHTML.__init__   s:    	5 5X 5 5Hfm4	6 h%8}H8S(FHkK 		;IVX7H&#&"O3U;$03DF/0'2:F./":6:		; 'vx8&$)88GGT  H  +!11??		; 		;s   ADD$c                 ,    |rt         t        gS t         gS N)HTML5_UA_STYLESHEETHTML5_UA_FORM_STYLESHEET)rM   formss     r5   _ua_stylesheetszHTML._ua_stylesheets   s    ')ABB#$$r7   c                 ,    t        j                         gS r[   )HTML5_UA_COUNTER_STYLEcopyrM   s    r5   _ua_counter_stylezHTML._ua_counter_style   s    &++-..r7   c                     t         gS r[   )HTML5_PH_STYLESHEETrc   s    r5   _ph_stylesheetszHTML._ph_stylesheets   s    #$$r7   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(   warningrb   updater   _render)rM   font_configcounter_styleoptionsunknownnew_optionss         r5   renderzHTML.render   sj    & 7|c/&:: 	EGNN:GD	E%**,7#k='JJr7   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   rb   rk   rr   	write_pdf)rM   targetzoomfinisherrm   rn   ro   rq   s           r5   rt   zHTML.write_pdf   s\    J &**,7#KDKK]>g>YvtX:18:	;r7   )F)NN)Nr#   NNN)__name__
__module____qualname____doc__r"   rY   r_   rd   rg   rr   rt    r7   r5   r   r   q   sG    ,Z "DdTtd0W@8%
/%K4 7;26*;r7   r   c                   4    e Zd ZdZdddddddeddddddf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.

    NFr
   c           
         t        j                  d|xs |xs t        |dd             t        ||||||||	      }|5 \  }}}}|dk(  r|j	                         }t        |t              rt        j                  |      }nt        j                  |||      \  }}d d d        || _
        |xs t        j                         | _        |g n|| _        |i n|}t        |
||| j                  | j                  ||       y # 1 sw Y   exY w)Nz&Step 2 - Fetching and parsing CSS - %sr:   z
CSS stringrF   rG   check_css_mime_typerQ   )environment_encodingrW   )r)   r?   r@   rC   readrA   rB   tinycss2parse_stylesheetparse_stylesheet_bytesrF   rH   Matchermatcher
page_rulespreprocess_stylesheet)rM   rN   rO   rP   rQ   rR   rS   rF   rG   _check_mime_typer	   rm   rn   r   r   rT   rU   rV   rW   
stylesheets                       r5   rY   zCSS.__init__  s   
 	4FFwxF	H  8S(F; 02  		9IVX7Hj(&#&%66v>
'/'F'F&7(9$
H		9 !6*"4"4"6 * 2"
+3*k4<<OO[-	9		9 		9s   AC??Drx   ry   rz   r{   r"   rY   r|   r7   r5   r   r     s/     "DdTtd05#T$	9r7   r   c                   0    e Zd ZdZddddddedddddf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.

    NUnspecifiedc           	      b   t        |||||||      | _        || _        |	| _        || _        d | _        |
5|rt        j                  t        |            }
nt        j                         }
|5|rt        j                  t        |            }nt        j                         }|
| _        || _        y )N)rF   rG   )rC   rV   r:   descriptionrelationshipmd5r   fromtimestampr   nowr   createdmodified)rM   rN   rO   rP   rQ   rR   rF   rG   r:   r   r   r   r   s                r5   rY   zAttachment.__init__T  s     %8S(FX#% 	&(?"00(1CD",,.#11(82DE#<<> r7   r   r|   r7   r5   r   r   ;  s+    0 "DdTt9LdT+!r7   r   c              #     K   |t        |      }| ||||fD cg c]  }|| }	}t        |	      dk7  r#dj                  |	      xs d}
t        d|
       | St	        | d      rd}n#t        | t              rd}nt        |       rd	}nd}t        d|||d
|| i}|5 }| ddd       y|+|t        |      }t        |d      5 }d||df ddd       y|t        ||      5 }|r.|d   dk7  r&t        j                  d|d   |d          dd|df n@|j                  d      }||j                  d|      }d|v rd|d   ||f nd|d   ||f ddd       y|6|+t        |dd      }|r|j!                  d      st        |      }d||df y|J d||df yc c}w # 1 sw Y   yxY w# 1 sw Y   yxY w# 1 sw Y   yxY ww)zCIf only one input is given, return it with normalized ``base_url``.Nr#   z, nothingz!Expected exactly one source, got r   rQ   rO   rP   r   rb	mime_typeztext/cssz%Unsupported stylesheet type %s for %sredirected_urlrR   r-   rS   r:   <r|   )r&   lenjoin	TypeErrorhasattrrA   r   r'   rC   r%   openr$   r(   errorr0   r@   
startswith)rN   rO   rP   rQ   rR   rF   rG   r   paramselected_paramsrV   type_rT   proto_encodingr:   s                  r5   rC   rC   n  ss    
 h' "8S(FC 	O  ?q ?+8y;F8DEE		5&!Et$EU#EE ; 3 en  	vL	 			)H(D! 	7Xh$66	7 	7	;$ 	("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%d+(Hd22!!!$..k&	 	
	7 	7	( 	(sZ   GF&A:GF+#$G	F7G'A1GAG+F40G7G <GGG)r   )ra   r\   r]   rf   )r   r    )*r{   
contextlibr   os.pathr   r   pathlibr   urllib.parser   rH   r   rD   r   r!   r   __all__urlsr$   r"   r%   r&   r'   loggerr(   r)   r6   r   r   r   contextmanagerrC   cssr   htmlra   r\   r]   rf   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   