File: //proc/self/root/usr/lib/python3.6/site-packages/ipalib/__pycache__/backend.cpython-36.opt-1.pyc
3
�d[e� � @ s� d Z ddlZddlZddlZddlmZ ddlmZmZm Z ddl
mZmZm
Z
eje�ZG dd� dej�ZG dd � d e�ZG d
d� de�ZdS )z*
Base classes for all backed-end plugins.
� N)�plugable)�PublicError�
InternalError�CommandError)�context�
Connection�destroy_contextc @ s e Zd ZdZdS )�Backendz-
Base class for all backend plugins.
N)�__name__�
__module__�__qualname__�__doc__� r r �/usr/lib/python3.6/backend.pyr # s r c @ sR e Zd ZdZddd�Zdd� Zdd� Zd d
� Zdd� Zd
d� Z dd� Z
ee
�ZdS )�Connectiblea$
Base class for backend plugins that create connections.
In addition to the nicety of providing a standard connection API, all
backend plugins that create connections should use this base class so that
`request.destroy_context()` can properly close all open connections.
Fc C s6 t j| |� |r| j| _nd| jtt| ��f | _d S )Nz%s_%s)r �__init__�name�id�str)�selfZapiZshared_instancer r r r 2 s
zConnectible.__init__c O s\ t t| j�r(tdj| j| jtj� j���| j||�}t t| jt
|| j�� tj
d| j� dS )z1
Create thread-local connection.
z%{0} is already connected ({1} in {2})zCreated connection context.%sN)�hasattrr r � Exception�formatr � threading�current_thread�create_connection�setattrr �
disconnect�logger�debug)r �args�kw�connr r r �connect9 s zConnectible.connectc O s t d| j ��d S )Nz%s.create_connection())�NotImplementedErrorr )r r r! r r r r J s zConnectible.create_connectionc C sN t t| j�s(tdj| j| jtj� j���| j� t t| j� t
jd| j� d S )Nz!{0} is not connected ({1} in {2})zDestroyed connection context.%s)r r r r r r r r �destroy_connection�delattrr r )r r r r r M s zConnectible.disconnectc C s t d| j ��d S )Nz%s.destroy_connection())r$ r )r r r r r% Z s zConnectible.destroy_connectionc C s t t| j�S )zY
Return ``True`` if thread-local connection on `request.context` exists.
)r r r )r r r r �isconnected] s zConnectible.isconnectedc C s6 t t| j�s(tdj| j| jtj� j���tt| j�j S )z1
Return thread-local connection.
z!{0} is not connected ({1} in {2}))
r r r �AttributeErrorr r r r �getattrr"