§
    BP„j~  ã                   ó€   — d Z ddlmZ ddlZddlmZ  G d„ dej        j        ¦  «        Z	 G d„ dej
        ¦  «        Z
dS )	a¥  OAuth 2.0 utilities for SQLAlchemy.

Utilities for using OAuth 2.0 in conjunction with a SQLAlchemy.

Configuration
=============

In order to use this storage, you'll need to create table
with :class:`oauth2client.contrib.sqlalchemy.CredentialsType` column.
It's recommended to either put this column on some sort of user info
table or put the column in a table with a belongs-to relationship to
a user info table.

Here's an example of a simple table with a :class:`CredentialsType`
column that's related to a user table by the `user_id` key.

.. code-block:: python

    from sqlalchemy import Column, ForeignKey, Integer
    from sqlalchemy.ext.declarative import declarative_base
    from sqlalchemy.orm import relationship

    from oauth2client.contrib.sqlalchemy import CredentialsType


    Base = declarative_base()


    class Credentials(Base):
        __tablename__ = 'credentials'

        user_id = Column(Integer, ForeignKey('user.id'))
        credentials = Column(CredentialsType)


    class User(Base):
        id = Column(Integer, primary_key=True)
        # bunch of other columns
        credentials = relationship('Credentials')


Usage
=====

With tables ready, you are now able to store credentials in database.
We will reuse tables defined above.

.. code-block:: python

    from sqlalchemy.orm import Session

    from oauth2client.client import OAuth2Credentials
    from oauth2client.contrib.sql_alchemy import Storage

    session = Session()
    user = session.query(User).first()
    storage = Storage(
        session=session,
        model_class=Credentials,
        # This is the key column used to identify
        # the row that stores the credentials.
        key_name='user_id',
        key_value=user.id,
        property_name='credentials',
    )

    # Store
    credentials = OAuth2Credentials(...)
    storage.put(credentials)

    # Retrieve
    credentials = storage.get()

    # Delete
    storage.delete()

é    )Úabsolute_importN)Úclientc                   ó   — e Zd ZdZdS )ÚCredentialsTypezXType representing credentials.

    Alias for :class:`sqlalchemy.types.PickleType`.
    N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__© ó    úd/root/disk_3tb/conda_envs/Huy-visual/lib/python3.11/site-packages/oauth2client/contrib/sqlalchemy.pyr   r   d   s   € € € € € ðð ð ð r   r   c                   ó4   ‡ — e Zd ZdZˆ fd„Zd„ Zd„ Zd„ Zˆ xZS )ÚStoragez²Store and retrieve a single credential to and from SQLAlchemy.
    This helper presumes the Credentials
    have been stored as a Credentials column
    on a db model class.
    c                 óœ   •— t          t          | ¦  «                             ¦   «          || _        || _        || _        || _        || _        dS )a?  Constructor for Storage.

        Args:
            session: An instance of :class:`sqlalchemy.orm.Session`.
            model_class: SQLAlchemy declarative mapping.
            key_name: string, key name for the entity that has the credentials
            key_value: key value for the entity that has the credentials
            property_name: A string indicating which property on the
                           ``model_class`` to store the credentials.
                           This property must be a
                           :class:`CredentialsType` column.
        N)Úsuperr   Ú__init__ÚsessionÚmodel_classÚkey_nameÚ	key_valueÚproperty_name)Úselfr   r   r   r   r   Ú	__class__s         €r   r   zStorage.__init__r   sL   ø€ õ 	�g�tÑÔ×%Ò%Ñ'Ô'Ð'àˆŒØ&ˆÔØ ˆŒØ"ˆŒØ*ˆÔÐÐr   c                 ó  — | j         | j        i} | j                             | j        ¦  «        j        di |¤Ž}|                     ¦   «         }|r>t          || j        ¦  «        }|r%t          |d¦  «        r| 
                    | ¦  «         |S dS )zzRetrieve stored credential.

        Returns:
            A :class:`oauth2client.Credentials` instance or `None`.
        Ú	set_storeNr   )r   r   r   Úqueryr   Ú	filter_byÚfirstÚgetattrr   Úhasattrr   )r   Úfiltersr   ÚentityÚ
credentials        r   Ú
locked_getzStorage.locked_getˆ   sœ   € ð ”= $¤.Ð1ˆØ>�”×"Ò" 4Ô#3Ñ4Ô4Ô>ÐIÐIÀÐIÐIˆØ—’‘”ˆàð 	Ý  ¨Ô);Ñ<Ô<ˆJØð +�g j°+Ñ>Ô>ð +Ø×$Ò$ TÑ*Ô*Ð*ØÐà�4r   c                 ó  — | j         | j        i} | j                             | j        ¦  «        j        di |¤Ž}|                     ¦   «         }|s | j        di |¤Ž}t          || j        |¦  «         | j         	                    |¦  «         dS )zƒWrite a credentials to the SQLAlchemy datastore.

        Args:
            credentials: :class:`oauth2client.Credentials`
        Nr   )
r   r   r   r   r   r   r   Úsetattrr   Úadd)r   Úcredentialsr!   r   r"   s        r   Ú
locked_putzStorage.locked_putš   s›   € ð ”= $¤.Ð1ˆØ>�”×"Ò" 4Ô#3Ñ4Ô4Ô>ÐIÐIÀÐIÐIˆØ—’‘”ˆàð 	1Ø%�TÔ%Ð0Ð0¨Ð0Ð0ˆFå�˜Ô*¨KÑ8Ô8Ð8ØŒ×Ò˜Ñ Ô Ð Ð Ð r   c                 óš   — | j         | j        i} | j                             | j        ¦  «        j        di |¤Ž                     ¦   «          dS )z1Delete credentials from the SQLAlchemy datastore.Nr   )r   r   r   r   r   r   Údelete)r   r!   s     r   Úlocked_deletezStorage.locked_deleteª   sN   € à”= $¤.Ð1ˆØ6ˆŒ×Ò˜4Ô+Ñ,Ô,Ô6ÐAÐA¸ÐAÐA×HÒHÑJÔJÐJÐJÐJr   )	r   r   r	   r
   r   r$   r)   r,   Ú__classcell__)r   s   @r   r   r   k   sv   ø€ € € € € ðð ð+ð +ð +ð +ð +ð,ð ð ð$!ð !ð !ð Kð Kð Kð Kð Kð Kð Kr   r   )r
   Ú
__future__r   Úsqlalchemy.typesÚ
sqlalchemyÚoauth2clientr   ÚtypesÚ
PickleTyper   r   r   r   r   ú<module>r4      s¾   ððLð Lð\ 'Ð &Ð &Ð &Ð &Ð &à Ð Ð Ð à Ð Ð Ð Ð Ð ðð ð ð ð �jÔ&Ô1ñ ô ð ðBKð BKð BKð BKð BKˆfŒnñ BKô BKð BKð BKð BKr   