Ë
    úmxiÿD  ã                  ó\  — U d dl mZ d dlZd dlZd dlmZmZmZmZm	Z	m
Z
 d dlmZmZmZmZmZ d dlmZ d dlmZ d dlmZ d dlmZ d d	lmZ erd d
lmZ eeeedœZded<    ej>                  d«      Z dddddddœZ!ded<   dZ"ded<    e	dee   ¬«      Z# ed«      	 	 d*	 	 	 	 	 	 	 	 	 	 	 d+d„«       Z$d,d„Z%e
	 	 	 d-	 	 	 	 	 	 	 	 	 	 	 d.d„«       Z&e
	 	 	 d-	 	 	 	 	 	 	 	 	 	 	 	 	 d/d „«       Z&e
	 	 	 d-	 	 	 	 	 	 	 	 	 	 	 d0d!„«       Z&e
	 	 	 d-	 	 	 	 	 	 	 	 	 	 	 	 	 d1d"„«       Z&e
	 	 	 d-	 	 	 	 	 	 	 	 	 	 	 d2d#„«       Z&e
	 	 	 d-	 	 	 	 	 	 	 	 	 	 	 	 	 d3d$„«       Z&e
	 	 d*	 	 	 	 	 	 	 	 	 d4d%„«       Z&e
	 	 d*	 	 	 	 	 	 	 	 	 	 	 d5d&„«       Z&e
	 	 d*	 	 	 	 	 	 	 	 	 	 	 d6d'„«       Z&e
	 	 	 d7	 	 	 	 	 	 	 	 	 	 	 d8d(„«       Z&	 	 	 d7d)„Z&y)9é    )ÚannotationsN)ÚTYPE_CHECKINGÚAnyÚFinalÚLiteralÚTypeVarÚoverload)ÚBaseConnectionÚ SnowflakeCallersRightsConnectionÚSnowflakeConnectionÚSnowparkConnectionÚSQLConnection)Údeprecate_obj_name)ÚStreamlitAPIException)Úcache_resource)Úgather_metrics)Úsecrets_singleton)Ú	timedelta)Ú	snowflakezsnowflake-callers-rightsÚsnowparkÚsqlz+Final[dict[str, type[BaseConnection[Any]]]]Ú_FIRST_PARTY_CONNECTIONSzNo module named \'(.+)\'Úmysqlclientzpsycopg2-binaryÚ
sqlalchemyzsnowflake-connector-pythonzsnowflake-snowpark-python)ÚMySQLdbÚpsycopg2r   r   zsnowflake.connectorzsnowflake.snowparkzFinal[dict[str, str]]Ú_MODULES_TO_PYPI_PACKAGESzenv:r   Ú_USE_ENV_PREFIXÚConnectionClass)ÚboundÚ
connectionc                óR  — 	 	 	 	 	 	 	 	 dd„}t        |t        «      st        |› d�«      ‚t        |«      j	                  dd«      }|j
                  › d|› d|› �|_        |j                  «       }|dvrt        d|› d|› d�«      ‚dd	„} t        |d
|||¬«      |«      } || |fi |¤ŽS )ap  Create an instance of connection_class with the given name and kwargs.

    The weird implementation of this function with the @cache_resource annotated
    function defined internally is done to:
      - Always @gather_metrics on the call even if the return value is a cached one.
      - Allow the user to specify ttl and max_entries when calling st.connection.
    c                ó   —  |dd| i|¤ŽS )NÚconnection_name© r%   )ÚnameÚconnection_classÚkwargss      ú[/home/htdocs/ttos/venv/lib/python3.12/site-packages/streamlit/runtime/connection_factory.pyÚ__create_connectionz/_create_connection.<locals>.__create_connectionQ   s   € ñ  Ñ?°Ð?¸Ñ?Ð?ó    z% is not a subclass of BaseConnection!ú.Ú_)ÚglobalÚsessionzConnection class z has scope 'z*'. Valid values are 'global' or 'session'.c                ó$   — | j                  «        y ©N)Úclose)r!   s    r)   Úon_release_wrappedz._create_connection.<locals>.on_release_wrappedl   s   € Ø×ÑÕr+   zRunning `st.connection(...)`.)Úmax_entriesÚshow_spinnerÚttlÚscopeÚ
