
     h{                         d Z ddlZddlZddlmZ ddlmZmZ ddlm	Z	m
Z
 ddlmZ dd	e iZ ej                  d
      Zd Zd Zd Zd ZddZd Zy)z
Utils dealing with URLs.

    N)Path)urljoinurlparse)Requesturlopen   )VERSIONz
User-Agentz	CairoSVG zurl\((.+)\)c                 j   | r/t         j                  dk(  r| j                  d      s	| j                  d      st         j                  j	                  |       rnt         j                  j                  |       } d| v r| j                  dd      \  } }nd}t        |       j                         j                         } || dz   |z   } | S t        j                  d| t        j                  t        j                  z  t        j                  z        r$| j                  dd	      } | j                  d
d      } | S )a2  Normalize ``url`` for underlying NT/Unix operating systems.

    The input ``url`` may look like the following:

        - C:\Directory\zzz.svg
        - file://C:\Directory\zzz.svg
        - zzz.svg

    The output ``url`` on NT systems would look like below:

        - file:///C:/Directory/zzz.svg

    ntdata:zfile:#r   Nz^file://[a-z]:z//z///\/)osname
startswithpathisabsabspathrsplitr   resolveas_urirematch
IGNORECASE	MULTILINEDOTALLreplace)urlparts     h/home/developers/rajanand/mypropertyqr-fmb-refixing-v2/venv/lib/python3.12/site-packages/cairosvg/url.pynormalize_urlr"      s     rww$s~~g'> ~~g&277==+=''//#&CczJJsA.	Ts)##%,,.CCi$& J XX #,ryy8: ++dE*C++dC(CJ    c                 J   t         j                  dk(  rt        j                  d| t        j                  t        j
                  z  t        j                  z        rHt        j                  dd| t        j                  t        j
                  z  t        j                  z        S | S )a  Provide compatible NT file paths for ``os.path`` functions

    ``os.path`` expects NT paths with no ``/`` at the beginning. For
    example, ``/C:/Directory/zzz.svg`` would fail ``os.path.isfile()``,
    ``os.path.isdir()`` etc. where the expected input for `os.path`
    functions is ``/C:/Directory/zzz.svg``.

    Currently ``nt_compatible_path`` performs some basic checks and
    eliminates the unwanted ``/`` at the beginning.

    r   z	^/[a-z]:/z^/ )r   r   r   r   r   r   r   sub)r   s    r!   nt_compatible_pathr'   :   sh     
ww$288r}}r||;biiGIvvdBbmmbll&BRYY&NOOr#   c                 R    t        t        | t                    j                         S )zFetch the content of ``url``.

    ``resource_type`` is the mimetype of the resource (currently one of
    image/*, image/svg+xml, text/css).

    )headers)r   r   HTTP_HEADERSreadr   resource_types     r!   fetchr.   M   s     7356;;==r#   c                 B    | r| j                  d      rt        | |      S y)ub   Fetch the content of ``url`` only if it’s a data-URL.

    Otherwise, return an empty SVG.

    r   s    <svg width="1" height="1"></svg>)r   r.   r,   s     r!   
safe_fetchr0   W   s"     s~~g&S-((.r#   c                 F   | rt         j                  |       }|r|j                  d      } |rKt        |      }t        |       }|j                  dv r |j                  dv rt        |j                        }t        |j                        }t        j                  j                  |      rC|r>t        j                  j                  t        j                  j                  |      |      } nJ|} nGt        j                  j                  |      r&|r!t        j                  j                  ||      } nd} nd} |j                  r8|  d|j                   } n&|j                  d|j                  fv rt        ||       } t        | j                  d            } t        | xs d      S )zParse an URL.

    The URL can be surrounded by a ``url()`` string. If ``base`` is not `None`,
    the "folder" part of it is prepended to the URL.

    r   )r%   filer%   r   z'")URLsearchgroupr   schemer'   r   r   isfilejoindirnameisdirfragmentr   r"   strip)r   baser   parsed_base
parsed_urlparsed_base_pathparsed_url_paths          r!   	parse_urlrB   b   sV    

3++a.C"4.K!#J!!\1$$4'9+:J:J'K$&8&IOww~~&67* #%'',, "0@ A /#1C #3C'78*"$'',, 0/#CC #%C !**!$Qz':':&;<""r;+=+=&>>dC(CIIe,-CI2r#   c                     | j                   r| j                         } n;dt        j                  j	                  | j                                } t        |       }  || |      S )zGet bytes in a parsed ``url`` using ``url_fetcher``.

    If ``url_fetcher`` is None a default (no limitations) URLFetcher is used.
    zfile://)r6   geturlr   r   r   r"   )r   url_fetcherr-   s      r!   read_urlrF      sM    
 zzjjl

567C sM**r#   )N)__doc__r   r   pathlibr   urllib.parser   r   urllib.requestr   r   r%   r	   r*   compiler3   r"   r'   r.   r0   rB   rF    r#   r!   <module>rM      s_   
 
 	  * + 	'34bjj $N&>/*Z+r#   