
    ,h.                        S SK r SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SS	KJ	r	  S
SK
Jr  S
SKJr  Sr " S S\R"                  \R$                  \R&                  5      r " S S\R*                  5      r " S S\R*                  5      r " S S\R*                  5      r " S S\R*                  5      r " S S\R*                  5      r " S S\R*                  5      r " S S\R*                  5      r " S S\R*                  5      r\ R<                  " S \ R>                  5      r \ R<                  " S!\ R>                  5      r!S" r"S# r#S$ r$g)%    N   )ARRAY)CONTAINED_BY)CONTAINS)GETITEM)HAS_ALL)HAS_ANY)HAS_KEY   )types)	functions)HSTOREhstorec                       \ rS rSrSrS rSr\R                  " 5       r	SS jr
 " S S\R                  R                  \R                  R                  5      r\rS rS	 rS
rg)r      as  Represent 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`.

.. container:: topic

    **Detecting Changes in HSTORE columns when using the ORM**

    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                     Ub  Xl         gg)zConstruct a new :class:`.HSTORE`.

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

N	text_type)selfr   s     ]/var/www/auris/envauris/lib/python3.13/site-packages/sqlalchemy/dialects/postgresql/hstore.py__init__HSTORE.__init__l   s      &N !    c                   f    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rSrg)HSTORE.Comparatorv   z2Define comparison operations for :class:`.HSTORE`.c                 H    U R                  [        U[        R                  S9$ )z^Boolean expression.  Test for presence of a key.  Note that the
key may be a SQLA expression.
result_type)operater
   sqltypesBooleanr   others     r   has_keyHSTORE.Comparator.has_key{   s     <<H<L<L<MMr   c                 H    U R                  [        U[        R                  S9$ )z;Boolean expression.  Test for presence of all keys in jsonbr   )r    r   r!   r"   r#   s     r   has_allHSTORE.Comparator.has_all       <<H<L<L<MMr   c                 H    U R                  [        U[        R                  S9$ )z:Boolean expression.  Test for presence of any key in jsonbr   )r    r	   r!   r"   r#   s     r   has_anyHSTORE.Comparator.has_any   r*   r   c                 H    U R                  [        U[        R                  S9$ )zBoolean expression.  Test if keys (or array) are a superset
of/contained the keys of the argument jsonb expression.

kwargs may be ignored by this operator but are required for API
conformance.
r   )r    r   r!   r"   )r   r$   kwargss      r   containsHSTORE.Comparator.contains   s     <<%X=M=M<NNr   c                 H    U R                  [        U[        R                  S9$ )zdBoolean expression.  Test if keys are a proper subset of the
keys of the argument jsonb expression.
r   )r    r   r!   r"   r#   s     r   contained_byHSTORE.Comparator.contained_by   s'     <<e1A1A    r   c                 :    [         XR                  R                  4$ N)r   typer   )r   indexs     r   _setup_getitem HSTORE.Comparator._setup_getitem   s    E99#6#666r   c                 .    [        U R                  U5      $ )zuBoolean 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   definedHSTORE.Comparator.defined   s     *$))S99r   c                 n    [        U[        5      (       a  [        U5      n[        U R                  U5      $ )zHStore 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_HStoreDeleteFunctionr=   r>   s     r   deleteHSTORE.Comparator.delete   s,     #t$$',(C88r   c                 .    [        U R                  U5      $ )zLHStore expression.  Returns a subset of an hstore defined by
array of keys.
)_HStoreSliceFunctionr=   )r   arrays     r   sliceHSTORE.Comparator.slice   s     (		599r   c                 ,    [        U R                  5      $ )z.Text array expression.  Returns array of keys.)_HStoreKeysFunctionr=   r   s    r   keysHSTORE.Comparator.keys       &tyy11r   c                 ,    [        U R                  5      $ )z0Text array expression.  Returns array of values.)_HStoreValsFunctionr=   rP   s    r   valsHSTORE.Comparator.vals   rS   r   c                 ,    [        U R                  5      $ )zFText array expression.  Returns array of alternating keys and
values.
)_HStoreArrayFunctionr=   rP   s    r   rK   HSTORE.Comparator.array   s     (		22r   c                 ,    [        U R                  5      $ )z<Text array expression.  Returns array of [key, value] pairs.)_HStoreMatrixFunctionr=   rP   s    r   matrixHSTORE.Comparator.matrix   s    (33r    N)__name__
__module____qualname____firstlineno____doc__r%   r(   r,   r0   r3   r9   r@   rG   rL   rQ   rV   rK   r]   __static_attributes__r_   r   r   
Comparatorr   v   sM     	A	N	N	N	O		7	:	9	:	2	2	3	4r   rf   c                     S nU$ )Nc                 F    [        U [        5      (       a  [        U 5      $ U $ r6   )rC   rD   rE   values    r   process&HSTORE.bind_processor.<locals>.process   s    %&&(//r   r_   )r   dialectrk   s      r   bind_processorHSTORE.bind_processor       	 r   c                     S nU$ )Nc                 "    U b  [        U 5      $ U $ r6   )_parse_hstoreri   s    r   rk   (HSTORE.result_processor.<locals>.process   s     $U++r   r_   )r   rm   coltyperk   s       r   result_processorHSTORE.result_processor   rp   r   r   r6   )r`   ra   rb   rc   rd   __visit_name__hashabler!   Textr   r   	Indexablerf   Concatenablecomparator_factoryrn   rv   re   r_   r   r   r   r      sa    KZ NHI'K4%%x'<'<'G'GK4Z $