on_release)r&   Ústrr'   útype[ConnectionClass]r(   r   Úreturnr   )r!   r   r;   ÚNone)Ú
issubclassr
   r   r9   ÚreplaceÚ__qualname__r7   r   )	r&   r'   r4   r6   r(   r*   Úttl_strr7   r3   s	            r)   Ú_create_connectionrA   A   s  € ð @Øð@Ø%:ð@ØFIð@à	ó@ô
 Ð&¬Ô7Ü#ØÐ Ð EÐFó
ð 	
ô �#‹h×ÑØˆSó€Gð ×+Ñ+Ð
,¨A¨g¨Y°a¸°}ÐEð Ô$ð ×"Ñ"Ó$€EØÐ)Ñ)Ü#ØÐ 0Ð1°¸e¸Wð E)ð )ó
ð 	
ó
ðœ.ØØ4ØØØ%ôð óÐñ ˜tÐ%5Ñ@¸Ñ@Ð@r+   c                óN   — | t         v r	t         |    S t        d| › dt         › �«      ‚)NzInvalid connection 'z!'. Supported connection classes: )r   r   )r'   s    r)   Ú_get_first_party_connectionrC   z   s>   € ØÔ3Ñ3Ü'Ð(8Ñ9Ð9ä
Ø
Ð/Ð0ð 1)Ü)AÐ(Bð	Dóð r+   c                 ó   — y r1   r%   ©r&   r4   r6   Ú
autocommitr(   s        r)   Úconnection_factoryrG   „   ó   € ð 	r+   c                 ó   — y r1   r%   ©r&   Útyper4   r6   rF   r(   s         r)   rG   rG   �   ó   € ð 	r+   c                 ó   — y r1   r%   rE   s        r)   rG   rG   ›   rH   r+   c                 ó   — y r1   r%   rJ   s         r)   rG   rG   ¦   rL   r+   c                 ó   — y r1   r%   rE   s        r)   rG   rG   ²   rH   r+   c                 ó   — y r1   r%   rJ   s         r)   rG   rG   ½   rL   r+   c                 ó   — y r1   r%   )r&   r4   r6   r(   s       r)   rG   rG   É   s   € ð 	r+   c                 ó   — y r1   r%   ©r&   rK   r4   r6   r(   s        r)   rG   rG   Ó   rH   r+   c                 ó   — y r1   r%   rS   s        r)   rG   rG   Þ   rH   r+   c                 ó   — y r1   r%   rS   s        r)   rG   rG   é   rH   r+   c                ó"  — | j                  t        «      r(| j                  t        «      }t        j                  |   } |}|€7| t
        v rt        | «      }n#t        j                  «        t        d   |    d   }t        |t        «      rad|v rR|j                  d«      }|j                  «       }ddl}	|	j                  dj                  |«      «      }
