a cD6@slddlZddlZddlmZddlmZmZmZmZm Z m Z m Z m Z m Z mZmZddlmZmZddlmZddlmZddlmZmZmZmZdd lmZmZmZee Z!ed ge eeffZ"eee ee ed ffZ#Gd d d e$Z%Gdd d eZ&GdddZ'GdddZ(GdddZ)dddeee*e ee efdddZ+eee*e edddZ,dS)N)Path) AbstractSetAnyCallableClassVarDictListMappingOptionalTupleTypeUnion) BaseConfigExtra) ModelField) BaseModel)StrPathdisplay_as_type get_originis_union) deep_update path_type sequence_like BaseSettings.c@s eZdZdS) SettingsErrorN)__name__ __module__ __qualname__rrb/workspaces/shunt/resources/test-fastapi/venv/lib/python3.9/site-packages/pydantic/env_settings.pyrsrc seZdZUdZedddfeeeeeeeee ddfdd Z d e ee feeeeeeeee ee fdddZ Gd d d e Zeeeed <ZS) rz Base class for settings, allowing values to be overridden by environment variables. This is useful in production for secrets you do not wish to save in code, it plays nicely with docker(-compose), Heroku and any 12 factor app design. N) _env_file_env_file_encoding_env_nested_delimiter _secrets_dirvaluesreturnc s&tjfi|j|||||ddS)N)r!r"r#r$)super__init__ _build_values)Z__pydantic_self__r!r"r#r$r% __class__rr r(s zBaseSettings.__init__) init_kwargsr!r"r#r$r&c st|d}t|tkr|njj|dur*|njj|dur<|njjtjjd}t |p^jj d}jj |||d} | rt t fdd| DSiSdS)Nr,env_fileenv_file_encodingenv_nested_delimiterenv_prefix_len secrets_dir) init_settings env_settingsfile_secret_settingscsg|] }|qSrr).0sourceselfrr Kz.BaseSettings._build_values..)InitSettingsSourceEnvSettingsSourceenv_file_sentinel __config__r/r0r1len env_prefixSecretsSettingsSourcer4customise_sourcesrreversed) r;r,r!r"r#r$r5r6r7sourcesrr:r r)1s   zBaseSettings._build_valuesc@seZdZUdZeed<dZeeed<dZ eeed<dZ eeed<dZ ee ed<dZ eed <ejZeed <dZeed <d Zeed <eeddddZeeeeeedfdddZeeeedddZdS)zBaseSettings.ConfigrCNr/r0r1r4T validate_allextraarbitrary_types_allowedFcase_sensitivefieldr&cCs||j}|dp"|jjd}|durN|jr>tdt|j |jh}nRt |t r`|h}n@t |t t frt|}n,t|rt|}ntd|dt|d|js|dd|D}||jjd<dS) Nenvzaliases are no longer used by BaseSettings to define which environment variables to read. Instead use the "env" field setting. See https://pydantic-docs.helpmanual.io/usage/settings/#environment-variable-nameszinvalid field env: z (z ); should be string, list or setcss|]}|VqdSNlower)r8nrrr ur=z4BaseSettings.Config.prepare_field.. env_names)Zget_field_infonameget field_inforJZ has_aliaswarningswarn FutureWarningrC isinstancestrset frozensetrlist TypeErrorrrLr+)clsrNZfield_info_from_configrOrUrrr prepare_field\s&   z!BaseSettings.Config.prepare_field.)r5r6r7r&cCs |||fSrPr)rbr5r6r7rrr rExsz%BaseSettings.Config.customise_sources) field_nameraw_valr&cCs ||SrP)Z json_loads)rbrdrerrr parse_env_varsz!BaseSettings.Config.parse_env_var)rrrrCr]__annotations__r/r DotenvTyper0r1r4rrIboolrZforbidrJrKrL classmethodrrcSettingsSourceCallabler rErrfrrrr ConfigQs&      rlrA)NNNN)rrr__doc__r@r rhr]rrr(rr)rrlrr rg __classcell__rrr*r rs6    5c@sLeZdZdZeeefdddZeeeefdddZ eddd Z d S) r>r-cCs ||_dSrPr-)r;r,rrr r(szInitSettingsSource.__init__settingsr&cCs|jSrPr-)r;rprrr __call__szInitSettingsSource.__call__r&cCsd|jdS)NzInitSettingsSource(init_kwargs=)r-r:rrr __repr__szInitSettingsSource.__repr__N) rrr __slots__rr]rr(rrqrtrrrr r>sr>c@seZdZdZdeeeeeeedddZe e ee fdddZ e e eeefd d d Zeee e fd d dZeeeeefe ee fdddZedddZdS)r?r.NrcCs||_||_||_||_dSrPr.)r;r/r0r1r2rrr r(szEnvSettingsSource.__init__roc CsVi}|jjrtj}nddtjD}||jj}|rFi||}|jD]}d}|jj dD]}| |}|durfqqf| |\}} |r>|dur| ||} | r| ||j <nz|j|j|}Wn<ty } z"| std|d| WYd} ~ n d} ~ 00t|tr2t|| ||||j <n |||j <qP|durP|||j <qP|S)zP Build environment variables suitable for passing to the Model. cSsi|]\}}||qSrrQr8kvrrr r=z.EnvSettingsSource.__call__..NrUerror parsing env var "")rArLosenvironitems_read_env_files __fields__r%rXrJrWfield_is_complexexplode_env_varsaliasrfrV ValueErrorrr\dictr) r;rpdenv_vars dotenv_varsrNenv_valenv_name is_complexallow_parse_failureZ env_val_builterrr rqs<    (   zEnvSettingsSource.__call__)rLr&cCsd|j}|duriSt|ttjfr(|g}i}|D].}t|}|r0|t ||j |dq0|S)NencodingrL) r/r\r]r|PathLiker expanduseris_fileupdate read_env_filer0)r;rLZ env_filesrr/Zenv_pathrrr rs z!EnvSettingsSource._read_env_filesrMcCsH|rd}n2tt|jr<|jr.T)FF)rrrtype_Z sub_fieldsany)r;rNrrrr rs (z"EnvSettingsSource.field_is_complex)rNrr&c sfdd|jjdD}i}|D]d\}tfdd|DsFq&jd}|j^}}} |} |D]} | | i} qp|| | <q&|S)z Process env_vars and extract the values of keys containing env_nested_delimiter into nested dictionaries. This is applied to a single field, hence filtering by env_var prefix. csg|]}|jqSr)r1)r8rr:rr r<r=z6EnvSettingsSource.explode_env_vars..rUc3s|]}|VqdSrP) startswith)r8prefix)rrr rTr=z5EnvSettingsSource.explode_env_vars..N)rXrJr~rr2splitr1 setdefault) r;rNrprefixesresultrZenv_name_without_prefix_keysZlast_keyenv_varkeyr)rr;r rs z"EnvSettingsSource.explode_env_varsrrcCsd|jd|jd|jdS)NzEnvSettingsSource(env_file=z, env_file_encoding=z, env_nested_delimiter=rs)r/r0r1r:rrr rtszEnvSettingsSource.__repr__)Nr)rrrrur rhr]intr(rrrrqrirrr rr rrtrrrr r?s / &r?c@sHeZdZdZeedddZeee e fdddZ e ddd Z d S) rDr3cCs ||_dSrPr3)r;r4rrr r(szSecretsSettingsSource.__init__roc Cs*i}|jdur|St|j}|s>td|d|S|sXtdt||j D]}|j j dD]}t |||jj}|sqr|r|}|rz|j|j|}Wn6ty}ztd|d|WYd}~n d}~00|||j<qrtjd|d t|d d d qrqb|S) z4 Build fields from "secrets" files. Nz directory "z" does not existz.secrets_dir must reference a directory, not a rUrzr{zattempted to load secret file "z" but found a z instead.) stacklevel)r4rrexistsrYrZis_dirrrrr%rXrJfind_case_pathrArLr read_textstriprrfrVrr) r;rpZsecretsZ secrets_pathrNrpathZ secret_valuerrrr rqs6   (  zSecretsSettingsSource.__call__rrcCsd|jdS)Nz"SecretsSettingsSource(secrets_dir=rsr3r:rrr rt>szSecretsSettingsSource.__repr__N) rrrrur rr(rrr]rrqrtrrrr rDs)rDFr) file_pathrrLr&c Csnzddlm}Wn.ty>}ztd|WYd}~n d}~00|||pJdd}|sfdd|DS|SdS)Nr) dotenv_valueszBpython-dotenv is not installed, run `pip install pydantic[dotenv]`utf8)rcSsi|]\}}||qSrrQrvrrr ryLr=z!read_env_file..)Zdotenvr ImportErrorr~)rrrLrrZ file_varsrrr rBs r)dir_path file_namerLr&cCsB|D]4}|j|kr|S|s|j|kr|SqdS)zZ Find a file within path's directory matching filename, optionally ignoring case. N)iterdirrVrR)rrrLrrrr rQs    r)-r|rYpathlibrtypingrrrrrrr r r r r configrrfieldsrmainrrrrrutilsrrrr]objectr@rkrhrrrr>r?rDrirrrrrr s, 4   s y4