o
    R+ iD                     @  s   d Z ddlmZ ddlZddlZddlmZ ddlm	Z	 ddl
mZmZ ddlmZ ddlmZ dd	lmZ d
dlmZmZ d
dlmZmZmZ ddlmZ erVddlmZ G dd deZdddddd ddZddgZ dS )!zDotenv file settings source.    )annotationsN)Mapping)Path)TYPE_CHECKINGAny)dotenv_values)
get_origin)is_union_origin   )ENV_FILE_SENTINEL
DotenvType)_annotation_is_complex_union_is_complexparse_env_vars   )EnvSettingsSource)BaseSettingsc                	      s   e Zd ZdZeddddddddf	d- fddZd.ddZedddddd/d!d"Zd0d#d$Z	d.d%d&Z
d1 fd(d)Zd2d+d,Z  ZS )3DotEnvSettingsSourcezB
    Source class for loading settings values from env files.
    Nsettings_clstype[BaseSettings]env_fileDotenvType | Noneenv_file_encoding
str | Nonecase_sensitivebool | None
env_prefixenv_nested_delimiterenv_nested_max_split
int | Noneenv_ignore_emptyenv_parse_none_strenv_parse_enumsreturnNonec              
     sR   |t kr|n|jd| _|d ur|n|jd| _t |||||||	|
 d S )Nr   r   )r   Zmodel_configgetr   r   super__init__)selfr   r   r   r   r   r   r   r    r!   r"   	__class__ v/home/app/PaddleOCR-VL-test/.venv_paddleocr/lib/python3.10/site-packages/pydantic_settings/sources/providers/dotenv.pyr'   "   s   zDotEnvSettingsSource.__init__Mapping[str, str | None]c                 C  s   |   S N)_read_env_filesr(   r+   r+   r,   _load_env_vars>   s   z#DotEnvSettingsSource._load_env_varsFencodingr   ignore_emptyparse_none_str	file_pathr   r3   boolr4   r5   c                C  s   t | |pdd}t||||S )Nutf8)r3   )r   r   )r6   r3   r   r4   r5   Z	file_varsr+   r+   r,   _static_read_env_fileA   s   	z*DotEnvSettingsSource._static_read_env_filec                 C  s   | j || j| j| j| jdS )Nr2   )r9   r   r   r    r!   )r(   r6   r+   r+   r,   _read_env_fileM   s   z#DotEnvSettingsSource._read_env_filec                 C  s^   | j }|d u r	i S t|ttjfr|g}i }|D ]}t| }| r,|| 	| q|S r.   )
r   
isinstancestrosPathLiker   
expanduseris_fileupdater:   )r(   Z	env_filesZdotenv_varsr   Zenv_pathr+   r+   r,   r/   Y   s   z$DotEnvSettingsSource._read_env_filesdict[str, Any]c                   s  t   }| jddk}| j D ]o\}}|r%||v s%| jr&|| jjv r&qd}| jj D ]6\}}| 	||D ]'\}}	}||	ks[t
|j|jsVtt|jr_t|j|jr_||	r_d} nq8|rd nq.|s|r}|| jr}|t| jd  }
|||
< q|||< q|S )NextraZforbidFT)r&   __call__configr%   Zenv_varsitemsr   r   Zmodel_fieldsZ_extract_field_infor   
annotationmetadatar	   r   r   
startswithlen)r(   dataZis_extra_allowedenv_nameZ	env_valueZenv_used
field_namefield_Zfield_env_nameZnormalized_env_namer)   r+   r,   rD   i   s<   


zDotEnvSettingsSource.__call__r<   c              
   C  s.   | j j d| jd| jd| jd| jd
S )Nz
(env_file=z, env_file_encoding=z, env_nested_delimiter=z, env_prefix_len=))r*   __name__r   r   r   Zenv_prefix_lenr0   r+   r+   r,   __repr__   s   zDotEnvSettingsSource.__repr__)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r   r!   r   r"   r   r#   r$   )r#   r-   r6   r   r3   r   r   r7   r4   r7   r5   r   r#   r-   )r6   r   r#   r-   )r#   rB   )r#   r<   )rQ   
__module____qualname____doc__r   r'   r1   staticmethodr9   r:   r/   rD   rR   __classcell__r+   r+   r)   r,   r      s.    


#r   Fr2   r6   r   r3   r   r   r7   r4   r5   r#   r-   c                C  s    t dt tj| ||||dS )Nzmread_env_file will be removed in the next version, use DotEnvSettingsSource._static_read_env_file if you mustr2   )warningswarnDeprecationWarningr   r9   )r6   r3   r   r4   r5   r+   r+   r,   read_env_file   s   r\   rS   )!rV   
__future__r   Z_annotationsr=   rY   collections.abcr   pathlibr   typingr   r   Zdotenvr   Z pydantic._internal._typing_extrar   Ztyping_inspection.introspectionr	   typesr   r   utilsr   r   r   envr   Zpydantic_settings.mainr   r   r\   __all__r+   r+   r+   r,   <module>   s,    y