t!        |
|«      }nt        |«      }	 t#        | |f||dœ|¤Ž}t        |t$        «      rt'        |ddd	«      }|S # t(        $ rj}t        |«      }t+        j,                  t.        |«      }d
}|r,t0        j3                  |j5                  d«      «      }|rd|› d�}t)        |› d|› �«      ‚d}~ww xY w)aw  Create a new connection to a data store or API, or return an existing one.

    Configuration options, credentials, and secrets for connections are
    combined from the following sources:

    - The keyword arguments passed to this command.
    - The app's ``secrets.toml`` files.
    - Any connection-specific configuration files.

    The connection returned from ``st.connection`` is internally cached with
    ``st.cache_resource``. Connection types with a scope of ``"global"`` will be shared
    between sessions.

    Parameters
    ----------
    name : str
        The connection name used for secrets lookup in ``secrets.toml``.
        Streamlit uses secrets under ``[connections.<name>]`` for the
        connection. ``type`` will be inferred if ``name`` is one of the
        following: ``"snowflake"``, ``"snowpark"``, or ``"sql"``.

    type : str, connection class, or None
        The type of connection to create. This can be one of the following:

        - ``None`` (default): Streamlit will infer the connection type from
          ``name``. If the type is not inferable from ``name``, the type must
          be specified in ``secrets.toml`` instead.
        - ``"snowflake"``: Streamlit will initialize a connection with
          |SnowflakeConnection|_.
        - ``"snowflake-callers-rights"``: Streamlit will initialize a
          ``"snowflake"``-type connection, except the connection uses the
          current viewer's identity tokens instead of the app's connection
          configuration.
        - ``"snowpark"``: Streamlit will initialize a connection with
          |SnowparkConnection|_. This is deprecated.
        - ``"sql"``: Streamlit will initialize a connection with
          |SQLConnection|_.
        - A string path to an importable class: This must be a dot-separated
          module path ending in the importable class. Streamlit will import the
          class and initialize a connection with it. The class must extend
          ``st.connections.BaseConnection``.
        - An imported class reference: Streamlit will initialize a connection
          with the referenced class, which must extend
          ``st.connections.BaseConnection``.

        .. Important::
           Connections of type ``"snowflake-callers-rights"`` only work when
           they run in a Snowflake Snowpark Container Services environment. If
           they are used in a local environment, they will raise exceptions.

           For local development, use an environment variable or secret to
           logically switch between a ``"snowflake"`` and
           ``"snowflake-callers-rights"`` connection depending on the runtime
           environment.

        .. |SnowflakeConnection| replace:: ``SnowflakeConnection``
        .. _SnowflakeConnection: https://docs.streamlit.io/develop/api-reference/connections/st.connections.snowflakeconnection
        .. |SnowparkConnection| replace:: ``SnowparkConnection``
        .. _SnowparkConnection: https://docs.streamlit.io/develop/api-reference/connections/st.connections.snowparkconnection
        .. |SQLConnection| replace:: ``SQLConnection``
        .. _SQLConnection: https://docs.streamlit.io/develop/api-reference/connections/st.connections.sqlconnection

    max_entries : int or None
        The maximum number of connections to keep in the cache.
        If this is ``None`` (default), the cache is unbounded. Otherwise, when
        a new entry is added to a full cache, the oldest cached entry is
        removed.
    ttl : float, timedelta, or None
        The maximum number of seconds to keep results in the cache.
        If this is ``None`` (default), cached results do not expire with time.
    **kwargs : any
        Connection-specific keyword arguments that are passed to the
        connection's ``._connect()`` method. ``**kwargs`` are typically
        combined with (and take precedence over) key-value pairs in
        ``secrets.toml``. To learn more, see the specific connection's
        documentation.

    Returns
    -------
    Subclass of BaseConnection
        An initialized connection object of the specified ``type``.

    Examples
    --------
    **Example 1: Inferred connection type**

    The easiest way to create a first-party (SQL, Snowflake, or Snowpark) connection is
    to use their default names and define corresponding sections in your ``secrets.toml``
    file. The following example creates a ``"sql"``-type connection.

    .. code-block:: toml
        :filename: .streamlit/secrets.toml

        [connections.sql]
        dialect = "xxx"
        host = "xxx"
        username = "xxx"
        password = "xxx"

    .. code-block:: python
        :filename: streamlit_app.py

        import streamlit as st

        conn = st.connection("sql")

    **Example 2: Named connections**

    Creating a connection with a custom name requires you to explicitly
    specify the type. If ``type`` is not passed as a keyword argument, it must
    be set in the appropriate section of ``secrets.toml``. The following
    example creates two ``"sql"``-type connections, each with their own
    custom name. The first defines ``type`` in the ``st.connection`` command;
    the second defines ``type`` in ``secrets.toml``.

    .. code-block:: toml
        :filename: .streamlit/secrets.toml

        [connections.first_connection]
        dialect = "xxx"
        host = "xxx"
        username = "xxx"
        password = "xxx"

        [connections.second_connection]
        type = "sql"
        dialect = "yyy"
        host = "yyy"
        username = "yyy"
        password = "yyy"

    .. code-block:: python
        :filename: streamlit_app.py

        import streamlit as st

        conn1 = st.connection("first_connection", type="sql")
        conn2 = st.connection("second_connection")

    **Example 3: Using a path to the connection class**

    Passing the full module path to the connection class can be useful,
    especially when working with a custom connection. Although this is not the
    typical way to create first party connections, the following example
    creates the same type of connection as one with ``type="sql"``. Note that
    ``type`` is a string path.

    .. code-block:: toml
        :filename: .streamlit/secrets.toml

        [connections.my_sql_connection]
        url = "xxx+xxx://xxx:xxx@xxx:xxx/xxx"

    .. code-block:: python
        :filename: streamlit_app.py

        import streamlit as st

        conn = st.connection(
            "my_sql_connection", type="streamlit.connections.SQLConnection"
        )

    **Example 4: Importing the connection class**

    You can pass the connection class directly to the ``st.connection``
    command. Doing so allows static type checking tools such as ``mypy`` to
    infer the exact return type of ``st.connection``. The following example
    creates the same connection as in Example 3.

    .. code-block:: toml
        :filename: .streamlit/secrets.toml

        [connections.my_sql_connection]
        url = "xxx+xxx://xxx:xxx@xxx:xxx/xxx"

    .. code-block:: python
        :filename: streamlit_app.py

        import streamlit as st
        from streamlit.connections import SQLConnection

        conn = st.connection("my_sql_connection", type=SQLConnection)

    NÚconnectionsrK   r,   r   )r4   r6   zconnection("snowpark")zconnection("snowflake")z
