U
    be                     @   s   d dl Z d dlZd dlZd dlmZ d dlmZ d ZdZdZ	dZ
dZdZejZdd	d
ZefedddZe Zdd ZG dd dZe ZG dd dZe ZG dd dZdS )    N)partial)BytesIO               c                 C   s   d}t |}|tkrnb|tkr2|tO }|d}nF|tkrL|tO }d| }n,|tO }t }t	
||}|| | }||fS )Nr   utf8z%d)typebytesstr	FLAG_TEXTencodeintFLAG_INTEGERFLAG_PICKLEr   picklePicklerdumpgetvalue)keyvaluepickle_versionflagsZ
value_typeoutputZpickler r   R/var/www/html/services/stratfitenv/lib/python3.8/site-packages/pymemcache/serde.py_python_memcache_serializer%   s     

r   r   c                 C   s   t t| dS )z3Return a serializer using a specific pickle versionr   )r   r   r   r   r   r   get_python_memcache_serializer@   s    r   c                 C   s   |dkr|S |t @ r|dS |t@ r.t|S |t@ r>t|S |t@ rzt|}t|}|	 W S  t
k
r   tjddd Y d S X |S )Nr   r	   zPickle errorT)exc_info)r   decoder   r   	FLAG_LONGr   r   r   	Unpicklerload	Exceptionlogginginfo)r   r   r   bufZ	unpicklerr   r   r   python_memcache_deserializerH   s"    


r)   c                   @   s4   e Zd ZdZefeddddZdd Zdd	 ZdS )
PickleSerdea  
    An object which implements the serialization/deserialization protocol for
    :py:class:`pymemcache.client.base.Client` and its descendants using the
    :mod:`pickle` module.

    Serialization and deserialization are implemented as methods of this class.
    To implement a custom serialization/deserialization method for pymemcache,
    you should implement the same interface as the one provided by this object
    -- :py:meth:`pymemcache.serde.PickleSerde.serialize` and
    :py:meth:`pymemcache.serde.PickleSerde.deserialize`. Then,
    pass your custom object to the pymemcache client object in place of
    `PickleSerde`.

    For more details on the serialization protocol, see the class documentation
    for :py:class:`pymemcache.client.base.Client`
    N)r   returnc                 C   s   t || _d S N)r   _serialize_func)selfr   r   r   r   __init__s   s    zPickleSerde.__init__c                 C   s   |  ||S r,   )r-   r.   r   r   r   r   r   	serializev   s    zPickleSerde.serializec                 C   s   t |||S r,   )r)   r.   r   r   r   r   r   r   deserializey   s    zPickleSerde.deserialize)	__name__
__module____qualname____doc__DEFAULT_PICKLE_VERSIONr   r/   r1   r3   r   r   r   r   r*   a   s   r*   c                   @   s6   e Zd ZdZejejedfddZdd Z	dd Z
d	S )
CompressedSerdez
    An object which implements the serialization/deserialization protocol for
    :py:class:`pymemcache.client.base.Client` and its descendants with
    configurable compression.
    i  c                 C   s   || _ || _|| _|| _d S r,   )_serde	_compress_decompress_min_compress_len)r.   compress
decompressZserdeZmin_compress_lenr   r   r   r/      s    zCompressedSerde.__init__c                 C   sd   | j ||\}}t|| j  kr,dkr\n n,|}| |}t|t|k rT|}n|tO }||fS Nr   )r:   r1   lenr=   r;   FLAG_COMPRESSED)r.   r   r   r   	old_valuer   r   r   r1      s    
zCompressedSerde.serializec                 C   s&   |t @ r| |}| j|||}|S r,   )rB   r<   r:   r3   r2   r   r   r   r3      s    
zCompressedSerde.deserializeN)r4   r5   r6   r7   zlibr>   r?   pickle_serder/   r1   r3   r   r   r   r   r9      s   
r9   c                   @   s.   e Zd ZdZddddZdd Zdd	 ZdS )
LegacyWrappingSerdea  
    This class defines how to wrap legacy de/serialization functions into a
    'serde' object which implements '.serialize' and '.deserialize' methods.
    It is used automatically by pymemcache.client.base.Client when the
    'serializer' or 'deserializer' arguments are given.

    The serializer_func and deserializer_func are expected to be None in the
    case that they are missing.
    N)r+   c                 C   s   |p| j | _|p| j| _d S r,   )_default_serializer1   _default_deserializer3   )r.   Zserializer_funcZdeserializer_funcr   r   r   r/      s    zLegacyWrappingSerde.__init__c                 C   s   |dfS r@   r   r0   r   r   r   rG      s    z&LegacyWrappingSerde._default_serializec                 C   s   |S r,   r   r2   r   r   r   rH      s    z(LegacyWrappingSerde._default_deserialize)r4   r5   r6   r7   r/   rG   rH   r   r   r   r   rF      s   
rF   )N)r&   r   rD   	functoolsr   ior   Z
FLAG_BYTESr   r   r"   rB   r   HIGHEST_PROTOCOLr8   r   r   r   Zpython_memcache_serializerr)   r*   rE   r9   Zcompressed_serderF   r   r   r   r   <module>   s(   
+