o
    ²Çh·  ã                   @  s    U d dl mZ d dlZd dlZd dlZd dlZd dlmZ i Zde	d< ej
 ej
 d¡d¡Zej de¡Zejfd	d
„Zdd„ Zddd„Zeeeƒ eeƒ dS )é    )ÚannotationsN)ÚAnyzdict[str, dict[str, Any]]Úconfú~z.config/fsspecÚFSSPEC_CONFIG_DIRc           	      C  sB  g }|D ]~}|  d¡rtt|ƒdkrt|d dkrt| d¡dkr$| |¡ qz	t || ¡}W n tjjyL } zt 	d|› d|› ¡ W Y d}~qd}~ww t
|tƒrf| dd¡\}}|  | ¡ i ¡ |¡ qt 	d|› dt|ƒ› ¡ q|  d	¡r‚t 	d|› d
¡ q|D ]}| dd¡\}}}|| |  | ¡ i ¡| ¡ < q…dS )aÅ  Set config values from environment variables

    Looks for variables of the form ``FSSPEC_<protocol>`` and
    ``FSSPEC_<protocol>_<kwarg>``. For ``FSSPEC_<protocol>`` the value is parsed
    as a json dictionary and used to ``update`` the config of the
    corresponding protocol. For ``FSSPEC_<protocol>_<kwarg>`` there is no
    attempt to convert the string value, but the kwarg keys will be lower-cased.

    The ``FSSPEC_<protocol>_<kwarg>`` variables are applied after the
    ``FSSPEC_<protocol>`` ones.

    Parameters
    ----------
    conf_dict : dict(str, dict)
        This dict will be mutated
    envdict : dict-like(str, str)
        Source for the values - usually the real environment
    ÚFSSPEC_é   Ú_é   zIgnoring environment variable z due to a parse failure: Nz due to not being a dict: ÚFSSPECz! due to having an unexpected nameé   )Ú
startswithÚlenÚcountÚappendÚjsonÚloadsÚdecoderÚJSONDecodeErrorÚwarningsÚwarnÚ
isinstanceÚdictÚsplitÚ
setdefaultÚlowerÚupdateÚtype)	Ú	conf_dictÚenvdictÚ
kwarg_keysÚkeyÚvalueÚexr	   ÚprotoÚkwarg© r&   úa/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/fsspec/config.pyÚset_conf_env   s>   "
ÿ€ÿ
ÿÿ

ÿ€þr(   c              	   C  sê   t j | ¡sdS tt  | ¡ƒ}|D ]a}| d¡r=t ¡ }| t j 	| |¡¡ |D ]}|dkr/q(| 
|i ¡ t|| ƒ¡ q(| d¡rrtt j 	| |¡ƒ}t |¡}W d  ƒ n1 s[w   Y  |D ]}| 
|i ¡ t|| ƒ¡ qbqdS )a¥  Set config values from files

    Scans for INI and JSON files in the given dictionary, and uses their
    contents to set the config. In case of repeated values, later values
    win.

    In the case of INI files, all values are strings, and these will not
    be converted.

    Parameters
    ----------
    cdir : str
        Directory to search
    conf_dict : dict(str, dict)
        This dict will be mutated
    Nz.iniÚDEFAULTz.json)ÚosÚpathÚisdirÚsortedÚlistdirÚendswithÚconfigparserÚConfigParserÚreadÚjoinr   r   r   Úopenr   Úload)Úcdirr   ÚallfilesÚfnÚinir!   ÚfÚjsr&   r&   r'   Úset_conf_files@   s&   

ÿ€ôr<   c                 C  sf   |du rt }t| jttfƒr| jn| jg}i }|D ]}||v r&| || ¡ q|jdi |¤Ž |}|S )a°  Supply default values for kwargs when instantiating class

    Augments the passed kwargs, by finding entries in the config dict
    which match the classes ``.protocol`` attribute (one or more str)

    Parameters
    ----------
    cls : file system implementation
    kwargs : dict
    conf_dict : dict of dict
        Typically this is the global configuration

    Returns
    -------
    dict : the modified set of kwargs
    Nr&   )r   r   ÚprotocolÚtupleÚlistr   )ÚclsÚkwargsr   ÚprotosÚkwr$   r&   r&   r'   Úapply_configc   s   €rD   )N)Ú
__future__r   r0   r   r*   r   Útypingr   r   Ú__annotations__r+   r3   Ú
expanduserÚdefault_conf_dirÚenvironÚgetÚconf_dirr(   r<   rD   r&   r&   r&   r'   Ú<module>   s    2
#