2024-04-01z@You may be missing a dependency required to use this connection.é   zYou need to install the 'z!' package to use this connection.z. )Ú
startswithr   ÚremoveprefixÚosÚenvironr   rC   r   Úload_if_toml_existsÚ
isinstancer9   ÚsplitÚpopÚ	importlibÚimport_moduleÚjoinÚgetattrrA   r   r   ÚModuleNotFoundErrorÚreÚsearchÚ_MODULE_EXTRACTION_REGEXr   ÚgetÚgroup)r&   rK   r4   r6   r(   Úenvvar_namer'   ÚpartsÚ	classnamera   Úconnection_moduleÚconnÚeÚ
err_stringÚmissing_moduleÚ
extra_infoÚpypi_packages                    r)   rG   rG   ô   s£  € ð@ ‡�”Ô'Ø×'Ñ'¬Ó8ˆÜ�z‰z˜+Ñ&ˆð
 ÐàÐØÔ+Ñ+ô  ;¸4Ó@Ñô ×1Ñ1Ô3Ü0°Ñ?ÀÑEÀfÑMÐäÐ"¤CÔ(ð
 Ð"Ñ"Ø$×*Ñ*¨3Ó/ˆEØŸ	™	›ˆIãà )× 7Ñ 7¸¿¹À»Ó HÐÜ&Ð'8¸)ÓDÑä:Ð;KÓLÐð8Ü!ØÐ"ð
