Hacked By AnonymousFox

Current Path : /opt/cloudlinux/venv/lib64/python3.11/site-packages/sqlalchemy/dialects/postgresql/__pycache__/
Upload File :
Current File : //opt/cloudlinux/venv/lib64/python3.11/site-packages/sqlalchemy/dialects/postgresql/__pycache__/hstore.cpython-311.pyc

�

�܋f�0��:�ddlZddlmZddlmZddlmZddlmZ	ddlm
Z
d	Ze
je
j
Ze
jd
edd���Ze
jd
edd���Ze
jdedd���Ze
jdedd���Ze
jdedd���Ze
jdedd���ZGd�dejejej��ZGd�de	j��ZGd�de	j��ZGd�de	j��ZGd�de	j��ZGd�de	j��ZGd�de	j��Z Gd �d!e	j��Z!Gd"�d#e	j��Z"ej#d$ej$��Z%ej#d%ej$��Z&d&�Z'd'�Z(d(�Z)dS))�N�)�ARRAY�)�types)�util)�	functions)�	operators)�HSTORE�hstorez->T)�
precedence�natural_self_precedent�eager_grouping�?z?&z?|z@>z<@c��eZdZdZdZdZej��Zd	d�Z	Gd�dej
jejj��ZeZ
d�Zd�ZdS)
r
atRepresent the PostgreSQL HSTORE type.

    The :class:`.HSTORE` type stores dictionaries containing strings, e.g.::

        data_table = Table('data_table', metadata,
            Column('id', Integer, primary_key=True),
            Column('data', HSTORE)
        )

        with engine.connect() as conn:
            conn.execute(
                data_table.insert(),
                data = {"key1": "value1", "key2": "value2"}
            )

    :class:`.HSTORE` provides for a wide range of operations, including:

    * Index operations::

        data_table.c.data['some key'] == 'some value'

    * Containment operations::

        data_table.c.data.has_key('some key')

        data_table.c.data.has_all(['one', 'two', 'three'])

    * Concatenation::

        data_table.c.data + {"k1": "v1"}

    For a full list of special methods see
    :class:`.HSTORE.comparator_factory`.

    For usage with the SQLAlchemy ORM, it may be desirable to combine
    the usage of :class:`.HSTORE` with :class:`.MutableDict` dictionary
    now part of the :mod:`sqlalchemy.ext.mutable`
    extension.  This extension will allow "in-place" changes to the
    dictionary, e.g. addition of new keys or replacement/removal of existing
    keys to/from the current dictionary, to produce events which will be
    detected by the unit of work::

        from sqlalchemy.ext.mutable import MutableDict

        class MyClass(Base):
            __tablename__ = 'data_table'

            id = Column(Integer, primary_key=True)
            data = Column(MutableDict.as_mutable(HSTORE))

        my_object = session.query(MyClass).one()

        # in-place mutation, requires Mutable extension
        # in order for the ORM to detect
        my_object.data['some_key'] = 'some value'

        session.commit()

    When the :mod:`sqlalchemy.ext.mutable` extension is not used, the ORM
    will not be alerted to any changes to the contents of an existing
    dictionary, unless that dictionary value is re-assigned to the
    HSTORE-attribute itself, thus generating a change event.

    .. seealso::

        :class:`.hstore` - render the PostgreSQL ``hstore()`` function.


    FNc��|�	||_dSdS)z�Construct a new :class:`.HSTORE`.

        :param text_type: the type that should be used for indexed values.
         Defaults to :class:`_types.Text`.

         .. versionadded:: 1.1.0

        N)�	text_type)�selfrs  �\/opt/cloudlinux/venv/lib64/python3.11/site-packages/sqlalchemy/dialects/postgresql/hstore.py�__init__zHSTORE.__init__�s��� �&�D�N�N�N�!� �c�`�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�ZdS)�HSTORE.Comparatorz2Define comparison operations for :class:`.HSTORE`.c�P�|�t|tj���S)zvBoolean expression.  Test for presence of a key.  Note that the
            key may be a SQLA expression.
            ��result_type)�operate�HAS_KEY�sqltypes�Boolean�r�others  r�has_keyzHSTORE.Comparator.has_key�s���<�<���H�<L�<�M�M�Mrc�P�|�t|tj���S)z;Boolean expression.  Test for presence of all keys in jsonbr)r�HAS_ALLrrr s  r�has_allzHSTORE.Comparator.has_all�����<�<���H�<L�<�M�M�Mrc�P�|�t|tj���S)z:Boolean expression.  Test for presence of any key in jsonbr)r�HAS_ANYrrr s  r�has_anyzHSTORE.Comparator.has_any�r&rc�P�|�t|tj���S)z�Boolean expression.  Test if keys (or array) are a superset
            of/contained the keys of the argument jsonb expression.
            r)r�CONTAINSrr)rr!�kwargss   r�containszHSTORE.Comparator.contains�s���<�<��%�X�=M�<�N�N�Nrc�P�|�t|tj���S)z|Boolean expression.  Test if keys are a proper subset of the
            keys of the argument jsonb expression.
            r)r�CONTAINED_BYrrr s  r�contained_byzHSTORE.Comparator.contained_by�s)���<�<��e��1A� ���
rc�*�t||jjfS�N)�GETITEM�typer)r�indexs  r�_setup_getitemz HSTORE.Comparator._setup_getitem�s���E�4�9�#6�6�6rc�,�t|j|��S)z�Boolean expression.  Test for presence of a non-NULL value for
            the key.  Note that the key may be a SQLA expression.
            )�_HStoreDefinedFunction�expr�r�keys  r�definedzHSTORE.Comparator.defined�s��*�$�)�S�9�9�9rc�t�t|t��rt|��}t|j|��S)z�HStore expression.  Returns the contents of this hstore with the
            given key deleted.  Note that the key may be a SQLA expression.
            )�
isinstance�dict�_serialize_hstore�_HStoreDeleteFunctionr9r:s  r�deletezHSTORE.Comparator.delete�s5���#�t�$�$�
-�'��,�,��(���C�8�8�8rc�,�t|j|��S)zdHStore expression.  Returns a subset of an hstore defined by
            array of keys.
            )�_HStoreSliceFunctionr9)r�arrays  r�slicezHSTORE.Comparator.slice�s��(��	�5�9�9�9rc�*�t|j��S)z.Text array expression.  Returns array of keys.)�_HStoreKeysFunctionr9�rs r�keyszHSTORE.Comparator.keys����&�t�y�1�1�1rc�*�t|j��S)z0Text array expression.  Returns array of values.)�_HStoreValsFunctionr9rIs r�valszHSTORE.Comparator.vals�rKrc�*�t|j��S)z^Text array expression.  Returns array of alternating keys and
            values.
            )�_HStoreArrayFunctionr9rIs rrEzHSTORE.Comparator.array�s��(��	�2�2�2rc�*�t|j��S)z<Text array expression.  Returns array of [key, value] pairs.)�_HStoreMatrixFunctionr9rIs r�matrixzHSTORE.Comparator.matrix�s��(���3�3�3rN)�__name__�
__module__�__qualname__�__doc__r"r%r)r-r0r6r<rBrFrJrNrErS�rr�
Comparatorr�s�������	A�@�	N�	N�	N�	N�	N�	N�	N�	N�	N�	O�	O�	O�	�	�	�	7�	7�	7�	:�	:�	:�	9�	9�	9�	:�	:�	:�	2�	2�	2�	2�	2�	2�	3�	3�	3�	4�	4�	4�	4�	4rrYc�@��tjr
|j��fd�}nd�}|S)Nc�v��t|t��r"t|������S|Sr2)r>r?r@�encode��value�encodings �r�processz&HSTORE.bind_processor.<locals>.process�s6����e�T�*�*�!�,�U�3�3�:�:�8�D�D�D� �Lrc�N�t|t��rt|��S|Sr2)r>r?r@�r^s rr`z&HSTORE.bind_processor.<locals>.process�s'���e�T�*�*�!�,�U�3�3�3� �Lr�r�py2kr_)r�dialectr`r_s   @r�bind_processorzHSTORE.bind_processor��I����9�	!��'�H�
!�
!�
!�
!�
!�
!�
!�
!�
!��rc�@��tjr
|j��fd�}nd�}|S)Nc�P��|�"t|������S|Sr2)�
_parse_hstore�decoder]s �rr`z(HSTORE.result_processor.<locals>.process�s(����$�(����h�)?�)?�@�@�@� �Lrc�(�|�t|��S|Sr2)rjrbs rr`z(HSTORE.result_processor.<locals>.processs���$�(��/�/�/� �Lrrc)rre�coltyper`r_s    @r�result_processorzHSTORE.result_processor�rgrr2)rTrUrVrW�__visit_name__�hashabler�Textrr�	IndexablerY�Concatenable�comparator_factoryrfrnrXrrr
r
@s�������D�D�L�N��H���
���I�
'�
'�
'�
'�H4�H4�H4�H4�H4���%�x�'<�'G�H4�H4�H4�T$�����(����rr
c��eZdZdZeZdZdS)ra_Construct an hstore value within a SQL expression using the
    PostgreSQL ``hstore()`` function.

    The :class:`.hstore` function accepts one or two arguments as described
    in the PostgreSQL documentation.

    E.g.::

        from sqlalchemy.dialects.postgresql import array, hstore

        select([hstore('key1', 'value1')])

        select([
                hstore(
                    array(['key1', 'key2', 'key3']),
                    array(['value1', 'value2', 'value3'])
                )
            ])

    .. seealso::

        :class:`.HSTORE` - the PostgreSQL ``HSTORE`` datatype.

    N)rTrUrVrWr
r4�namerXrrrrs$��������2�D��D�D�Drrc� �eZdZejZdZdS)r8r<N)rTrUrVrrr4rvrXrrr8r8*s��������D��D�D�Drr8c��eZdZeZdZdS)rArBN�rTrUrVr
r4rvrXrrrArA/s�������D��D�D�DrrAc��eZdZeZdZdS)rDrFNryrXrrrDrD4s�������D��D�D�DrrDc�2�eZdZeej��ZdZdS)rH�akeysN�rTrUrVrrrqr4rvrXrrrHrH9�$�������5�����D��D�D�DrrHc�2�eZdZeej��ZdZdS)rM�avalsNr}rXrrrMrM>r~rrMc�2�eZdZeej��ZdZdS)rP�hstore_to_arrayNr}rXrrrPrPCs$�������5�����D��D�D�DrrPc�2�eZdZeej��ZdZdS)rR�hstore_to_matrixNr}rXrrrRrRHs$�������5�����D��D�D�DrrRz�
(
  "(?P<key> (\\ . | [^"])* )"       # Quoted key
)
[ ]* => [ ]*    # Pair operator, optional adjoining whitespace
(
    (?P<value_null> NULL )          # NULL value
  | "(?P<value> (\\ . | [^"])* )"   # Quoted value
)
z
[ ]* , [ ]*
c�d�d}t|��}|t||z
dz
d��t||���}|t||��t||zdz|���}t|��|kr
d|dd�z}t|��|kr
|dd�dz}d|||fzS)zformat an unmarshalling error.�rrz[...]N���z5After %r, could not parse residual at position %d: %r)�len�max�min)�
hstore_str�pos�ctx�hslen�parsed_tail�residuals      r�_parse_errorr�ks���
�C��
�O�O�E��S��s��Q���2�2�S��e�_�_�D�E�K��#�c�5�/�/�C��c�	�A�
�u�,E�,E�E�F�H�
�;���#�����A�B�B��/��
�8�}�}�s����C�R�C�=�7�*��B����F��rc���i}d}t�|��}|��|�d���dd���dd��}|�d��rd}n=|�d	���dd���dd��}|||<||���z
}t
�||d���}|�||���z
}t�||d���}|��|t
|��krtt||�����|S)
a�Parse an hstore from its literal string representation.

    Attempts to approximate PG's hstore input parsing rules as closely as
    possible. Although currently this is not strictly necessary, since the
    current implementation of hstore's output syntax is stricter than what it
    accepts as input, the documentation makes no guarantees that will always
    be the case.



    rNr;�\"�"�\\�\�
value_nullr^)	�HSTORE_PAIR_RE�match�group�replace�end�HSTORE_DELIMITER_REr��
ValueErrorr�)r��resultr��
pair_matchr;r^�delim_matchs       rrjrj�sV���F�
�C��%�%�j�1�1�J�
�
 ����u�%�%�-�-�e�S�9�9�A�A�&�$�O�O�����L�)�)�	��E�E�� � ��)�)�����$�$�����&�&�
�
��s���z�~�~�����)�/�/�
�3�4�4�0@�A�A���"��;�?�?�$�$�$�C�#�)�)�*�S�T�T�*:�;�;�
�%�
 �(�c�*�o�o�����j�#�6�6�7�7�7��Mrc�p��d��d��fd�|���D����S)zxSerialize a dictionary into an hstore literal.  Keys and values must
    both be strings (except None for values).

    c���|dkr|�dSt|tj��r-d|�dd���dd��zSt	|�d|�d	����)
Nr^�NULLz"%s"r�r�r�r�z in z position is not a string.)r>r�string_typesr�r�)�s�positions  r�escz_serialize_hstore.<locals>.esc�sv���w���1�9��6�
��4�,�
-�
-�	��A�I�I�d�F�3�3�;�;�C��G�G�G�G��89���8�8�8�D���
rz, c3�T�K�|]"\}}�|d���d�|d����V��#dS)r;z=>r^NrX)�.0�k�vr�s   �r�	<genexpr>z$_serialize_hstore.<locals>.<genexpr>�sW�������8<��1�C�C��5�M�M�M�M�3�3�q�'�?�?�?�3������r)�join�items)�valr�s @rr@r@�sX�������9�9�����@C�	�	��������r)*�rerEr�rrr�sqlr�sqlfuncr	�__all__�_PRECEDENCE�json_getitem_op�idx_precedence�	custom_opr3rr$r(r+r/rrrs�
TypeEnginer
�GenericFunctionrr8rArDrHrMrPrR�compile�VERBOSEr�r�r�rjr@rXrr�<module>r�s���
�	�	�	�������!�!�!�!�!�!�������'�'�'�'�'�'����������&�y�'@�A��
�)�
�����	�����)�
�����	�����)�
�����	�����)�
�����	�����9������	����#�y�"�����	����I�I�I�I�I�X�
��!6��8K�I�I�I�X�����W�
$����<�����W�4����
�����G�3����
�����7�2����
�����'�1����
�����'�1����
�����7�2����
�����G�3�������	��J����!�b�j���J�	������*'�'�'�T����r

Hacked By AnonymousFox1.0, Coded By AnonymousFox