
    itD              
          d dl Z d dlmZmZmZmZ d dl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 dd	lmZ d
efdZd Zded
ee
ef         fdZ	 	 	 	 d"deeeef                  deeeef                  dee         dee         fdZ	 d#deeeef                  d
efdZd Zd Zded
dfdZdeded
dfdZdeded
dfdZded
dfdZdeeef         d ed
dfd!Z dS )$    N)AnyCallableOptionalUnion   )
ArrowArray)	DataFrame)	base_impl)driver_mode)errors)
thick_implreturnc                  (    t          j                    S )z
    This function can only be called when python-oracledb is in Thick mode.
    Using it in Thin mode will throw an exception.
    )r   clientversion     ^/var/www/html/Pagina-Ingenieria-Requisitos/venv/lib/python3.11/site-packages/oracledb/utils.pyr   r   ,   s    
 #%%%r   c                  d    t          j        d          5  	 ddd           dS # 1 swxY w Y   dS )a  
    Makes python-oracledb be in Thin mode. After this method is called, Thick
    mode cannot be enabled. If python-oracledb is already in Thick mode, then
    calling ``enable_thin_mode()`` will fail. If Thin mode connections have
    already been opened, or a connection pool created in Thin mode, then
    calling ``enable_thin_mode()`` is a no-op.

    Since python-oracledb defaults to Thin mode, almost all applications do not
    need to call this method. However, because it bypasses python-oracledb's
    internal mode-determination heuristic, it may be useful for applications
    with multiple threads that concurrently create :ref:`standalone connections
    <standaloneconnection>` when the application starts.
    T)requested_thin_modeN)r   get_managerr   r   r   enable_thin_moder   4   s     
	 T	:	:	:                   s   %))objc                     t          | d          rt          j        |           S t          | d          rt          j        |           S d}t	          |          )a  
    This method converts a data frame to a
    :ref:`DataFrame <oracledataframeobj>` or
    :ref:`ArrowArray <oraclearrowarrayobj>` instance.

    If ``obj`` supports the Arrow PyCapsule interface ``__arrow_c_stream__``
    method, then ``from_arrow()`` returns the instance as a :ref:`DataFrame
    <oracledataframeobj>`. If ``obj`` does not support that method, but does
    support ``__arrow_c_array__``, then an :ref:`ArrowArray
    <oraclearrowarrayobj>` is returned.
    __arrow_c_stream____arrow_c_array__z>object must implement the PyCapsule stream or array interfaces)hasattrr	   _from_arrowr   