Ø0;Àñ
ØHNñ
ˆô �dÔ.Ô/Ü%ØØ(Ø)Øó	ˆDð ˆøÜò 
8Ü˜“Vˆ
ÜŸ™Ô#;¸ZÓHˆàWˆ
ÙÜ4×8Ñ8¸×9MÑ9MÈaÓ9PÓQˆLÙØ8¸¸ÐFgÐh�
ä! Q C r¨*¨Ð"6Ó7Ð7ûð
8ús   Ã+/D Ä	FÄ$A%F	Æ	F)NN)r&   r9   r'   r:   r4   ú
int | Noner6   úfloat | timedelta | Noner(   r   r;   r   )r'   r9   r;   ztype[BaseConnection[Any]])NNF)r&   úLiteral['sql']r4   ru   r6   rv   rF   Úboolr(   r   r;   r   )r&   r9   rK   rw   r4   ru   r6   rv   rF   rx   r(   r   r;   r   )r&   úLiteral['snowflake']r4   ru   r6   rv   rF   rx   r(   r   r;   r   )r&   r9   rK   ry   r4   ru   r6   rv   rF   rx   r(   r   r;   r   )r&   ú#Literal['snowflake-callers-rights']r4   ru   r6   rv   rF   rx   r(   r   r;   r   )r&   r9   rK   rz   r4   ru   r6   rv   rF   rx   r(   r   r;   r   )
r&   úLiteral['snowpark']r4   ru   r6   rv   r(   r   r;   r   )r&   r9   rK   r{   r4   ru   r6   rv   r(   r   r;   r   )r&   r9   rK   r:   r4   ru   r6   rv   r(   r   r;   r   )NNN)r&   r9   rK   z
str | Noner4   ru   r6   rv   r(   r   r;   zBaseConnection[Any])'Ú
__future__r   r[   rf   Útypingr   r   r   r   r   r	   Ústreamlit.connectionsr
   r   r   r   r   Ústreamlit.deprecation_utilr   Ústreamlit.errorsr   Ústreamlit.runtime.cachingr   Ústreamlit.runtime.metrics_utilr   Ústreamlit.runtime.secretsr   Údatetimer   r   Ú__annotations__Úcompilerh   r   r   r   rA   rC   rG   r%   r+   r)   ú<module>r‡      s•  ðö #ã 	Û 	ß H× H÷õ õ :Ý 2Ý 4Ý 9Ý 7áÝ"ð %Ø @Ø"Øñ	IÐ ÐEó ð &˜2Ÿ:™:Ð&AÓBÐ àØ!ØØ-Ø7Ø5ñ4Ð Ð0ó ð  €�Ó ñ
 Ð+°>À#Ñ3FÔG€ñ �Óð #Ø$(ð	5AØ
ð5Aà+ð5Að ð5Að 
"ð	5Að
 ð5Að ò5Aó ð5Aópð 
ð #Ø$(Øð		Ø
ð	àð	ð 
"ð	ð ð		ð
 ð	ð ò	ó 
ð	ð 
ð #Ø$(Øð	Ø
ð	à
ð	ð ð	ð 
"ð		ð
 ð	ð ð	ð ò	ó 
ð	ð 
ð #Ø$(Øð		Ø
ð	àð	ð 
"ð	ð ð		ð
 ð	ð ò	ó 
ð	ð 
ð #Ø$(Øð	Ø
ð	à
ð	ð ð	ð 
"ð		ð
 ð	ð ð	ð ò	ó 
ð	ð 
ð #Ø$(Øð		Ø
-ð	àð	ð 
"ð	ð ð		ð
 ð	ð &ò	ó 
ð	ð 
ð #Ø$(Øð	Ø
ð	à
-ð	ð ð	ð 
"ð		ð
 ð	ð ð	ð &ò	ó 
ð	ð 
ð #Ø$(ð	Ø
ð	àð	ð 
"ð	ð ð		ð
 ò	ó 
ð	ð 
ð #Ø$(ð		Ø
ð	à
ð	ð ð	ð 
"ð		ð
 ð	ð ò	ó 
ð	ð 
ð #Ø$(ð		Ø
ð	à
ð	ð ð	ð 
"ð		ð
 ð	ð ò	ó 
ð	ð 
ð Ø"Ø$(ð		Ø
ð	à
ð	ð ð	ð 
"ð		ð
 ð	ð ò	ó 
ð	ð 
ØØô	~8r+   