U
    e»{jË  ã                   @   s,   d Z ddlZddgZddd„Zd	dd„ZdS )
zt
This module contains simple input/output related functionality that is not
part of a larger framework or standard.
é    NÚfnpickleÚ
fnunpicklec                 C   s¶   t | tƒrt| dƒ}d}n| }d}z€|dkrPg }t|ƒD ]}| t |¡¡ q8nP|dk r–g }d}|s z| t |¡¡ W q` tk
r�   d}Y q`X q`n
t |¡}W 5 |r°| ¡  X |S )a±  Unpickle pickled objects from a specified file and return the contents.

    Parameters
    ----------
    fileorname : str or file-like
        The file name or file from which to unpickle objects. If a file object,
        it should have been opened in binary mode.
    number : int
        If 0, a single object will be returned (the first in the file). If >0,
        this specifies the number of objects to be unpickled, and a list will
        be returned with exactly that many objects. If <0, all objects in the
        file will be unpickled and returned as a list.

    Raises
    ------
    EOFError
        If ``number`` is >0 and there are fewer than ``number`` objects in the
        pickled file.

    Returns
    -------
    contents : object or list
        If ``number`` is 0, this is a individual object - the first one
        unpickled from the file. Otherwise, it is a list of objects unpickled
        from the file.

    ÚrbTFr   )	Ú
isinstanceÚstrÚopenÚcloseÚrangeÚappendÚpickleÚloadÚEOFError)Ú
fileornameÚnumberÚfr   ÚresÚiÚeof© r   ú]/var/www/html/bwave/python/venv/lib/python3.8/site-packages/astropy/io/misc/pickle_helpers.pyr      s,    


Fc                 C   s`   |dkrt j}t|tƒr0t||r$dndƒ}d}n|}d}zt j| ||d� W 5 |rZ| ¡  X dS )a©  Pickle an object to a specified file.

    Parameters
    ----------
    object
        The python object to pickle.
    fileorname : str or file-like
        The filename or file into which the `object` should be pickled. If a
        file object, it should have been opened in binary mode.
    protocol : int or None
        Pickle protocol to use - see the :mod:`pickle` module for details on
        these options. If None, the most recent protocol will be used.
    append : bool
        If True, the object is appended to the end of the file, otherwise the
        file will be overwritten (if a file object is given instead of a
        file name, this has no effect).

    NÚabÚwbTF)Úprotocol)r   ÚHIGHEST_PROTOCOLr   r   r   r   Údump)Úobjectr   r   r
   r   r   r   r   r   r   F   s    
)r   )NF)Ú__doc__r   Ú__all__r   r   r   r   r   r   Ú<module>   s   
: