o
    ðT·j  ã                   @   s†   d Z ddlZddlZddlZddlT ddlmZ e ej	e
¡ e eje
¡ e eje
¡ ejZG dd„ deƒZG dd„ deeƒZdS )	a&  
Peewee integration with sqlcipher3.

Example usage:

    from playground.sqlcipher_ext import SqlCipherDatabase
    db = SqlCipherDatabase('/path/to/my.db', passphrase="don'tuseme4real")

Invalid or incorrect passphrases do not get a special exception, unfortunately,
so to catch these in application code you can do something like this:

    try:
        db.get_tables()  # Attempt to read from db.
    except DatabaseError as exc:
        if 'not a database' in exc.args[0]:
            print('Invalid passphrase')
        else:
            raise
é    N)Ú*)Údbapi2c                   @   s(   e Zd ZeZdd„ Zdd„ Zdd„ ZdS )Ú_SqlCipherDatabasec                 C   sj   t | jƒ}| dd¡ dd¡}tj| jfdd i|¤Ž}z|r%| d| ¡ |  |¡ W |S    | 	¡  ‚ )NÚ
passphraseÚ ú'ú''Úisolation_levelzPRAGMA key='%s')
ÚdictÚconnect_paramsÚpopÚreplaceÚ	sqlcipherÚconnectÚdatabaseÚexecuteÚ_add_conn_hooksÚclose)ÚselfÚparamsr   Úconn© r   úZ/home/dinkstrade/pdmp-scanner/venv/lib/python3.10/site-packages/playhouse/sqlcipher_ext.pyÚ_connect$   s   
ýz_SqlCipherDatabase._connectc                 C   s   |   ¡ stdƒ‚|| jd< d S )NzmCannot set passphrase when database is open. To change passphrase of an open database use the rekey() method.r   )Ú	is_closedÚImproperlyConfiguredr   ©r   r   r   r   r   Úset_passphrase2   s   z!_SqlCipherDatabase.set_passphrasec                 C   s4   |   ¡ r|  ¡  |  d| dd¡ ¡ || jd< dS )NzPRAGMA rekey='%s'r   r   r   T)r   r   Úexecute_sqlr   r   r   r   r   r   Úrekey:   s
   
z_SqlCipherDatabase.rekeyN)Ú__name__Ú
__module__Ú__qualname__Ú__sqlcipher_version__Úserver_versionr   r   r   r   r   r   r   r   !   s
    r   c                   @   s   e Zd ZdS )ÚSqlCipherDatabaseN)r    r!   r"   r   r   r   r   r%   C   s    r%   )Ú__doc__ÚdatetimeÚdecimalÚsysÚpeeweeÚ
sqlcipher3r   r   Úregister_adapterÚDecimalÚstrÚdateÚtimeÚsqlite_version_infor#   Úobjectr   ÚSqliteDatabaser%   r   r   r   r   Ú<module>   s    "