r   r   c                   $    \ rS rSrSr\rS rSrSr	g)r      a  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.

Tr_   N)
r`   ra   rb   rc   rd   r   r7   nameinherit_cachere   r_   r   r   r   r      s    2 DDMr   r   c                   4    \ rS rSr\R
                  rSrSrSr	g)r<      r@   Tr_   N)
r`   ra   rb   rc   r!   r"   r7   r   r   re   r_   r   r   r<   r<      s    DDMr   r<   c                        \ rS rSr\rSrSrSrg)rF   i  rG   Tr_   N	r`   ra   rb   rc   r   r7   r   r   re   r_   r   r   rF   rF     s    DDMr   rF   c                        \ rS rSr\rSrSrSrg)rJ   i	  rL   Tr_   Nr   r_   r   r   rJ   rJ   	  s    DDMr   rJ   c                   @    \ rS rSr\" \R                  5      rSrSr	Sr
g)rO   i  akeysTr_   Nr`   ra   rb   rc   r   r!   rz   r7   r   r   re   r_   r   r   rO   rO         DDMr   rO   c                   @    \ rS rSr\" \R                  5      rSrSr	Sr
g)rU   i  avalsTr_   Nr   r_   r   r   rU   rU     r   r   rU   c                   @    \ rS rSr\" \R                  5      rSrSr	Sr
g)rY   i  hstore_to_arrayTr_   Nr   r_   r   r   rY   rY     s    DDMr   rY   c                   @    \ rS rSr\" \R                  5      rSrSr	Sr
g)r\   i!  hstore_to_matrixTr_   Nr   r_   r   r   r\   r\   !  s    DDMr   r\   z
(
  "(?P<key> (\\ . | [^"])* )"       # Quoted key
)
[ ]* => [ ]*    # Pair operator, optional adjoining whitespace
(
    (?P<value_null> NULL )          # NULL value
  | "(?P<value> (\\ . | [^"])* )"   # Quoted value
)
z
[ ]* , [ ]*
c                     Sn[        U 5      nU [        X-
  S-
  S5      [        X5       nU [        X5      [        X-   S-   U5       n[        U5      U:  a  SUSS -   n[        U5      U:  a  USS S-   nSUUU4-  $ )zformat an unmarshalling error.   r   r   z[...]Nz5After %r, could not parse residual at position %d: %r)lenmaxmin)
hstore_strposctxhslenparsed_tailresiduals         r   _parse_errorr   E  s     C
OESQ2S_EK#c/C	Au,EFH
;#AB/
8}sCR=7*BF  r   c                 6   0 nSn[         R                  U 5      nUb  UR                  S5      R                  SS5      R                  SS5      nUR                  S5      (       a  SnO1UR                  S	5      R                  SS5      R                  SS5      nXQU'   X#R	                  5       -  n[
        R                  XS 5      nUb  X&R	                  5       -  n[         R                  XS 5      nUb  M  U[        U 5      :w  a  [        [        X5      5      eU$ )
ai  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.



r   Nr?   \""\\\
value_nullrj   )	HSTORE_PAIR_REmatchgroupreplaceendHSTORE_DELIMITER_REr   
ValueErrorr   )r   resultr   
pair_matchr?   rj   delim_matchs          r   rs   rs   Z  s    F
C%%j1J

 u%--eS9AA&$OL))E   )$& 
 s~~)//
40@A"??$$C#))*T*:;
% 
 ( c*oj677Mr   c                 \   ^ S mSR                  U4S jU R                  5        5       5      $ )zpSerialize a dictionary into an hstore literal.  Keys and values must
both be strings (except None for values).

c                     US:X  a  U c  g[        U [        5      (       a%  SU R                  SS5      R                  SS5      -  $ [        U < SU< S	35      e)
Nrj   NULLz"%s"r   r   r   r   z in z position is not a string.)rC   strr   r   )spositions     r   esc_serialize_hstore.<locals>.esc  sV    w193AIIdF3;;CGGG898D r   z, c              3   V   >#    U  H  u  pT" US 5      < ST" US5      < 3v   M      g7f)r?   z=>rj   Nr_   ).0kvr   s      r   	<genexpr>$_serialize_hstore.<locals>.<genexpr>  s'      @KC5M3q'?3s   &))joinitems)valr   s    @r   rE   rE     s.     99 @C		  r   )%rerK   r   	operatorsr   r   r   r   r	   r
    r   r!   sqlr   sqlfunc__all__r{   r|   
TypeEnginer   GenericFunctionr   r<   rF   rJ   rO   rU   rY   r\   compileVERBOSEr   r   r   rs   rE   r_   r   r   <module>r      s.   
  #      ! ' AX!6!68K8K AHW$$ >W44 G33 722 '11 '11 722 G33  	 JJ jj JJ	 *'Tr   