[ Avaa Bypassed ]




Upload:

Command:

hmhc3928@18.191.233.251: ~ $


R6�W	 �@s�dZddlZddlZddlZddlmZddlmZddlmZejd�Z	dd�Z
Gd	d
�d
e�ZGdd�dee�Z
Gd
d�de�ZGdd�dee�Zy-ddlmZGdd�dee�ZWnek
rYnXGdd�de�ZGdd�dee�Zy-ddlmZGdd�dee�ZWnek
r�YnXdS)ap	
Lightweight connection pooling for peewee.

In a multi-threaded application, up to `max_connections` will be opened. Each
thread (or, if using gevent, greenlet) will have it's own connection.

In a single-threaded application, only one connection will be created. It will
be continually recycled until either it exceeds the stale timeout or is closed
explicitly (using `.manual_close()`).

By default, all your application needs to do is ensure that connections are
closed when you are finished with them, and they will be returned to the pool.
For web applications, this typically means that at the beginning of a request,
you will open a connection, and when you return a response, you will close the
connection.

Simple Postgres pool example code:

    # Use the special postgresql extensions.
    from playhouse.pool import PooledPostgresqlExtDatabase

    db = PooledPostgresqlExtDatabase(
        'my_app',
        max_connections=32,
        stale_timeout=300,  # 5 minutes.
        user='postgres')

    class BaseModel(Model):
        class Meta:
            database = db

That's it!

In some situations you may want to manage your connections more explicitly.
Since peewee stores the active connection in a threadlocal, this typically
would mean that there could only ever be one connection open per thread. For
most applications this is desirable, but if you would like to manually manage
multiple connections you can create an *ExecutionContext*.

Execution contexts allow finer-grained control over managing multiple
connections to the database. When an execution context is initialized (either
as a context manager or as a decorated function), a separate connection will
be used for the duration of the wrapped block. You can also choose whether to
wrap the block in a transaction.

Execution context examples (using above `db` instance):

    with db.execution_context() as ctx:
        # A new connection will be opened or pulled from the pool of available
        # connections. Additionally, a transaction will be started.
        user = User.create(username='charlie')

    # When the block ends, the transaction will be committed and the connection
    # will be returned to the pool.

    @db.execution_context(with_transaction=False)
    def do_something(foo, bar):
        # When this function is called, a separate connection is made and will
        # be closed when the function returns.
�N)�
MySQLDatabase)�PostgresqlDatabase)�SqliteDatabasezpeewee.poolcCs0|dk	r,t|ttf�r,t|�S|S)N)�
isinstance�int�float)�val�r	�/pool.py�make_intHs"
rcs�eZdZdd�fdd�Zdd�fdd�Z�fdd�Zd	d
�Zdd�Zd
�fdd�Zdd�Z	dd�Z
�S)�PooledDatabase�Ncsbt|�|_t|�|_g|_i|_t�|_t|_t	t
|�j||�dS)N)r�max_connections�
stale_timeout�_connections�_in_use�set�_closed�id�conn_key�superr�__init__)�self�databaserr�kwargs)�	__class__r	r
rOs			zPooledDatabase.__init__csStt|�j||�|dk	r4t|�|_|dk	rOt|�|_dS)N)rr�initrrr)rrrrZconnect_kwargs)rr	r
rZs
zPooledDatabase.initcs�x�y+tj|j�\}}|j|�}Wn*tk
rZd}}tjd�PYqX|j||�r�tjd|�d}}|jj	|�q|j
r�|j|�r�tjd|�|j|d�|jj	|�d}}qPqW|dkrs|j
r-t|j�|j
kr-td��tt|�j||�}tj�}|j|�}tjd|�||j|<|S)Nz No connection available in pool.zConnection %s was closed.z!Connection %s was stale, closing.TzExceeded maximum connections.zCreated new connection %s.)�heapq�heappoprr�
IndexError�logger�debug�
_is_closedr�discardr�	_is_stale�_closer�lenr�
ValueErrorrr�_connect�time)r�argsr�ts�conn�key)rr	r
r(bs8




	
zPooledDatabase._connectcCstj�||jkS)N)r)r)rZ	timestampr	r	r
r$�szPooledDatabase._is_stalecCs
||jkS)N)r)rr-r,r	r	r
r"�szPooledDatabase._is_closedFcs�|j|�}|r>|jj|�tt|�j|�n�||jkr�|j|}|j|=|jr�|j|�r�t	j
d|�tt|�j|�n)t	j
d|�tj|j
||f�dS)NzClosing stale connection %s.zReturning %s to pool.)rr�addrrr%rrr$r r!r�heappushr)rr,�
close_connr-r+)rr	r
r%�s

zPooledDatabase._closecCsH|j�}|j�|j|j|�|�sD|j|dd�dS)zS
        Close the underlying connection without returning it to the pool.
        r0TN)Zget_conn�closer"rr%)rr,r	r	r
�manual_close�s
zPooledDatabase.manual_closecCs1x*|jD]\}}|j|dd�q
WdS)z<
        Close all connections managed by the pool.
        r0TN)rr%)r�_r,r	r	r
