zmc
2023-08-08 e792e9a60d958b93aef96050644f369feb25d61b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
U
ß=®d2ã@sbddlmZddlZddlZddlZddlZddlZddlm    Z    Gdd„dƒZ
Gdd„de ƒZ dS)é)Ú annotationsN)Ú import_stringc@sJeZdZdZdddddœdd„Zdd    d    d    d
œd d „Zd    d    dd œdd„ZdS)ÚConfigAttributez(Makes an attribute forward to the configNÚstrzt.Callable | NoneÚNone)ÚnameÚ get_converterÚreturncCs||_||_dS©N)Ú__name__r)Úselfrr©r úCd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\flask/config.pyÚ__init__szConfigAttribute.__init__út.Any)ÚobjÚownerr    cCs0|dkr |S|j|j}|jdk    r,| |¡}|Sr
)Úconfigr r)r rrÚrvr r rÚ__get__s  
 
zConfigAttribute.__get__)rÚvaluer    cCs||j|j<dSr
)rr )r rrr r rÚ__set__szConfigAttribute.__set__)N)N)r Ú
__module__Ú __qualname__Ú__doc__rrrr r r rr srcsÐeZdZdZd,ddddœ‡fdd„ Zd-dd
d
d œd d „Zd.ejdœddd
dœdd„Zd/dd
d
dœdd„Z    dddœdd„Z
d0ddd
d
d
dœdd„Z d1d d!d
d"œd#d$„Z d2dd
d
d%d&œd'd(„Z dd)œd*d+„Z‡ZS)3ÚConfigaÙWorks exactly like a dict but provides ways to fill it from files
    or special dictionaries.  There are two common patterns to populate the
    config.
 
    Either you can fill the config from a config file::
 
        app.config.from_pyfile('yourconfig.cfg')
 
    Or alternatively you can define the configuration options in the
    module that calls :meth:`from_object` or provide an import path to
    a module that should be loaded.  It is also possible to tell it to
    use the same module and with that provide the configuration values
    just before the call::
 
        DEBUG = True
        SECRET_KEY = 'development key'
        app.config.from_object(__name__)
 
    In both cases (loading from any Python file or loading from modules),
    only uppercase keys are added to the config.  This makes it possible to use
    lowercase values in the config file for temporary values that are not added
    to the config or to define the config keys in the same file that implements
    the application.
 
    Probably the most interesting way to load configurations is from an
    environment variable pointing to a file::
 
        app.config.from_envvar('YOURAPPLICATION_SETTINGS')
 
    In this case before launching the application you have to set this
    environment variable to the file you want to use.  On Linux and OS X
    use the export statement::
 
        export YOURAPPLICATION_SETTINGS='/path/to/config/file'
 
    On windows use `set` instead.
 
    :param root_path: path to which files are read relative from.  When the
                      config object is created by the application, this is
                      the application's :attr:`~flask.Flask.root_path`.
    :param defaults: an optional dictionary of default values
    Nrz dict | Noner)Ú    root_pathÚdefaultsr    cstƒ |p i¡||_dSr
)Úsuperrr)r rr©Ú    __class__r rrKszConfig.__init__FÚbool)Ú variable_nameÚsilentr    cCs6tj |¡}|s(|rdStd|›dƒ‚|j||dS)aùLoads a configuration from an environment variable pointing to
        a configuration file.  This is basically just a shortcut with nicer
        error messages for this line of code::
 
            app.config.from_pyfile(os.environ['YOURAPPLICATION_SETTINGS'])
 
        :param variable_name: name of the environment variable
        :param silent: set to ``True`` if you want silent failure for missing
                       files.
        :return: ``True`` if the file was loaded successfully.
        FzThe environment variable zv is not set and as such configuration could not be loaded. Set this variable and make it point to a configuration file)r#)ÚosÚenvironÚgetÚ RuntimeErrorÚ from_pyfile)r r"r#rr r rÚ from_envvarOs 
