+
    	ioG                        R t ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RI	t	^ RI
Ht ^ RIHt ^ RIHtHt ^ RIHt ^ RIHt ^ RIHtHtHtHt ^RIHt ^R	IHt ]P<                  ! R
4      t]P<                  ! R4      t ]PB                  ! 4       t" ]PF                  ! ]"4      PH                  R8X  d   Rt"RR] 2RRRR/t& ! R R]4      t'R t(R t)R t*R)R lt+R t,R t-R t.R t/R*R lt0]Pb                  R+R l4       t2 ! R  R!]34      t4 ! R" R#]54      t6 ! R$ R%]Pn                  4      t8 ! R& R'4      t9]Pb                  R( 4       t:R#   ]% d    Rt" Li ; i),z9Various utility functions and classes for URL management.N)EmailMessage)GzipFile)BytesIOStringIO)Path)request)quoteunquoteurljoinurlsplit)__version__)LOGGERz^([a-zA-Z][a-zA-Z0-9.+-]+):s   ^([a-zA-Z][a-zA-Z0-9.+-]+):asciiutf-8z
User-AgentzWeasyPrint Acceptz*/*zAccept-Encodingzgzip, deflatec                   2   a  ] tR t^*t o R tR tR tRtV tR# )StreamingGzipFilec                @    \         P                  ! WR 7       Wn        R# )fileobjN)r   __init__fileobj_to_close)selfr   s   &&U/Users/agent/.openclaw/workspace/venv/lib/python3.14/site-packages/weasyprint/urls.pyr   StreamingGzipFile.__init__+   s    $0 '    c                f    \         P                  ! V 4       V P                  P                  4        R # N)r   closer   r   s   &r   r   StreamingGzipFile.close/   s     t##%r   c                    R # F r   s   &r   seekableStreamingGzipFile.seekable3   s    r   )r   N)	__name__
__module____qualname____firstlineno__r   r   r$   __static_attributes____classdictcell____classdict__s   @r   r   r   *   s     (& r   r   c                    V P                  R4      '       d   V # T P                  V P                  R4      '       d   \        MR4      p \        V RR7      # )zDTurn a Unicode IRI into an ASCII-only URI that conforms to RFC 3986.zdata:file:r   s   /:?#[]@!$&'()*+,;=~%)safe)
startswithencodeFILESYSTEM_ENCODINGr   urls   &r   
iri_to_urir6   7   sE    
~~g

**CNN7,C,C(
QC 233r   c                   \        V \        4      '       d   \        V 4      p M+\        V \        4      '       d   V P	                  \
        4      p V P                  \        P                  P                  R34      p\        P                  P                  V 4      p V'       g&   \        P                  P                  V 4      '       d$   V \        P                  P                  ,          p Rp\        P                  ! V 4      p V'       d!   V P                  R4      '       g
   V R,          p V P                  R4      '       d   RV  2# RV  2# )zNReturn file URL of `path`.

Accepts 'str', 'bytes' or 'Path', returns 'str'.

/Tz///r/   zfile://)
isinstancer   strbytesdecoder3   endswithospathsepabspathisdirr   pathname2urlr1   )r?   wants_trailing_slashs   & r   path2urlrE   G   s     $4y	D%	 	 {{./=="''++s);<77??4 Drww}}T22 	#%DDMM#$6$6u tf~r   c                z    \        V \        4      '       d   \        M\        p\	        VP                  V 4      4      # )z4Return whether an URL (bytes or string) is absolute.)r9   r:   UNICODE_SCHEME_REBYTES_SCHEME_REboolmatch)r5   schemes   & r   url_is_absoluterL   f   s*    ",S#"6"6OFS!""r   c           	         V P                  VR4      P                  4       pV'       d%   \        T;'       g    RWCRV P                  W34      # R# )a  Get the URI corresponding to the ``attr_name`` attribute.

Return ``None`` if:

* the attribute is empty or missing or,
* the value is a relative URI but the document has no base URI and
  ``allow_relative`` is ``False``.

Otherwise return an URI, absolute if possible.

 z<%s %s="%s">N)getstripurl_jointag)element	attr_namebase_urlallow_relativevalues   &&&& r   get_url_attributerX   l   sK     KK	2&,,.ENNE>[[)+- 	- r   c                    V P                  R4      '       d   R\        V R,          4      3# \        V 4      '       d   R\        V 4      3# V'       d   R\        \	        W4      4      3# R# )z.Get tuple describing internal or external URI.#internal   NNexternalN)r1   r	   rL   r6   r
   )r5   rU   s   &&r   get_url_tupler_      s\    
~~cGCG,--			JsO,,	Jwx'=>?? 
r   c                    \        V4      '       d   \        V4      # V '       d   \        \        W4      4      # V'       d   \        V4      # \        P                  ! RV 2.VO5!   R# )zBLike urllib.urljoin, but warn if base_url is required but missing.z+Relative URI reference without a base URI: N)rL   r6   r
   r   error)rU   r5   rV   contextcontext_argss   &&&&&r   rQ   rQ      sZ    s#	'(011	#9'C		 r   c                H   V P                  VR4      P                  4       pVP                  R4      '       d'   \        V4      ^8  d   RR\	        VR,          4      33# \        WVRR7      pV'       d_   V'       dQ    \        V4      p \        V4      pVP                  '       d'   VRR VRR 8X  d   RR\	        VP                  4      33# RRV33# R#   \         d    \        P                  ! R	T4        L,i ; i  \         d    \        P                  ! R
T4        LTi ; i)zGet the URL value of an element attribute.

Return ``('external', absolute_uri)``, or ``('internal',
unquoted_fragment_id)``, or ``None``.

rN   rZ   r5   r[   r\   T)rV   NzMalformed base URL: %szMalformed URL: %sr^   )rO   rP   r1   lenr	   rX   r   fragment
ValueErrorr   warning)rS   rT   rU   
attr_valueuriparsedparsed_bases   &&&    r   get_link_attributern      s    Y+113JS!!c*o&9
GJrN$;<==
G
NC
O!#O"*8"4K
 6#2;+cr:J+J %
GFOO4L'MNN
C())  " GNN#;XFG  92C89s$   =C< 	C "C98C9<"D! D!c                >    \        V 4      '       d   V # \        V 4      # )zGet a ``scheme://path`` URL from ``string``.

If ``string`` looks like an URL, return it unchanged. Otherwise assume a
filename and convert it to a ``file://`` URL.

)rL   rE   )strings   &r   
ensure_urlrq      s     %V,,6B(62BBr   c                x    \         P                  ! R\        R7       \        WW4RR7      pVP	                  V 4      # )zvFetch an external resource such as an image or stylesheet.

This function is deprecated, use ``URLFetcher`` instead.

a-  default_url_fetcher is deprecated and will be removed in WeasyPrint 69.0, please use URLFetcher instead. For security reasons, HTTP redirects are not supported anymore with default_url_fetcher, but are with URLFetcher.

See https://doc.courtbouillon.org/weasyprint/stable/first_steps.html#url-fetcherscategoryF)allow_redirects)warningswarnDeprecationWarning
URLFetcherfetch)r5   timeoutssl_contexthttp_headersallowed_protocolsfetchers   &&&&& r   default_url_fetcherr      s>     MM	X $% luVG==r   c              #  .  "   Ve   \        V4      pVf   \        4       pWW#V3 Uu. uF  pVf   K	  VNK  	  p	p\        V	4      ^8w  d*   RP                  V	4      ;'       g    Rp
\	        RV
 24      hV ey   RVRVRV/p\        V R4      '       d   WR	&   M5\        V \        4      '       d   WR
&   M\        V 4      '       d   WR&   MWR
&   \        R/ VB pT;_uu_ 4       pVx  RRR4       R# Ve6   Vf   \        V4      p\        VR4      ;_uu_ 4       pW5RR3x  RRR4       R# Ve   \        Wb4      ;_uu_ 4       pV'       dT   VP                  R8w  dC   \        P                  ! RVP                   RVP                    24       \#        R4      VRR3x  M+Vf   VP                   pWVP$                  VP                  3x  RRR4       R# VeE   Vf8   \'        VRR4      pV'       d#   VP)                  R4      '       g   \        V4      pW5RR3x  R# \        V\*        4      '       d   \#        V4      VRR3x  R# \-        V4      VRR3x  R# u upi   + '       g   i     R# ; i  + '       g   i     R# ; i  + '       g   i     R# ; i5i)z~If only one input is given, return it.

Yield a file object, the base url, the protocol encoding and the protocol mime-type.

Nz, nothingz!Expected exactly one source, got rU   url_fetchercheck_css_mime_typereadfile_objfilenamer5   rbztext/csszUnsupported stylesheet type z for rN   name<r#   )rq   ry   rf   join	TypeErrorhasattrr9   r   rL   select_sourcerE   openrz   content_typer   ra   r5   r   charsetgetattrr1   r:   r   )guessr   r5   r   rp   rU   r   r   paramselected_paramssourcekwargsresultresponser   s   &&&&&&&&       r   r   r      s{     h' l "SFCC% 	C   ?q ?+88y;F8DEE		;!#6

 5&!!!&:t$$!&:U##!5M!&:((VvL V		)H(D!!XdD00 "!	;$$"x'<'<
'J283H3H2I J#<<.*+ rlHdD88#'||H(*:*:H<Q<QQQ %$ 
	8VT2DDOOC00%d+$,,fc""6"HdD88&/8T477g* VV
 "!! %$$sk   %JII)J"A>J I%1JI-!J?BJ=JAJI*	$	J-I>	8	JJ		Jc                       ] tR tRtRtRtR# )URLFetchingErrori  z)Some error happened when fetching an URL.r#   Nr&   r'   r(   r)   __doc__r*   r#   r   r   r   r     s    3r   r   c                       ] tR tRtRtRtR# )FatalURLFetchingErrori  zESome error happened when fetching an URL and must stop the rendering.r#   Nr   r#   r   r   r   r     s    Or   r   c                   Z   a a ] tR tRt oRtRV 3R lltR	V 3R lltR
R ltR tRt	Vt
V ;t# )ry   i  a0  Fetcher of external resources such as images or stylesheets.

:param int timeout: The number of seconds before HTTP requests are dropped.
:param ssl.SSLContext ssl_context: An SSL context used for HTTPS requests.
:param dict http_headers: Additional HTTP headers used for HTTP requests.
:type allowed_protocols: :term:`sequence`
:param allowed_protocols: A set of authorized protocols, :obj:`None` means all.
:param bool allow_redirects: Whether HTTP redirects must be followed.
:param bool fail_on_errors: Whether HTTP errors should stop the rendering.

Another class inheriting from this class, with a ``fetch`` method that has a
compatible signature, can be given as the ``url_fetcher`` argument to
:class:`weasyprint.HTML` or :class:`weasyprint.CSS`.

See :ref:`URL Fetchers` for more information and examples.

c                v  < \         S
V `  4        \        P                  ! 4       \        P                  ! 4       \        P
                  ! 4       \        P                  ! 4       \        P                  ! 4       \        P                  ! 4       \        P                  ! 4       \        P                  ! 4       \        P                  ! VR 7      .	pV'       d%   VP                  \        P                  ! 4       4       V F  p	V P                  V	4       K  	  Wn        / \         CT;'       g    / CV n        W@n        W`n        R# ))rb   N)superr   r   ProxyHandlerUnknownHandlerHTTPHandlerHTTPDefaultErrorHandler
FTPHandlerFileHandlerHTTPErrorProcessorDataHandlerHTTPSHandlerappendHTTPRedirectHandleradd_handler_timeoutHTTP_HEADERS_http_headers_allowed_protocols_fail_on_errors)r   r{   r|   r}   r~   ru   fail_on_errorsr   handlershandler	__class__s   &&&&&&&,  r   r   URLFetcher.__init__0  s     	  "G$:$:$<g>Q>Q>S++-w/A/A/C!7#=#=#?ATATAV  5	7
 OOG779:GW%    EE1C1CE"3-r   c                n  < \         P                  V4      ;p'       g   \        RV 24      hV^,          P                  4       pV P                  e   W@P                  9  d   \        RV 24      hVR8X  d   VP                  R4      ^ ,          p\        V4      p/ V P                  CT;'       g    / Cp\        P                  ! WR7      p\        S
V `-  WPP                  R7      pTpRVP                  9   dc   VP                  R,          pVP                  R VR8X  d   \        VR	7      pM.VR
8X  d(   VP                  4       p	 \         P"                  ! V	4      p\'        VP(                  WvP                  VP*                  4      #   \         P$                   d    \         P"                  ! T	R4      p LYi ; i)a  Fetch a given URL.

:returns: A :obj:`URLFetcherResponse` instance.
:raises: An exception indicating failure, e.g. :obj:`ValueError` on
    syntactically invalid URL. All exceptions are catched internally by
    WeasyPrint, except when they inherit from :obj:`FatalURLFetchingError`.

zNot an absolute URI: zURI uses disallowed protocol: file?headers)r{   zContent-Encodinggzipr   deflatei)rG   rJ   rh   lowerr   splitr6   r   r   Requestr   r   r   r   r   r   zlib
decompressra   URLFetcherResponser5   status)r   r5   r   rJ   rK   http_requestr   bodycontent_encodingdatar   s   &&&       r   rz   URLFetcher.fetchC  s    +005554SE:;;q! "".444 #A#!GHH V))C.#C o <T'';GMMr;s<7<mm<D !1!11'//0BC  !346)(:!Y.}}6??40D
 "(,,6F6FXX	 zz 6??45D6s   F ,F43F4c                    \        V\        P                  4      '       d'   V P                  VP                  VP
                  4      # V P                  V4      # r   )r9   r   r   rz   full_urlr   )r   r5   r   r{   s   &&&&r   r   URLFetcher.opent  s:    c7??++::cllCKK88zz#r   c                $    V P                  V4      # r   )rz   )r   r5   s   &&r   __call__URLFetcher.__call__y  s    zz#r   )r   r   r   r   )
   NNNTFr   )NN)r&   r'   r(   r)   r   r   rz   r   r   r*   r+   __classcell__)r   r-   s   @@r   ry   ry     s%     $.&/Yb
 r   ry   c                      a  ] tR tRt o RtRR ltR tR t]R 4       t	]R 4       t
]R	 4       tR
 tR t]R 4       tR tRtV tR# )r   i}  u  The HTTP response of an URL fetcher.

:param str url: The URL of the HTTP response.
:type body: :class:`str`, :class:`bytes` or :term:`file object`
:param body: The body of the HTTP response.
:type headers: dict or email.message.EmailMessage
:param headers: The headers of the HTTP response.
:param int status: The status of the HTTP response.

Has the same interface as :class:`urllib.response.addinfourl`.

If a :term:`file object` is given for the body, it is the caller’s responsibility to
call ``close()`` on it. The default function used internally to fetch data in
WeasyPrint tries to close the file object after retreiving; but if this URL fetcher
is used elsewhere, the file object has to be closed manually.

Nc                   Wn         W@n        \        V\        4      '       d   W0n        MA\        4       V n        T;'       g    / P                  4        F  w  rg WpP                  V&   K  	  \        VR 4      '       d	   W n        R# \        V\        4      '       d>   V P                  P                  RR4       \        VP                  R4      4      V n        R# \        V4      V n        R#   \         d     K  i ; i)r   r   r   N)r5   r   r9   r   r   itemsrh   r   	_file_objr:   	set_paramr   r2   )r   r5   r   r   r   r   keyrW   s   &&&&&,  r   r   URLFetcherResponse.__init__  s    g|,,"L'>DL&}}"335
(-LL% 6 4  !Nc""LL""9g6$T[[%9:DN$T]DN " s   C**C98C9c                :    V P                   P                  ! V/ VB # r   )r   r   )r   argsr   s   &*,r   r   URLFetcherResponse.read  s    ~~""D3F33r   c                     V P                   P                  4        R#   \         d:    \        P                  ! R T P
                  \        P                  ! 4       4        R# i ; i)z$Error when closing stream for %s:
%sN)r   r   	Exceptionr   ri   r5   	traceback
format_excr   s   &r   r   URLFetcherResponse.close  sI    	2NN  " 	2 NN7)..02	2s    A A"!A"c                    V P                   P                  R 4      '       dF   \        P                  ! V P                   P	                  R4      ^ ,          P                  R 4      4      # R# )r/   r   N)r5   r1   r   url2pathnamer   removeprefixr   s   &r   r?   URLFetcherResponse.path  sJ    88w''''s(;A(>(K(KG(TUU (r   c                6    V P                   P                  4       # r   )r   get_content_typer   s   &r   r   URLFetcherResponse.content_type  s    ||,,..r   c                8    V P                   P                  R 4      # )r   )r   	get_paramr   s   &r   r   URLFetcherResponse.charset  s    ||%%i00r   c                    V P                   # r   r4   r   s   &r   geturlURLFetcherResponse.geturl  s    xxr   c                    V P                   # r   r   r   s   &r   infoURLFetcherResponse.info  s    ||r   c                    V P                   # r   r   r   s   &r   codeURLFetcherResponse.code  s    {{r   c                    V P                   # r   r   r   s   &r   getcodeURLFetcherResponse.getcode  s    {{r   )r   r   r   r5   )NN   )r&   r'   r(   r)   r   r   r   r   propertyr?   r   r   r   r   r   r   r*   r+   r,   s   @r   r   r   }  s     "+,42 V V / / 1 1   r   r   c              #    "    V ! V4      p\        T\        4      '       d   \        P                  ! R\        R7       R	T9  d   TP                  R
T4      TR	&   TP                  RTP                  R4      4      TR&   TP                  RR4      pTP                  R4      ;p'       d   TRT 2,          pRT/TR&   \        R/ TB p\        T\        4      '       g   Q R4       h Tx  TP                  4        R#   \          dL   p\        T RR4      '       d   \        RT R24      Th\        \	        T4      P
                   RT 24      hRp?ii ; i  TP                  4        i ; i5i)a4  Fetch an ``url`` with ```url_fetcher``, fill in optional data, and clean up.

Fatal errors must raise a ``FatalURLFetchingError`` that stops the rendering. All
other exceptions are catched and raise an ``URLFetchingError``, that is usually
catched by the code that fetches the resource and emits a warning.

r   FzError fetching ""z: NzReturning dicts in URL fetchers is deprecated and will be removed in WeasyPrint 69.0, please return URLFetcherResponse instead.rs   r5   redirected_urlr   rp   r   	mime_typezapplication/octet-streamencodingz
; charset=zContent-Typer   zFURL fetcher must return either a dict or a URLFetcherResponse instancer#   )r   r   r   r   typer&   r9   dictrv   rw   rx   rO   r   r   )r   r5   resource	exceptionr   r   s   &&    r   rz   rz     sd    Ks# (D!!L'	)  &ll+;SAHUO#<<
HLL4JK||K1KLll:..7.j	22L-|<%11h 233 RPR33  K; 1599'*:3%q(AB	Q$y/":":!;2i[IJJK2 	sG   E)C; BE));E)%E )E);EAEEE)E&&E)r"   )r   NNN)NNNNNNNF);r   codecs
contextlibos.pathr>   resysr   rv   r   email.messager   r   r   ior   r   pathlibr   urllibr   urllib.parser   r	   r
   r   rN   r   loggerr   compilerG   rH   getfilesystemencodingr3   lookupr   LookupErrorr   r   r6   rE   rL   rX   r_   rQ   rn   rq   r   contextmanagerr   IOErrorr   BaseExceptionr   OpenerDirectorry   r   rz   r#   r   r   <module>r     ss   ?    	 
    &      : :  
 JJ<= **;< //1 "}}()..'9%
 K}-e
 
4  >#-&@*<C$ ?8 ?8D4w 4PM P]'' ]@M M` # #]  "!"s   #E 	EE