
    Bh&                        S r SSKrSSKrSSKrSSKrSSKrSSKrSSKrSSK	J
r
  SSKJr  SSKJrJrJrJr  SSKJrJrJr  SSKJr  SS	KJr  \R4                  " S
5      r\R4                  " S5      r\R:                  " 5       r \R>                  " \5      R@                  S:X  a  SrS\ 3SSS.r" " S S\
5      r#S r$S r%S r&SS jr'S r(S r)S r*S S jr+ " S S\,5      r-\R\                  S 5       r/g! \! a    Sr NXf = f)!z9Various utility functions and classes for URL management.    N)GzipFile)Path)quoteunquoteurljoinurlsplit)Requestpathname2urlurlopen   )__version__)LOGGERz^([a-zA-Z][a-zA-Z0-9.+-]+):s   ^([a-zA-Z][a-zA-Z0-9.+-]+):asciiutf-8zWeasyPrint z*/*zgzip, deflate)z
User-AgentAcceptzAccept-Encodingc                   &    \ rS rSrS rS rS rSrg)StreamingGzipFile'   c                 8    [         R                  " XS9  Xl        g )Nfileobj)r   __init__fileobj_to_close)selfr   s     A/var/www/html/env/lib/python3.13/site-packages/weasyprint/urls.pyr   StreamingGzipFile.__init__(   s    $0 '    c                 d    [         R                  " U 5        U R                  R                  5         g )N)r   closer   r   s    r   r   StreamingGzipFile.close,   s     t##%r   c                     g)NF r    s    r   seekableStreamingGzipFile.seekable0   s    r   )r   N)__name__
__module____qualname____firstlineno__r   r   r$   __static_attributes__r#   r   r   r   r   '   s    (&r   r   c                     U R                  S5      (       a  U $ U R                  U R                  S5      (       a  [        OS5      n [        U SS9$ )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_urir2   4   sI    
~~g

**"~~g66GEC 233r   c                    [        U [        5      (       a  [        U 5      n O*[        U [        5      (       a  U R	                  [
        5      n U R                  [        R                  R                  5      =(       d    U R                  S5      n[        R                  R                  U 5      n U(       d$  [        R                  R                  U 5      (       a  U [        R                  R                  -  n Sn[        U 5      n U(       a  U R                  S5      (       d  U S-  n U R                  S5      (       a  SU  3$ SU  3$ )zNReturn file URL of `path`.

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

/Tz///r,   file://)
isinstancer   strbytesdecoder0   endswithospathsepabspathisdirr
   r.   )r<   wants_trailing_slashs     r   path2urlrA   E   s     $4y	D%	 	 {{./==5Ks9K77??4 Drww}}T22 	#DDMM#$6$6u tf~r   c                 x    [        U [        5      (       a  [        O[        n[	        UR                  U 5      5      $ )z4Return whether an URL (bytes or string) is absolute.)r6   r7   UNICODE_SCHEME_REBYTES_SCHEME_REboolmatch)r1   schemes     r   url_is_absoluterH   d   s*    ",S#"6"6OFS!""r   c           	          U R                  US5      R                  5       nU(       a#  [        U=(       d    SXCSU R                  X45      $ g)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_attributerT   j   sI     KK	2&,,.ENE>[[)+- 	- r   c                     [        U5      (       a  [        U5      $ U (       a  [        [        X5      5      $ U(       a  [        U5      $ [        R                  " SU 3/UQ76   g)zBLike urllib.urljoin, but warn if base_url is required but missing.z+Relative URI reference without a base URI: N)rH   r2   r   r   error)rQ   r1   rR   contextcontext_argss        r   rM   rM   }   sZ    s#	'(011	#9'C		 r   c                 (   U R                  US5      R                  5       nUR                  S5      (       a!  [        U5      S:  a  SS[	        USS 5      44$ [        XUSS9nU(       a[  U(       aN   [        U5      n [        U5      nUR                  (       a%  USS	 USS	 :X  a  SS[	        UR                  5      44$ SSU44$ g! [         a    [        R                  " S
U5         N*f = f! [         a    [        R                  " SU5         NQf = f)zGet the URL value of an element attribute.

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

rJ   #r   r1   internalNT)rR   zMalformed base URL: %szMalformed URL: %sexternal)rK   rL   r.   lenr   rT   r   fragment
ValueErrorr   warning)rO   rP   rQ   
attr_valueuriparsedparsed_bases          r   get_link_attributerf      s    Y+113JS!!c*o&9
GJqrN$;<==
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$   2C- >C !C*)C*-!DDc                 <    [        U 5      (       a  U $ [        U 5      $ )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.

)rH   rA   )strings    r   
ensure_urlri      s     %V,,6B(62BBr   c                    [         R                  U 5      (       a  U R                  S5      (       a  U R                  S5      S   n [	        U 5      n [        [        U [        S9UUS9nUR                  5       nUR                  5       UR                  5       UR                  S5      UR                  5       S.nUR                  S5      nUS	:X  a  [        US
9US'   U$ US:X  a,  UR                  5       n [         R"                  " U5      US'   U$ X5S'   U$ ['        SU -  5      e! [         R$                   a    [         R"                  " US5      US'    U$ f = f)u  Fetch an external resource such as an image or stylesheet.

Another callable with the same signature can be given as the
``url_fetcher`` argument to :class:`HTML` or :class:`CSS`.
(See :ref:`URL Fetchers`.)

:param str url:
    The URL of the resource to fetch.
:param int timeout:
    The number of seconds before HTTP requests are dropped.
:param ssl.SSLContext ssl_context:
    An SSL context used for HTTP requests.
:raises: An exception indicating failure, e.g. :obj:`ValueError` on
    syntactically invalid URL.
:returns: A :obj:`dict` with the following keys:

    * One of ``string`` (a :obj:`bytestring <bytes>`) or ``file_obj``
      (a :term:`file object`).
    * Optionally: ``mime_type``, a MIME type extracted e.g. from a
      *Content-Type* header. If not provided, the type is guessed from the
      file extension in the URL.
    * Optionally: ``encoding``, a character encoding extracted e.g. from a
      *charset* parameter in a *Content-Type* header
    * Optionally: ``redirected_url``, the actual URL of the resource
      if there were e.g. HTTP redirects.
    * Optionally: ``filename``, the filename of the resource. Usually
      derived from the *filename* parameter in a *Content-Disposition*
      header

    If a ``file_obj`` key is given, it is the caller’s responsibility
    to call ``file_obj.close()``. 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.

r5   ?r   )headers)timeoutrW   charset)redirected_url	mime_typeencodingfilenamezContent-Encodinggzipr   file_objdeflaterh   izNot an absolute URI: %r)rC   rF   r.   splitr2   r   r	   HTTP_HEADERSinfogeturlget_content_type	get_paramget_filenamerK   r   readzlib
decompressrV   r`   )r1   rm   ssl_contextresponseresponse_inforesultcontent_encodingdatas           r   default_url_fetcherr      sT   J s##>>)$$))C.#CoC.! !&oo/&779%//	:%224	
 ),,-?@v%!28!DF:  *==?D>#'??4#8x   "*:2S899 :: >#'??4#=x  >s   3D" ".EEc                       \ rS rSrSrSrg)URLFetchingError   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           	   #   6  #     U " U5      nUR	                  SU5        UR	                  SS5        SU;   a   Uv    US   R                  5         gUv   g! [          a(  n[        [        U5      R                   SU 35      eSnAff = f! [          a.    [        R                  " SU[        R                  " 5       5         gf = f!  US   R                  5         f ! [          a.    [        R                  " SU[        R                  " 5       5         f f = f= f7f)z9Call an url_fetcher, fill in optional data, and clean up.z: Nro   rp   rt   z$Error when closing stream for %s:
%s)
	Exceptionr   typer&   
setdefaultr   r   ra   	traceback
format_exc)url_fetcherr1   r   	exceptions       r   fetchr      s    KS! &,
k4(V
	1L1z"((* #  K$y/":":!;2i[IJJK  1 ;--/111z"((* 1 ;--/11s   DA *DC B
 D
B#BBD
5C?DCDDCD5DDDDD)F)
   N)0r   codecs
contextlibos.pathr;   resysr   r~   rs   r   pathlibr   urllib.parser   r   r   r   urllib.requestr	   r
   r   rJ   r   loggerr   compilerC   rD   getfilesystemencodingr0   lookupnameLookupErrorrw   r   r2   rA   rH   rT   rM   rf   ri   r   IOErrorr   contextmanagerr   r#   r   r   <module>r      s   ?    	 
     : : 9 9  
 JJ<= **;< //1 "}}()..'9%
  }-&
 
4" >#-&*<CC:L4w 4  E  "!"s   "C3 3C>=C>