ÿzConfig.from_envvarÚFLASK)Úloadszt.Callable[[str], t.Any])Úprefixr+r    c
    Csº|›d}t|ƒ}ttjƒD]˜}| |¡s,qtj|}z ||ƒ}Wntk
rVYnX||d…}d|krv|||<q|}| d¡^}}|D]}    |    |kr¢i||    <||    }qŽ|||<qdS)aLoad any environment variables that start with ``FLASK_``,
        dropping the prefix from the env key for the config key. Values
        are passed through a loading function to attempt to convert them
        to more specific types than strings.
 
        Keys are loaded in :func:`sorted` order.
 
        The default loading function attempts to parse values as any
        valid JSON type, including dicts and lists.
 
        Specific items in nested dicts can be set by separating the
        keys with double underscores (``__``). If an intermediate key
        doesn't exist, it will be initialized to an empty dict.
 
        :param prefix: Load env vars that start with this prefix,
            separated with an underscore (``_``).
        :param loads: Pass each string value to this function and use
            the returned value as the config value. If any error is
            raised it is ignored and the value remains a string. The
            default is :func:`json.loads`.
 
        .. versionadded:: 2.1
        Ú_NÚ__T)ÚlenÚsortedr$r%Ú
startswithÚ    ExceptionÚsplit)
r r,r+Z
len_prefixÚkeyrÚcurrentÚpartsÚtailÚpartr r rÚfrom_prefixed_envgs,
 
 
 
 
zConfig.from_prefixed_env)Úfilenamer#r    c
Cs¼tj |j|¡}t d¡}||_z4t|dd}tt    | 
¡|dƒ|j ƒW5QRXWnXt k
r¬}z:|rŠ|j t jt jt jfkrŠWY¢dSd|j›d|_‚W5d}~XYnX| |¡d    S)
aTUpdates the values in the config from a Python file.  This function
        behaves as if the file was imported as module with the
        :meth:`from_object` function.
 
        :param filename: the filename of the config.  This can either be an
                         absolute filename or a filename relative to the
                         root path.
        :param silent: set to ``True`` if you want silent failure for missing
                       files.
        :return: ``True`` if the file was loaded successfully.
 
        .. versionadded:: 0.7
           `silent` parameter.
        rÚrb)ÚmodeÚexecFú#Unable to load configuration file (ú)NT)r$ÚpathÚjoinrÚtypesÚ
ModuleTypeÚ__file__Úopenr=ÚcompileÚreadÚ__dict__ÚOSErrorÚerrnoÚENOENTÚEISDIRÚENOTDIRÚstrerrorÚ from_object)r r:r#ÚdÚ config_fileÚer r rr(§s
&
 
zConfig.from_pyfilez object | str)rr    cCs:t|tƒrt|ƒ}t|ƒD]}| ¡rt||ƒ||<qdS)aUpdates the values from the given object.  An object can be of one
        of the following two types:
 
        -   a string: in this case the object with that name will be imported
        -   an actual object reference: that object is used directly
 
        Objects are usually either modules or classes. :meth:`from_object`
        loads only the uppercase attributes of the module/class. A ``dict``
        object will not work with :meth:`from_object` because the keys of a
        ``dict`` are not attributes of the ``dict`` class.
 
        Example of module-based configuration::
 
            app.config.from_object('yourapplication.default_config')
            from yourapplication import default_config
            app.config.from_object(default_config)
 
        Nothing is done to the object before loading. If the object is a
        class and has ``@property`` attributes, it needs to be
        instantiated before being passed to this method.
 
        You should not use this function to load the actual configuration but
        rather configuration defaults.  The actual config should be loaded
        with :meth:`from_pyfile` and ideally from a location not within the
        package because the package might be installed system wide.
 
        See :ref:`config-dev-prod` for an example of class-based configuration
        using :meth:`from_object`.
 
        :param obj: an import name or object
        N)Ú
