L iu?UdZddlmZddlZddlZddlmZmZddlm Z m Z m Z ddl m Z ddlmZddlmZe rdd lmZeeZd ed <ed GddZGddZy)aComponent registry for Custom Components v2. This module defines the data model and in-memory registry for Custom Components v2. During development, component assets (JS/CSS/HTML) may change on disk as build tools produce new outputs. See Also -------- - :class:`streamlit.components.v2.component_file_watcher.ComponentFileWatcher` for directory watching and change notifications. ) annotationsN) dataclassfield) TYPE_CHECKINGAnyFinal)ComponentPathUtils)StreamlitComponentRegistryError) get_logger)MutableMappingr_LOGGERT)frozencVeZdZUdZded<dZded<dZded<dZded<ed d d Z d ed <ed d d Z d ed <ee d d Z ded<dZ ded<dZded<ddZddZeddZeddZ ddZeddZeddZeddZed dZy)!BidiComponentDefinitionaDefinition of a bidirectional component V2. The definition holds inline content or file references for HTML, CSS, and JavaScript, plus metadata used by the runtime to serve assets. When CSS/JS are provided as file paths, their asset-dir-relative URLs are exposed via ``css_url`` and ``js_url`` (or can be overridden with ``css_asset_relative_path``/``js_asset_relative_path``). Parameters ---------- name : str A short, descriptive name for the component. html : str or None, optional HTML content as a string. css : str or None, optional Inline CSS content or an absolute/relative path to a ``.css`` file. Relative paths are interpreted as asset-dir-relative and validated to reside within the component's ``asset_dir``. Absolute paths are rejected by the API. js : str or None, optional Inline JavaScript content or an absolute/relative path to a ``.js`` file. Relative paths are interpreted as asset-dir-relative and validated to reside within the component's ``asset_dir``. Absolute paths are rejected by the API. css_asset_relative_path : str or None, optional Asset-dir-relative URL path to use when serving the CSS file. If not provided, the filename from ``css`` is used when ``css`` is file-backed. js_asset_relative_path : str or None, optional Asset-dir-relative URL path to use when serving the JS file. If not provided, the filename from ``js`` is used when ``js`` is file-backed. strnameN str | NonehtmlcssjsF)defaultinitreprbool _has_css_path _has_js_path)default_factoryrrdict[str, str] _source_pathscss_asset_relative_pathjs_asset_relative_pathci}|j|j\}}|j|j\}}|r"tjj ||d<|r"tjj ||d<t j|d|t j|d|t j|d|y)Nrrrrr) _is_file_pathrrospathdirnameobject __setattr__)self source_paths is_css_pathcss_path is_js_pathjs_paths p/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/streamlit/components/v2/component_registry.py __post_init__z%BidiComponentDefinition.__post_init__^s !% 2 2488 < X"009 G "$''//(";L  !#!9L 4+>4<4,?c4|yt|tr|j}tj| }|r]t j j|r3|}t j j|std|d|fStdy)ayDetermine whether ``content`` is a filesystem path and resolve it. For string inputs that look like paths (contain separators, prefixes, or have common asset extensions), values are normally provided by the v2 public API, which resolves and validates asset-dir-relative inputs and passes absolute paths here. When this dataclass is constructed internally, callers must supply already-resolved absolute paths that have passed the same validation rules upstream. Relative paths are not accepted here. Parameters ---------- content : str or None The potential inline content or path. Returns ------- tuple[bool, str | None] ``(is_path, abs_path)`` where ``is_path`` indicates whether the input was treated as a path and ``abs_path`` is the resolved absolute path if a path, otherwise ``None``. Raises ------ ValueError If ``content`` is treated as a path but the file does not exist, or if a non-absolute, path-like string is provided. )FNzFile does not exist: TztRelative file paths are not accepted in BidiComponentDefinition; pass absolute, pre-validated paths from the v2 API.) isinstancerstripr looks_like_inline_contentr$r%isabsexists ValueError)r)contentstrippedis_likely_pathabs_paths r/r#z%BidiComponentDefinition._is_file_pathss: ? gs #}}H!3!M!Mh!WWN77==)&H77>>(3(+@ )KLL>) J r1cf|j|j|j|jS)a8Return the asset-dir-relative URL path for CSS when file-backed. When present, servers construct ``/_stcore/bidi-components//`` using this value. If ``css_asset_relative_path`` is specified, it takes precedence over the filename derived from ``css``. has_pathvalueoverride)_derive_asset_urlrrr r)s r/css_urlzBidiComponentDefinition.css_urls5%%''((11&  r1cf|j|j|j|jS)a4Return the asset-dir-relative URL path for JS when file-backed. When present, servers construct ``/_stcore/bidi-components//`` using this value. If ``js_asset_relative_path`` is specified, it takes precedence over the filename derived from ``js``. r>)rBrrr!rCs r/js_urlzBidiComponentDefinition.js_urls5%%&&''00&  r1c.|sy|r|St|}tjj|rtjj |S|j ddj d}d|vr|Stjj |S)aCompute asset-dir-relative URL for a file-backed asset. Parameters ---------- has_path Whether the value refers to a file path. value The css/js field value (inline string or path). override Optional explicit asset-dir-relative override. Returns ------- str or None The derived URL path or ``None`` if not file-backed. N\/z./)rr$r%r6basenamereplace removeprefix)r)r?r@rApath_strnorms r/rBz)BidiComponentDefinition._derive_asset_urls& Ou: 77== "77##H- -c*77=d{t>(8(8(>>r1c^|js |jyt|jS)z@Return inline CSS content or ``None`` if file-backed or missing.N)rrrrCs r/ css_contentz#BidiComponentDefinition.css_contents'   !1488}r1c^|js |jyt|jS)zGReturn inline JavaScript content or ``None`` if file-backed or missing.N)rrrrCs r/ js_contentz"BidiComponentDefinition.js_contents&   477|r1c|jS)z7Return inline HTML content or ``None`` if not provided.)rrCs r/ html_contentz$BidiComponentDefinition.html_contentsyyr1c|jS)zReturn source directories for file-backed CSS/JS content. The returned mapping contains keys like ``"js"`` and ``"css"`` with the directory path from which each was loaded. )rrCs r/r*z$BidiComponentDefinition.source_pathss!!!r1returnNone)r9rrWztuple[bool, str | None])rWr)r?rr@rrArrWr)rWr)__name__ __module__ __qualname____doc____annotations__rrrrrrdictrr r!r0r#propertyrDrFrBrPrRrTr*r1r/rr.s)@ ID*CB EFM4Fu5uEL$E$)$UQV$WM>W+/Z.)-J-@*2h         ? ?(2 ?>H ?  ?D""r1rcPeZdZdZd dZ d dZd dZd dZddZd dZ d dZ y )BidiComponentRegistryzRegistry for bidirectional components V2. The registry stores and updates :class:`BidiComponentDefinition` instances in a thread-safe mapping guarded by a lock. cDi|_tj|_y)zCInitialize the component registry with an empty, thread-safe store.N) _components threadingLock_lockrCs r/__init__zBidiComponentRegistry.__init__ sIK^^% r1c |j5|jD]\}}|jd}|std|dt ||jd|jd|jd|jd|jd }||j |<t jd | d d d y #1swYy xYw) zRegister components from processed definition data. Parameters ---------- component_definitions : dict[str, dict[str, Any]] Mapping from component identifier to definition data. rzComponent definition for key 'z"' is missing required 'name' fieldrrrr r!)rrrrr r!z2Registered component %s from processed definitionsN)rgitemsgetr8rrdr debug)r)component_definitions comp_name comp_def_datar definitions r/$register_components_from_definitionsz:BidiComponentRegistry.register_components_from_definitionssZZ ,A,G,G,I ( =$((0$8 Cef5$((.%))%0&**62,9,=,=1-,9+<+<=U+V  /9  + H)'    s B! !F ;D. AB Gr1rb)r\ __future__rr$re dataclassesrrtypingrrr,streamlit.components.v2.component_path_utilsr streamlit.errorsr streamlit.loggerr collections.abcr rYr r]rrbr`r1r/rsn # (,,K<'.H%% $T"T"T"nSGSGr1