File: //opt/alt/python37/lib/python3.7/site-packages/bmemcached/__pycache__/protocol.cpython-37.pyc
B
��f�� � @ s� d dl m Z mZ d dlZd dlZd dlZd dlZd dlZyd dlmZ W n e k
rh d dl
mZ Y nX d dlZd dlm
Z
d dlZd dlmZmZ d dlmZ d dlmZmZmZ d dlmZ e�e�ZG d d
� d
ej�ZdS )� )�datetime� timedeltaN)� splitport)�BytesIO)�binary_type� text_type)�long)�AuthenticationNotSupported�InvalidCredentials�MemcachedException)�str_to_bytesc s� e Zd ZdZdZdZddd�Zddd �d
dd �ddd �dd
d �dd
d �dd
d �dd
d �dd
d �ddd �ddd �ddd �ddd �ddd �ddiddiddd �d�Zdddddd d!�Zdddddd"�Z d#Z
dZdf� fd%d&� Zd'd(� Z
ed)d*� �Zd+d,� Zd-d.� Zd/d0� Zed1d2� �Zd3d4� Zd5d6� Zd7d8� Zd9d:� Zd;d<� Zdgd>d?�Zd@dA� ZdBdC� ZdDdE� ZdFdG� ZdhdHdI�ZdidJdK�Z djdLdM�Z!dkdNdO�Z"dldPdQ�Z#dmdSdT�Z$dUdV� Z%dndXdY�Z&dodZd[�Z'dpd\d]�Z(d^d_� Z)d`da� Z*dqdbdc�Z+ddde� Z,� Z-S )r�ProtocolaD
This class is used by Client class to communicate with server.
Reference https://github.com/memcached/memcached/wiki/BinaryProtocolRevamped ::
Header structure
Byte/ 0 | 1 | 2 | 3 |
/ | | | |
|0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|
+---------------+---------------+---------------+---------------+
0| Magic | Opcode | Key length |
+---------------+---------------+---------------+---------------+
4| Extras length | Data type | vbucket id |
+---------------+---------------+---------------+---------------+
8| Total body length |
+---------------+---------------+---------------+---------------+
12| Opaque |
+---------------+---------------+---------------+---------------+
16| CAS |
| |
+---------------+---------------+---------------+---------------+
Total 24 bytes
z
!BBHBBHLLQ� � � )�request�responser z%ds)�command�struct� �
� zLL%ds%ds� � � � � � zQQL%ds� � �I�
� r � � �! z%ds%ds)�get�getk�getkq�set�setq�add�addq�replace�delete�incr�decr�flush�noop�stat�auth_negotiation�auth_requestl �� )�success�
key_not_found�
key_exists�
auth_error�unknown_command�server_disconnected)�object�integerr �
compressed�binaryl �� Nc
s� t t| ��� || _|| _|| _|d kr,tn|| _d | _d| _ || _
|| _|| _|| _
| | _d | _|�d�s�| �| j�\| _| _| �d� nd | _| _| �d� d S )NF�/r r )�superr
�__init__�server� _username� _password�zlib�compression�
connection�
authenticated�socket_timeout�pickle_protocol�pickler� unpickler�tls_context�reconnects_deferred_until�
startswith�split_host_port�host�port�set_retry_delay)
�selfrC �username�passwordrG rJ rK rL rM rN )� __class__� �D/opt/alt/python37/lib/python3.7/site-packages/bmemcached/protocol.pyrB e s$
zProtocol.__init__c C s d� | j| j| j�S )Nz{}_{}_{})�formatrC rD rE )rU rY rY rZ �__str__~ s zProtocol.__str__c C s
| j d kS )N)rR )rU rY rY rZ �server_uses_unix_socket� s z Protocol.server_uses_unix_socketc C s
|| _ d S )N)�retry_delay)rU �valuerY rY rZ rT � s zProtocol.set_retry_delayc C s� | j r
d S d| _| jr(| jt�� kr(d S y�| jr�t�tjtj�| _ | j � | j
� | j �| j| jf� | j
r�| j
j| j | jd�| _ n t�tjtj�| _ | j �| j� | �� W n. tjk
r� t�� t| jd� | _� Y nX d S )NF)�server_hostname)�seconds)rH rI rO r �nowrR �socket�AF_INET�SOCK_STREAM�
settimeoutrJ �connectrS rN �wrap_socket�AF_UNIXrC �_send_authentication�errorr r^ )rU rY rY rZ �_open_connection� s( zProtocol._open_connectionc C s | � � d S )N)�
disconnect)rU � exceptionrY rY rZ �_connection_error� s zProtocol._connection_errorc C sB t |�\}}|dkrd}t|�}t�d|�r:t�dd|�}||fS )z�
Return (host, port) from server.
Port defaults to 11211.
>>> split_host_port('127.0.0.1:11211')
('127.0.0.1', 11211)
>>> split_host_port('127.0.0.1')
('127.0.0.1', 11211)
Ni�+ z:.*$r"