ValueError)r   msgs     r   
from_arrowr    F   s]     s()) +$S)))	)	*	* +%c***
JC
S//r   lib_dir
config_dir	error_urldriver_namec                 4    t          j        | |||           dS )aG  
    Enables python-oracledb Thick mode by initializing the Oracle Client
    library, see :ref:`enablingthick`. If a standalone connection or pool has
    already been created in Thin mode, ``init_oracle_client()`` will raise an
    exception and python-oracledb will remain in Thin mode.

    If a standalone connection or pool has *not* already been created in Thin
    mode, but ``init_oracle_client()`` raises an exception, python-oracledb
    will remain in Thin mode but further calls to ``init_oracle_client()`` can
    be made, if desired.

    The ``init_oracle_client()`` method can be called multiple times in each
    Python process as long as the arguments are the same each time.

    The ``lib_dir`` parameter is a string or a bytes object that specifies the
    directory containing Oracle Client libraries.  If the ``lib_dir`` parameter
    is set, then the specified directory is the only one searched for the
    Oracle Client libraries; otherwise, the operating system library search
    path is used to locate the Oracle Client library.  If you are using Python
    3.11 and later, then the value specified in this parameter is encoded
    using `locale.getencoding() <https://docs.python.org/3/library/locale.html
    #locale.getencoding>`__.  For all other Python versions, the encoding
    "utf-8" is used.  If a bytes object is specified in this parameter, then
    this value will be used as is without any encoding.

    The ``config_dir`` parameter is a string or a bytes object that specifies
    the directory in which the
    :ref:`Optional Oracle Net Configuration <optnetfiles>` and
    :ref:`Optional Oracle Client Configuration <optclientfiles>` files reside.
    If the ``config_dir`` parameter is set, then the specified directory is
    used to find Oracle Client library configuration files.  This is
    equivalent to setting the environment variable ``TNS_ADMIN`` and overrides
    any value already set in ``TNS_ADMIN``.  If this parameter is not set, the
    :ref:`Oracle standard <usingconfigfiles>` way of locating Oracle Client
    library configuration files is used.  If you are using Python 3.11 and
    later, then the value specified in this parameter is encoded using
    `locale.getencoding() <https://docs.python.org/3/library/locale.html#
    locale.getencoding>`__.  For all other Python versions, the encoding
    "utf-8" is used.  If a bytes object is specified in this parameter, then
    this value will be used as is without any encoding.

    The ``error_url`` parameter is a string that specifies the URL which is
    included in the python-oracledb exception message if the Oracle Client
    libraries cannot be loaded.  If the ``error_url`` parameter is set, then
    the specified value is included in the message of the exception raised
    when the Oracle Client library cannot be loaded; otherwise, the
    :ref:`installation` URL is included.  This parameter lets your application
    display custom installation instructions.

    The ``driver_name`` parameter is a string that specifies the driver name
    value. If the ``driver_name`` parameter is set, then the specified value
    can be found in database views that give information about connections.
    For example, it is in the CLIENT_DRIVER column of the
    V$SESSION_CONNECT_INFO view. From Oracle Database 12.2, the name displayed
    can be 30 characters.  The standard is to set this value to ``"<name> :
    version>"``, where <name> is the name of the driver and <version> is its
    version. There should be a single space character before and after the
    colon. If this parameter is not set, then the value specified in
    :attr:`oracledb.defaults.driver_name <defaults.driver_name>` is used. If
    the value of this attribute is *None*, then the default value in
    python-oracledb Thick mode is like "python-oracledb thk : <version>". See
    :ref:`otherinit`.

    At successful completion of a call to ``oracledb.init_oracle_client()``,
    the attribute :attr:`oracledb.defaults.config_dir <Defaults.config_dir>`
    will be set as determined below (first one wins):

    - the value of the ``oracledb.init_oracle_client()`` parameter
      ``config_dir``, if one was passed.

    - the value of :attr:`oracledb.defaults.config_dir <Defaults.config_dir>`
      if it has one. i.e.
      :attr:`oracledb.defaults.config_dir <Defaults.config_dir>` remains
      unchanged after ``oracledb.init_oracle_client()`` completes.

    - the value of the environment variable ``$TNS_ADMIN``, if it is set.

    - the value of ``$ORACLE_HOME/network/admin`` if the environment variable
      ``$ORACLE_HOME`` is set.

    - the directory of the loaded Oracle Client library, appended with
      ``network/admin``. Note this directory is not determinable on AIX.

    - otherwise the value *None* is used. (Leaving
      :attr:`oracledb.defaults.config_dir <Defaults.config_dir>` unchanged).
    N)r   init_oracle_client)r!   r"   r#   r$   s       r   r&   r&   Z   s"    x !':y+NNNNNr   valuec                 @   | t          j                    j        } nOt          | t                    r|                     d          } n$t          | t                    st          d          t          |           dk    r t          dt          |            d          | S )aZ  
    Normalize and validate the transaction_id.

    - If `value` is a string, it's UTF-8 encoded.
    - If `value` is None, a UUID4-based transaction_id is generated.
    - If `value` is not str/bytes/None, raises TypeError.
    - If transaction_id exceeds 64 bytes, raises ValueError.

    Returns:
        bytes: Normalized transaction_id
    Nzutf-8z3invalid transaction_id: must be str, bytes, or None@   z*transaction_id size exceeds 64 bytes (got ))	uuiduuid4bytes
