
    ph                     B   S r SSKrSSKrSSKJr  SSKJr  SSKJr  SSK	J
r
  SSKJr  SrS	 rS
\\\4   S\4S jrSSSSSSSSSSSSSSS.r\R'                  5        V Vs1 s H  u  pUS:X  d  M  U iM     snn rS
\4S jrS\4S jrS rS rS
\\\4   4S jrgs  snn f )zUtility functions.    N)Version)Path)Union)urlparse)vsimem_rmtree_toplevel)z	.gpkg.zipz.shp.zipc                 L   [        U [        5      (       a  [        U 5      $ [        U [        5      (       a  U $ [	        U S5      (       aI  U R                  5       n[	        U S5      (       a&  U R                  5       (       a  U R                  S5        U$ [        [        U 5      5      $ )a  Get VSI-prefixed path or bytes buffer depending on type of path_or_buffer.

If path_or_buffer is a bytes object, it will be returned directly and will
be read into an in-memory dataset when passed to one of the Cython functions.

If path_or_buffer is a file-like object with a read method, bytes will be
read from the file-like object and returned.

Otherwise, it will be converted to a string, and parsed to prefix with
appropriate GDAL /vsi*/ prefixes.

Parameters
----------
path_or_buffer : str, pathlib.Path, bytes, or file-like
    A dataset path or URI, raw buffer, or file-like object with a read method.

Returns
-------
str or bytes

readseekabler   )	
isinstancer   vsi_pathbyteshasattrr	   r
   seekstr)path_or_bufferbytes_buffers     dC:\Users\julio\OneDrive\Documentos\Trabajo\IdeasFrscas\Cabanna\env\Lib\site-packages\pyogrio/util.pyget_vsi_path_or_bufferr      s    0 .$''''.%((~v&&%**, >:..>3J3J3L3L"C'((    pathreturnc                    [        U [        5      (       aT  [        R                  S:X  a5  U R	                  5       R                  S5      (       a  U R	                  5       n O[        U 5      n U R                  S5      (       a  U $ [        R                  S:X  ay  [        R                  " SU 5      (       a]  U R                  S5      S   R                  S5      (       d  U $ U R                  S5      S   R                  [        5      (       a  U $ SU  3n [        U 5      u  pnU(       d7  U(       d0  U R                  S5      (       a&  U R                  [        5      (       d  [        XU5      $ U $ )z:Ensure path is a local path or a GDAL-compatible VSI path.win32z/vsiz^[a-zA-Z]\:!r   .zipzzip://)r   r   sysplatformas_posix
startswithr   rematchsplitendswithMULTI_EXTENSIONS
_parse_uri_construct_vsi_path)r   archiveschemes      r   r   r   9   s    $<<7"t}}'A'A&'I'I==?Dt9D v ||w288ND#A#A zz#q!**622K::c?1&&'788K v&t,D6 	MM&!!$--8H*I*I"4&99Kr   fileziptargzipcurls3gsazadlshdfswebhdfs)r)   r*   r+   r,   httphttpsftpr.   r/   r0   r1   adlr2   r3   c                    [        U SS9nUR                  (       a5  [        S UR                  R                  S5       5       5      (       d  U SS4$ UR                  n UR                  =(       d    SnUR
                  (       a  U SUR
                  -   -  n UR                  (       a   UR                  (       a  UR                  U -   n U R                  S5      nU(       a  UR                  5       OSn U(       a  UR                  5       OSnXU4$ )zParse a URI.

Returns a tuples of (path, archive, scheme)

path : str
    Parsed path. Includes the hostname and query string in the case
    of a URI.
archive : str
    Parsed archive path.
scheme : str
    URI scheme such as "https" or "zip+s3".
F)allow_fragmentsc              3   2   #    U  H  o[         ;   v   M     g 7f)NSCHEMES.0ps     r   	<genexpr>_parse_uri.<locals>.<genexpr>   s     N6MW6Ms   + ?r   )r   r(   allr"   r   querynetlocpop)r   partsr(   r'   s       r   r%   r%   v   s     T51E ||CNell6H6H6MNNNR| ::D\\RF{{ekk!!||||d"JJsOE599;RD"eiikG6""r   c                    SnSnUR                  S5      nSU;  aX  UR                  S5      (       d0  U R                  S5      (       a,  U R                  [        5      (       d  UR                  SS5        U(       a-  SR	                  S U 5       5      nUS   [
        ;   a  US    S	3nU(       a2  U(       a!  S
R                  X4XR                  S5      5      $ SU SU U  3$ U $ )z)Convert a parsed path to a GDAL VSI path.rC   rB   r*   r   r   /c              3   Z   #    U  H!  o(       d  M  US :w  d  M  S[         U    3v   M#     g7f)r)   vsiNr;   r=   s     r   r@   &_construct_vsi_path.<locals>.<genexpr>   s)     Sg,qF{,C
|,gs   
+++z://z/{}/{}{}/{})r"   r#   r$   insertjoinCURLSCHEMESformatlstrip)r   r'   r(   prefixsuffixschemess         r   r&   r&      s    FFll3GG  MM&!!$--8H*I*Iq% SgSS2;+%}C(F ''SAQRRvhaxv..Kr   c                    [        U [        5      (       d  [        S[        U 5       35      e0 nU R	                  5        HJ  u  p#Uc  M
  UR                  5       n[        U[        5      (       a  U(       a  SOSnO[        U5      nX1U'   ML     U$ )z`Preprocess options.

For example, `spatial_index=True` gets converted to `SPATIAL_INDEX="YES"`.
z#Expected options to be a dict, got ONOFF)r   dict	TypeErrortypeitemsupperboolr   )optionsresultkvs       r   _preprocess_options_key_valuere      s    
 gt$$=d7m_MNNF9GGIauAAAq	   Mr   c                    U c  U $  SSK n[        UR                  5      [        S5      :  a  SnU(       d  [	        S5      e[        XR                  5      (       d  [	        S5      eUR                  U 5      $ ! [         a    Sn NVf = f)a  Convert a Shapely mask geometry to WKB.

Parameters
----------
mask : Shapely geometry
    The geometry to convert to WKB.

Returns
-------
WKB bytes or None

Raises
------
ValueError
    raised if Shapely >= 2.0 is not available or mask is not a Shapely
    Geometry object

Nr   z2.0.0z('mask' parameter requires Shapely >= 2.0z+'mask' parameter must be a Shapely geometry)shapelyr   __version__ImportError
ValueErrorr   Geometryto_wkb)maskrg   s     r   _mask_to_wkbrn      s    & |7&&'''*::G CDDd,,--FGG>>$  s   (A7 7BBc                 d    [        U [        5      (       a  U R                  5       n [        U 5        g)a  Remove the parent directory of the file path recursively.

This is used for final cleanup of an in-memory dataset, which may have been
created within a directory to contain sibling files.

Additional VSI handlers may be chained to the left of /vsimem/ in path and
will be ignored.

Remark: function is defined here to be able to run tests on it.

Parameters
----------
path : str or pathlib.Path
    path to in-memory file

N)r   r   r   _vsimem_rmtree_toplevel)r   s    r   r   r      s$    " $}}D!r   )__doc__r    r   packaging.versionr   pathlibr   typingr   urllib.parser   pyogrio._vsir   rp   r$   r   r   r   r<   r^   rR   r%   r&   re   rn   )rc   rd   s   00r   <module>rw      s     	 
 %   ! J, ')T#5d# # #P 


& %]]_<_TQVq_< #S  #F# 6*$ N"sDy!1 "{ =s    B0B