
    j{                         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dS )z
Utils dealing with URLs.

    N)Path)urljoinurlparse)Requesturlopen   )VERSIONz
User-Agentz	CairoSVG zurl\((.+)\)c                    | r>t           j        dk    r-|                     d          s|                     d          st           j                            |           r}t           j                            |           } d| v r|                     dd          \  } }nd}t          |                                           	                                } || dz   |z   } nft          j        d| t          j        t          j        z  t          j        z            r,|                     dd	          } |                     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     S/home/ubuntu/budget-transfer-bot/.venv/lib/python3.11/site-packages/cairosvg/url.pynormalize_urlr"      s     )rw$s~~g'>'> ~~g&& 	)27==+=+= 	)'//#&&CczzJJsA..	TTs))##%%,,..CCi$& X #,ry8: : 	) ++dE**C++dC((CJ    c                    t           j        dk    rut          j        d| t          j        t          j        z  t          j        z            r;t          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'   :   sc     
w$28r}r|;biGI IvdBbmbl&BRY&NOOOr#   c                 l    t          t          | t                                                              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5566;;===r#   c                 T    | r%|                      d          rt          | |          S dS )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   s5      )s~~g&& )S-(((..r#   c                 @   | rt                               |           }|r|                    d          } |r5t          |          }t          |           }|j        dv r|j        dv rt          |j                  }t          |j                  }t          j                            |          rC|r>t          j        	                    t          j        
                    |          |          } nJ|} nGt          j                            |          r&|r!t          j        	                    ||          } nd} nd} |j        r|  d|j         } n |j        d|j        fv rt          ||           } t          |                     d                    } t          | p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   s     ".

3 	!++a..C 	)"4..K!#J!\11$44'9+:J'K'K$&8&I&IOw~~&677 !* 3 #%',, "0@ A A /#1 #1CC #3CC'788 !* %"$',, 0/#C #CCC #%CC !* =!$<<z':<<"r;+=&>>>dC((CIIe,,--CI2r#   c                     | j         r|                                 } nCdt          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      s_    
 z !jjll7

557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'334bj  $ $ $N  &> > >/ / /* * * *Z+ + + + +r#   