isinstancestrencode	TypeErrorlenr   )r'   s    r   $normalize_sessionless_transaction_idr3      s     }
"	E3		 OW%%u%% OMNNN
5zzBFUFFF
 
 	
 Lr   c                 F     t          j                    fd            }|S )a[  
    Decorator function which is used on the ConnectParams and PoolParams
    classes. It creates the implementation object using the implementation
    class stored on the parameter class. It first, however, calls the original
    method to ensure that the keyword parameters supplied are valid (the
    original method itself does nothing).
    c                      | g|R i | |                                  | _        |r| j                            |           d S d S N)_impl_class_implsetselfargskwargsfs      r   	wrapped_fz params_initer.<locals>.wrapped_f   sb    	$       %%''
 	#JNN6"""""	# 	#r   	functoolswrapsr>   r?   s   ` r   params_initerrD      s;     _Q# # # # # r   c                 F     t          j                    fd            }|S )a^  
    Decorator function which is used on the ConnectParams and PoolParams
    classes. It calls the set() method on the parameter implementation object
    with the supplied keyword arguments. It first, however, calls the original
    method to ensure that the keyword parameters supplied are valid (the
    original method itself does nothing).
    c                 T     | g|R i | | j                             |           d S r6   )r8   r9   r:   s      r   r?   z params_setter.<locals>.wrapped_f   s=    	$       
