ok

Mini Shell

Direktori : /opt/alt/python38/lib64/python3.8/site-packages/playhouse/__pycache__/
Upload File :
Current File : //opt/alt/python38/lib64/python3.8/site-packages/playhouse/__pycache__/sqliteq.cpython-38.pyc

U

S��W[!�@sddlZddlZddlmZddlmZzddlmZWn ek
rXddlmZYnXz0ddlZddlm	Z
ddlmZddl
mZWn ek
r�dZ
ZZYnXddlmZe�d�ZGdd	�d	e�ZGd
d�de�ZdZd
ZGdd�de�ZGdd�de�ZGdd�de�ZdS)�N��Event)�Thread)�Queue)�Greenlet)�SqliteExtDatabasezpeewee.sqliteqc@seZdZdS)�
ResultTimeoutN)�__name__�
__module__�__qualname__�rr�/sqliteq.pyrsrc@s|eZdZdZdd�Zddd�Zddd�Zd	d
�Zdd�ZeZ	e
d
d��Ze
dd��Ze
dd��Z
dd�Zdd�Zdd�ZdS)�AsyncCursor)	�sql�params�commit�timeout�_event�_cursor�_exc�_idx�_rowscCs:||_||_||_||_||_d|_|_|_|_dS�N)	rrrrrrrrr)�self�eventrrrrrrr
�__init__ szAsyncCursor.__init__NcCs6||_||_d|_|dkr"|��ng|_|j��|S)Nr)rrr�fetchallrr�set)r�cursor�excrrr
�
set_result(s
zAsyncCursor.set_resultcCs@|dk	r|n|j}|jj|d�s,|r,td��|jdk	r<|j�dS)N)rzresults not ready, timed out.)rr�waitrr)rrrrr
�_wait0s

zAsyncCursor._waitcCs|��|jdk	r|j�|Sr)r"r�_exec�rrrr
�__iter__7s
zAsyncCursor.__iter__cCs@z|j|j}Wntk
r(t�YnX|jd7_|SdS)N�)rr�
IndexError�
StopIteration)r�objrrr
�next=s
zAsyncCursor.nextcCs|��|jjSr)r"r�	lastrowidr$rrr
r+GszAsyncCursor.lastrowidcCs|��|jjSr)r"r�rowcountr$rrr
r,LszAsyncCursor.rowcountcCs|jjSr)r�descriptionr$rrr
r-QszAsyncCursor.descriptioncCs|j��dSr)r�closer$rrr
r.UszAsyncCursor.closecCst|�Sr)�listr$rrr
rXszAsyncCursor.fetchallcCs.|��z
t|�WStk
r(YdSXdSr)r"r*r(r$rrr
�fetchone[s

zAsyncCursor.fetchone)N)N)r	r
r�	__slots__rr r"r%r*�__next__�propertyr+r,r-r.rr0rrrr
rs 




rz�threadlocals cannot be set to True when using the Sqlite thread / queue database. All queries are serialized through a single connection, so allowing multiple threads to connect defeats the purpose of this database.z�SQLite must be configured to use the WAL journal mode when using this feature. WAL mode allows one or more readers to continue reading while another connection writes to the database.csreZdZd�fdd�	Zdd�Zddd	�Zd
d�Zdd
�Zdd�Zdd�Z	ddd�Z
dd�Zdd�Zdd�Z
�ZS)�SqliteQueueDatabaseFr&Ncs�|�d�rtt��d|d<d|d<|�|�dd�|�dd��}	tt|�}
|
j|_|
j	|f|�d|	i|��||_
||_||_d|_
|�|�|�|_|��|j
r�|��dS)NZthreadlocalsFZcheck_same_thread�journal_mode�pragmasT)�get�
ValueError�THREADLOCAL_ERROR_MESSAGE�_validate_journal_mode�pop�superr4�execute_sql�!_SqliteQueueDatabase__execute_sqlrZ
_autostart�_results_timeout�_num_readers�_is_stopped�get_thread_impl�_thread_helper�_create_queues_and_workers�start)rZdatabase�
use_geventZ	autostartZreaders�queue_max_sizeZresults_timeout�args�kwargsr6ZParent��	__class__rr
ros&


