MCPcopy Create free account
hub / github.com/streamlit/streamlit / _parse

Method _parse

lib/streamlit/runtime/secrets.py:379–422  ·  view source on GitHub ↗

Parse our secrets.toml files if they're not already parsed. This function is safe to call from multiple threads. Raises ------ StreamlitSecretNotFoundError Raised if secrets.toml doesn't exist.

(self)

Source from the content-addressed store, hash-verified

377 raise StreamlitSecretNotFoundError(error_msg)
378
379 def _parse(self) -> Mapping[str, Any]:
380 """Parse our secrets.toml files if they're not already parsed.
381 This function is safe to call from multiple threads.
382
383 Raises
384 ------
385 StreamlitSecretNotFoundError
386 Raised if secrets.toml doesn't exist.
387
388 """
389 # Avoid taking a lock for the common case where secrets are already
390 # loaded.
391 secrets = self._secrets
392 if secrets is not None:
393 return secrets
394
395 with self._lock:
396 if self._secrets is not None:
397 return self._secrets
398
399 secrets = {}
400
401 file_paths = config.get_option("secrets.files")
402 found_secrets_file = False
403 for path in file_paths:
404 path_secrets, found_secrets_file_in_path = self._parse_file_path(path)
405 found_secrets_file = found_secrets_file or found_secrets_file_in_path
406 secrets.update(path_secrets)
407
408 if not found_secrets_file:
409 error_msg = (
410 secret_error_messages_singleton.get_no_secrets_found_message(
411 file_paths
412 )
413 )
414 raise StreamlitSecretNotFoundError(error_msg)
415
416 for k, v in secrets.items():
417 self._maybe_set_environment_variable(k, v)
418
419 self._secrets = secrets
420 self._maybe_install_file_watchers()
421
422 return self._secrets
423
424 def to_dict(self) -> dict[str, Any]:
425 """Converts the secrets store into a nested dictionary, where nested AttrDict objects are

Callers 14

load_if_toml_existsMethod · 0.95
to_dictMethod · 0.95
_on_secrets_changedMethod · 0.95
__getattr__Method · 0.95
__getitem__Method · 0.95
__repr__Method · 0.95
__len__Method · 0.95
has_keyMethod · 0.95
keysMethod · 0.95
valuesMethod · 0.95
itemsMethod · 0.95

Calls 7

_parse_file_pathMethod · 0.95
updateMethod · 0.45
itemsMethod · 0.45