vr   r@   rC   s   ` r   params_setterrG      s;     _Q     r   hook_functionc                     | t          |           st          d          t          j                            |            dS )aD  
    Registers a user parameter hook function that will be called internally by
    python-oracledb prior to connection or pool creation. The hook function
    accepts a copy of the parameters that will be used to create the pool or
    standalone connection and may modify them. For example, the cloud native
    authentication plugins modify the "access_token" parameter with a function
    that will acquire the token using information found in the
    "extra_auth_parms" parameter.

    Multiple hooks may be registered. They will be invoked in order of
    registration.
    Nz3hook_function must be a callable and cannot be None)callabler1   r
   REGISTERED_PARAMS_HOOKSappendrH   s    r   register_params_hookrN      sC     H]$;$;MNNN%,,];;;;;r   password_typec                    t          | t                    st          d          |t          |          st          d          |                                 } |!t
          j                            |            dS |t
          j        | <   dS )aG  
    Registers a user password hook function that will be called internally by
    python-oracledb when a password is supplied as a dictionary containing the
    given ``password_type`` as the key "type". The hook function is called for
    passwords specified as the ``password``, ``newpassword`` and
    ``wallet_parameter`` parameters in calls to :meth:`oracledb.connect()`,
    :meth:`oracledb.create_pool()`, :meth:`oracledb.connect_async()`, and
    :meth:`oracledb.create_pool_async()`.

    Your hook function is expected to accept the dictionary supplied by the
    application and return the valid password.

    Calling :meth:`~oracledb.register_password_type()` with the
    ``hook_function`` parameter set to *None* will result in a previously
    registered user function being removed and the default behavior restored.
    zpassword_type must be a stringN hook_function must be a callable)r.   r/   r1   rJ   lowerr
   REGISTERED_PASSWORD_TYPESpop)rO   rH   s     r   register_password_typerU     s    & mS)) :8999 -)@)@ :;;;!''))M+//>>>>>=J	+M:::r   protocolc                    t          | t                    st          d          |t          |          st          d          |                                 } |!t
          j                            |            dS |t
          j        | <   dS )a  
    Registers a user protocol hook function that will be called internally by
    python-oracledb Thin mode prior to connection or pool creation.  The hook
    function will be invoked when :func:`oracledb.connect`,
    :func:`oracledb.create_pool`, :meth:`oracledb.connect_async()`, or
    :meth:`oracledb.create_pool_async()` are called with a ``dsn`` parameter
    value prefixed with the specified protocol. The user function will also be
    invoked when :meth:`ConnectParams.parse_connect_string()` is called in Thin
    or Thick modes with a similar ``connect_string`` parameter value.

    Your hook function is expected to construct valid connection details. For
    example, if a hook function is registered for the "ldaps" protocol, then
    calling :func:`oracledb.connect` with a connection string prefixed with
    "ldaps://" will invoke the function.  The function can then perform LDAP
    lookup to retrieve and set the actual database information that will be
    used internally by python-oracledb to complete the connection creation.

    The ``protocol`` parameter is a string that will be matched against the
    prefix appearing before "://" in connection strings.

    The ``hook_function`` parameter should be a function with the signature::

        hook_function(protocol, protocol_arg, params)

    The hook function will be called with the following arguments:

    - The ``protocol`` parameter is the value that was registered.

    - The ``protocol_arg`` parameter is the section after "://" in the
      connection string used in the connection or pool creation call, or passed
      to :meth:`~ConnectParams.parse_connect_string()`.

    - The ``params`` parameter is an instance of :ref:`ConnectParams
      <connparam>`.

      When your hook function is invoked internally prior to connection or pool
      creation, ``params`` will be the ConnectParams instance originally passed
      to the :func:`oracledb.connect`, :func:`oracledb.create_pool`,
      :meth:`oracledb.connect_async()`, or :meth:`oracledb.create_pool_async()`
      call, if such an instance was passed.  Otherwise it will be a new
      ConnectParams instance.  The hook function should parse ``protocol`` and
      ``protocol_arg`` and take any desired action to update ``params``
      :ref:`attributes <connparamsattr>` with appropriate connection
      parameters. Attributes can be set using :meth:`ConnectParams.set()` or
      :meth:`ConnectParams.parse_connect_string()`. The ConnectParams instance
      will then be used to complete the connection or pool creation.

      When your hook function is invoked by
      :meth:`ConnectParams.parse_connect_string()`, then ``params`` will be the
      invoking ConnectParams instance that you can update using
      :meth:`ConnectParams.set()` or
      :meth:`ConnectParams.parse_connect_string()`.

    Internal hook functions for the "tcp" and "tcps" protocols are
    pre-registered but can be overridden if needed. If any other protocol has
    not been registered, then connecting will result in the error ``DPY-4021:
    invalid protocol``.

    Calling :meth:`~oracledb.register_protocol()` with the ``hook_function``
    parameter set to *None* will result in a previously registered user
    function being removed and the default behavior restored.
    zprotocol must be a stringNrQ   )r.   r/   r1   rJ   rR   r
   REGISTERED_PROTOCOLSrT   )rV   rH   s     r   register_protocolrY   *  s    ~ h$$ 53444 -)@)@ :;;;~~H&**8444443@	&x000r   c                 D    t           j                            |            dS )z
    Unregisters a user parameter function that was earlier registered with a
    call to :meth:`oracledb.register_params_hook()`.
    N)r
   rK   removerM   s    r   unregister_params_hookr\   t  s!    
 %,,];;;;;r   
parameterskeyword_parametersc                     | :t          | t          t          f          st          j        t          j                   |5t          |t                    s"t          j        t          j                   dS dS dS )ze
    Verifies that the arguments to a call to a stored procedure or function
    are acceptable.
    N)r.   listtupler   
_raise_errERR_ARGS_MUST_BE_LIST_OR_TUPLEdictERR_KEYWORD_ARGS_MUST_BE_DICT)r]   r^   s     r   verify_stored_proc_argsrf   |  su     jdE]&K&K&?@@@%jD/ /% 	&>????? &%%%r   )NNNNr6   )!rA   typingr   r   r   r   r+   arrow_arrayr   	dataframer	    r
   r   r   r   ra   r   r   r    r/   r-   r&   r3   rD   rG   rN   rU   rY   r\   r`   rd   rf   r   r   r   <module>rk      s  >     1 1 1 1 1 1 1 1 1 1 1 1  # # # # # #                                    &u & & & &  $C E)Z"78    * ,0.2#!%	\O \OeCJ'(\OsEz*+\O }\O #	\O \O \O \O@ *. E%*%&
   :  &  "< <T < < < <$KK'/K	K K K K<GA GAH GA GA GA GA GAT<( <t < < < <@dEk"@8<@	@ @ @ @ @ @r   