�
zSqliteQueueDatabase.__init__cCs|rtStSr)�GreenletHelper�ThreadHelper)rrFrrr
rB�sz#SqliteQueueDatabase.get_thread_implcCsh|r|��dkrtt��|r^tdd�|D��}|�dd���dkrJtt��dd�|D�dgSdgSdS)N�walcss|]\}}|��|fVqdSr)�lower��.0�k�vrrr
�	<genexpr>�sz=SqliteQueueDatabase._validate_journal_mode.<locals>.<genexpr>r5cSs g|]\}}|dkr||f�qS)r5rrPrrr
�
<listcomp>�s�z>SqliteQueueDatabase._validate_journal_mode.<locals>.<listcomp>)r5rN)rOr8�WAL_MODE_ERROR_MESSAGE�dictr7)rr5r6Zpdictrrr
r:�s�z*SqliteQueueDatabase._validate_journal_modecsP�j���_�j���_�j��j���j��_��fdd�t�j�D��_	dS)Ncsg|]}�j���j��qSr)rC�thread�_read_queue)rQ�_�r�targetrr
rU�s�zBSqliteQueueDatabase._create_queues_and_workers.<locals>.<listcomp>)
rC�queue�_write_queuerY�_run_worker_looprX�_writer�ranger@�_readersr$rr[r
rD�s�z.SqliteQueueDatabase._create_queues_and_workerscCs<|��}|tkrt�d�dSt�d|j�|�|�qdS)Nzworker shutting down.zreceived query %s)r7r(�logger�info�debugr�_process_execution)rr]�async_cursorrrr
r_�s
z$SqliteQueueDatabase._run_worker_loopc
CsPz|�|j|j|j�}Wn&tk
r>}zd}W5d}~XYnXd}|�||�Sr)r>rrr�	Exceptionr )rrgrrrrr
rf�s�z&SqliteQueueDatabase._process_executioncCs|j��|j��fSr)r^ZqsizerYr$rrr
�
queue_size�szSqliteQueueDatabase.queue_sizeTcCsDt|j��||||dkr|jn|d�}|r0|jn|j}|�|�|S)N)rrrrr)rrCrr?r^rY�put)rrrZrequire_commitrrr]rrr
r=�s�
zSqliteQueueDatabase.execute_sqlc	Csb|j�R|jsW5QR�dS|j��|jD]}|��q,t�d�d|_W5QR�dSQRXdS)NFzworkers started.T)�
_conn_lockrAr`rErbrcrd)r�readerrrr
rE�s



zSqliteQueueDatabase.startc	Cs�t�d�|j�f|jr&W5QR�dS|j�t�|jD]}|j�t�q8|j	�
�|jD]}|�
�qZW5QR�dSQRXdS)Nzenvironment stop requested.FT)rcrerkrAr^rjr(rbrYr`�join)rrZrlrrr
�stop�s




zSqliteQueueDatabase.stopc
Cs$|j�|jW5QR�SQRXdSr)rkrAr$rrr
�
is_stopped�szSqliteQueueDatabase.is_stopped)FFr&NN)NN)NTN)r	r
rrrBr:rDr_rfrir=rErnro�
__classcell__rrrJr
r4ns�!
	



r4c@s4eZdZdZddd�Zdd�Zddd�Zd	d
�ZdS)
rM�rGNcCs
||_dSrrq)rrGrrr
r�szThreadHelper.__init__cCst�Srrr$rrr
r��zThreadHelper.eventcCs |dk	r|n|j}t|pdd�S�Nr)�maxsize)rGr�rZmax_sizerrr
r]�szThreadHelper.queuecOst|||d�}d|_|S)N)r\rHrIT)rZdaemon)r�fnrHrIrXrrr
rX�szThreadHelper.thread)N)N)r	r
rr1rrr]rXrrrr
rM�s


rMc@s*eZdZdZdd�Zd	dd�Zdd�ZdS)
rLrqcCst�Sr)�GEventr$rrr
r�rrzGreenletHelper.eventNcCs |dk	r|n|j}t|pdd�Srs)rG�GQueuerurrr
r]szGreenletHelper.queuecs�fdd�}t|f|�|�S)Ncst���||�Sr)�gevent�sleep)�arR�rvrr
�wrapsz#GreenletHelper.thread.<locals>.wrap)�GThread)rrvrHrIr}rr|r
rXszGreenletHelper.thread)N)r	r
rr1rr]rXrrrr
rL�s
rL)Zlogging�weakrefZ	threadingrrr�ImportErrorr]ryrr~Zgevent.eventrwZgevent.queuerxZplayhouse.sqlite_extrZ	getLoggerrcrhr�objectrr9rVr4rMrLrrrr
�<module>s.
G{

Zerion Mini Shell 1.0