o
    ={c
                     @   sF   d Z ddlZddlZddlm  mZ ddlmZ dd Z	dd Z
dS )z5Saving utilities to support Python's Pickle protocol.    N)
saving_libc              
   C   s   t  }zAz(tj|d}t|d}||  W d   n1 s"w   Y  t|}W n t	y; } z|d}~ww |W t
jj| S t
jj| w )zReconstruct a Model from the output of `serialize_model_as_bytecode`.

    Args:
        serialized_model: (bytes) return value from
          `serialize_model_as_bytecode`.

    Returns:
        Keras Model instance.
    model.keraswbN)tempfilemkdtempospathjoinopenwriter   Z
load_model	Exceptiontfiogfilermtree)Zserialized_modeltemp_dirfilepathfmodele r   9lib/python3.10/site-packages/keras/saving/pickle_utils.pydeserialize_model_from_bytecode   s    r   c              
   C   s   t  }zAz(tj|d}t| | t|d}| }W d   n1 s'w   Y  W n t	y; } z|d}~ww |W t
jj| S t
jj| w )zConvert a Keras Model into a bytecode representation for pickling.

    Args:
        model: Keras Model instance.

    Returns:
        Tuple that can be read by `deserialize_from_bytecode`.
    r   rbN)r   r   r   r   r	   r   Z
save_modelr
   readr   r   r   r   r   )r   r   r   r   datar   r   r   r   serialize_model_as_bytecode7   s   
 r   )__doc__r   r   Ztensorflow.compat.v2compatZv2r   Zkeras.saving.experimentalr   r   r   r   r   r   r   <module>   s   