�	close_all�szPooledDatabase.close_all)�__name__�
__module__�__qualname__rrr(r$r"r%r2r4r	r	)rr
rNs,	rcs"eZdZ�fdd�Z�S)�PooledMySQLDatabasec	sGtt|�j||�}|sCy|jd�Wnd}YnX|S)NFT)rr8r"Zping)rr-r,Z	is_closed)rr	r
r"�szPooledMySQLDatabase._is_closed)r5r6r7r"r	r	)rr
r8�sr8cs"eZdZ�fdd�Z�S)�_PooledPostgresqlDatabasecs4tt|�j||�}|s0t|j�}|S)N)rr9r"�bool�closed)rr-r,r;)rr	r
r"�sz$_PooledPostgresqlDatabase._is_closed)r5r6r7r"r	r	)rr
r9�sr9c@seZdZdS)�PooledPostgresqlDatabaseN)r5r6r7r	r	r	r
r<�sr<)�PostgresqlExtDatabasec@seZdZdS)�PooledPostgresqlExtDatabaseN)r5r6r7r	r	r	r
r>�sr>cs"eZdZ�fdd�Z�S)�_PooledSqliteDatabasec	s?tt|�j||�}|s;y|jWndSYnX|S)NT)rr?r"Z
total_changes)rr-r,r;)rr	r
r"�s	z _PooledSqliteDatabase._is_closed)r5r6r7r"r	r	)rr
r?�sr?c@seZdZdS)�PooledSqliteDatabaseN)r5r6r7r	r	r	r
r@�sr@)�SqliteExtDatabasec@seZdZdS)�PooledSqliteExtDatabaseN)r5r6r7r	r	r	r
rB�srB)�__doc__r�loggingr)Zpeeweerrr�	getLoggerr r�objectrr8r9r<Zplayhouse.postgres_extr=r>�ImportErrorr?r@Zplayhouse.sqlite_extrArBr	r	r	r
�<module><s0f




Filemanager

Name Type Size Permission Actions
__init__.cpython-35.opt-1.pyc File 95 B 0644
__init__.cpython-35.pyc File 95 B 0644
apsw_ext.cpython-35.opt-1.pyc File 7.47 KB 0644
apsw_ext.cpython-35.pyc File 7.47 KB 0644
berkeleydb.cpython-35.opt-1.pyc File 3.2 KB 0644
berkeleydb.cpython-35.pyc File 3.2 KB 0644
csv_loader.cpython-35.opt-1.pyc File 135 B 0644
csv_loader.cpython-35.pyc File 135 B 0644
csv_utils.cpython-35.opt-1.pyc File 11.43 KB 0644
csv_utils.cpython-35.pyc File 11.43 KB 0644
dataset.cpython-35.opt-1.pyc File 13.38 KB 0644
dataset.cpython-35.pyc File 13.38 KB 0644
db_url.cpython-35.opt-1.pyc File 3.16 KB 0644
db_url.cpython-35.pyc File 3.16 KB 0644
djpeewee.cpython-35.opt-1.pyc File 5.76 KB 0644
djpeewee.cpython-35.pyc File 5.76 KB 0644
fields.cpython-35.opt-1.pyc File 12.7 KB 0644
fields.cpython-35.pyc File 12.7 KB 0644
flask_utils.cpython-35.opt-1.pyc File 5.93 KB 0644
flask_utils.cpython-35.pyc File 5.97 KB 0644
gfk.cpython-35.opt-1.pyc File 6.02 KB 0644
gfk.cpython-35.pyc File 6.02 KB 0644
hybrid.cpython-35.opt-1.pyc File 2.15 KB 0644
hybrid.cpython-35.pyc File 2.15 KB 0644
kv.cpython-35.opt-1.pyc File 6.77 KB 0644
kv.cpython-35.pyc File 6.77 KB 0644
migrate.cpython-35.opt-1.pyc File 22.68 KB 0644
migrate.cpython-35.pyc File 22.68 KB 0644
pool.cpython-35.opt-1.pyc File 7.96 KB 0644
pool.cpython-35.pyc File 7.96 KB 0644
postgres_ext.cpython-35.opt-1.pyc File 16.86 KB 0644
postgres_ext.cpython-35.pyc File 16.86 KB 0644
read_slave.cpython-35.opt-1.pyc File 1.75 KB 0644
read_slave.cpython-35.pyc File 1.75 KB 0644
reflection.cpython-35.opt-1.pyc File 18.58 KB 0644
reflection.cpython-35.pyc File 18.58 KB 0644
shortcuts.cpython-35.opt-1.pyc File 5.65 KB 0644
shortcuts.cpython-35.pyc File 5.65 KB 0644
signals.cpython-35.opt-1.pyc File 3.04 KB 0644
signals.cpython-35.pyc File 3.04 KB 0644
sqlcipher_ext.cpython-35.opt-1.pyc File 4.52 KB 0644
sqlcipher_ext.cpython-35.pyc File 4.52 KB 0644
sqlite_ext.cpython-35.opt-1.pyc File 36.56 KB 0644
sqlite_ext.cpython-35.pyc File 36.65 KB 0644
sqlite_udf.cpython-35.opt-1.pyc File 16.76 KB 0644
sqlite_udf.cpython-35.pyc File 16.76 KB 0644
test_utils.cpython-35.opt-1.pyc File 4.03 KB 0644
test_utils.cpython-35.pyc File 4.08 KB 0644