o
    bim                     @   s   U d dl Z d dlmZmZ d dlmZmZmZmZm	Z	 d dl
mZmZ daee ed< daee ed< dee fdd	Zd
edeeef defddZdedefddZdS )    N)DictOptional)	parse_qslunquote	urlencodeurlparse
urlunparse)Versionparse_PYARROW_INSTALLED_PYARROW_VERSIONreturnc                  C   s^   t du rdS t du r-zddl} da t| drt| jaW tS W tS  ty,   da Y tS w tS )z@Get the version of the pyarrow package or None if not installed.FNr   T__version__)r   pyarrowhasattrparse_versionr   r   ModuleNotFoundError)r    r   L/home/ubuntu/.local/lib/python3.10/site-packages/ray/_private/arrow_utils.pyget_pyarrow_version   s    
r   urlparamsc                 C   sd   t | } t| }|}tt|j}|| |dd | D  t|dd}|j|d}t	|S )a  Add params to the provided url as query parameters.

    If url already contains query parameters, they will be merged with params, with the
    existing query parameters overriding any in params with the same parameter name.

    Args:
        url: The URL to add query parameters to.
        params: The query parameters to add.

    Returns:
        URL with params added as query parameters.
    c                 S   s*   i | ]\}}t |ttfr|t|qS r   )
isinstancebooldictjsondumps).0kvr   r   r   
<dictcomp>5   s    
z)_add_url_query_params.<locals>.<dictcomp>T)doseq)query)
r   r   r   r   r"   updateitemsr   _replacer   )r   r   
parsed_urlbase_paramsencoded_paramsr   r   r   _add_url_query_params   s   
	r)   uric                 C   sB   t  }|dur|tdk r| S t| }|jdkrt| ddi} | S )aD  If the provided URI is an S3 URL, add allow_bucket_creation=true as a query
    parameter. For pyarrow >= 9.0.0, this is required in order to allow
    ``S3FileSystem.create_dir()`` to create S3 buckets.

    If the provided URI is not an S3 URL or if pyarrow < 9.0.0 is installed, we return
    the URI unchanged.

    Args:
        uri: The URI that we'll add the query parameter to, if it's an S3 URL.

    Returns:
        A URI with the added allow_bucket_creation=true query parameter, if the provided
        URI is an S3 URL; uri will be returned unchanged otherwise.
    Nz9.0.0s3allow_bucket_creationT)r   r   r   schemer)   )r*   pyarrow_version
parsed_urir   r   r   %add_creatable_buckets_param_if_s3_uriD   s   
r0   )r   typingr   r   urllib.parser   r   r   r   r   packaging.versionr	   r
   r   r   r   __annotations__r   r   strr)   r0   r   r   r   r   <module>   s   
 &