isinstancerrÚdirÚisupperÚgetattr)r rr4r r rrOÄs
 
 zConfig.from_objectTz$t.Callable[[t.IO[t.Any]], t.Mapping])r:Úloadr#Útextr    c
Csštj |j|¡}z*t||rdndƒ}||ƒ}W5QRXWnTtk
rŽ}z6|rl|jtjtjfkrlWY¢dSd|j    ›d|_    ‚W5d}~XYnX| 
|¡S)a"Update the values in the config from a file that is loaded
        using the ``load`` parameter. The loaded data is passed to the
        :meth:`from_mapping` method.
 
        .. code-block:: python
 
            import json
            app.config.from_file("config.json", load=json.load)
 
            import tomllib
            app.config.from_file("config.toml", load=tomllib.load, text=False)
 
        :param filename: The path to the data file. This can be an
            absolute path or relative to the config root path.
        :param load: A callable that takes a file handle and returns a
            mapping of loaded data from the file.
        :type load: ``Callable[[Reader], Mapping]`` where ``Reader``
            implements a ``read`` method.
        :param silent: Ignore the file if it doesn't exist.
        :param text: Open the file in text or binary mode.
        :return: ``True`` if the file was loaded successfully.
 
        .. versionchanged:: 2.3
            The ``text`` parameter was added.
 
        .. versionadded:: 2.0
        Úrr;Fr>r?N) r$r@rArrErIrJrKrLrNÚ from_mapping)r r:rWr#rXÚfrrRr r rÚ    from_fileês"
zConfig.from_filezt.Mapping[str, t.Any] | Noner)ÚmappingÚkwargsr    cKsFi}|dk    r| |¡| |¡| ¡D]\}}| ¡r(|||<q(dS)z¦Updates the config like :meth:`update` ignoring items with
        non-upper keys.
 
        :return: Always returns ``True``.
 
        .. versionadded:: 0.11
        NT)ÚupdateÚitemsrU)r r]r^Zmappingsr4rr r rrZs
 
 
 
zConfig.from_mappingzdict[str, t.Any])Ú    namespaceÚ    lowercaseÚtrim_namespacer    cCsTi}| ¡D]B\}}| |¡s q |r6|t|ƒd…}n|}|rF| ¡}|||<q |S)aiReturns a dictionary containing a subset of configuration options
        that match the specified namespace/prefix. Example usage::
 
            app.config['IMAGE_STORE_TYPE'] = 'fs'
            app.config['IMAGE_STORE_PATH'] = '/var/app/images'
            app.config['IMAGE_STORE_BASE_URL'] = 'http://img.website.com'
            image_store_config = app.config.get_namespace('IMAGE_STORE_')
 
        The resulting dictionary `image_store_config` would look like::
 
            {
                'type': 'fs',
                'path': '/var/app/images',
                'base_url': 'http://img.website.com'
            }
 
        This is often useful when configuration options map directly to
        keyword arguments in functions or class constructors.
 
        :param namespace: a configuration namespace
        :param lowercase: a flag indicating if the keys of the resulting
                          dictionary should be lowercase
        :param trim_namespace: a flag indicating if the keys of the resulting
                          dictionary should not include the namespace
 
        .. versionadded:: 0.11
        N)r`r1r/Úlower)r rarbrcrÚkÚvr4r r rÚ get_namespace-s
 
zConfig.get_namespace)r    cCsdt|ƒj›dt |¡›dS)Nú<ú ú>)Útyper ÚdictÚ__repr__)r r r rrmXszConfig.__repr__)N)F)r*)F)FT)N)TT)r rrrrr)Újsonr+r9r(rOr\rZrgrmÚ __classcell__r r rrrs$+ÿÿ@*û1ÿÿ+r) Ú
__future__rrJrnr$rBÚtypingÚtZwerkzeug.utilsrrrlrr r r rÚ<module>s