ó
šßÈ[c           @` sy   d  Z  d d l m Z m Z m Z m Z d d l m Z d d l m	 Z	 d d g Z
 d e d „ Z e d
 e d	 „ Z d
 S(   ut   
This module contains simple input/output related functionality that is not
part of a larger framework or standard.
i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsi   (   t   six(   t   rangeu   fnpickleu
   fnunpicklec   	      C` s,  | r t  j r d d l } n d d l } t |  t  j ƒ rT t |  d ƒ } t } n |  } t } z± | d k r¥ g  } x˜ t	 | ƒ D] } | j
 | j | ƒ ƒ q‚ Wnk | d k  rg  } t } xP | sý y | j
 | j | ƒ ƒ WqÀ t k
 rù t } qÀ XqÀ Wn | j | ƒ } Wd | r'| j ƒ  n  X| S(   uW   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.
    usecPickle : bool
        If True, the :mod:`cPickle` module is to be used in place of
        :mod:`pickle` (cPickle is faster). This only applies for python 2.x.

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

    Returns
    -------
    contents : obj 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.

    i    Nu   rb(   R   t   PY2t   cPicklet   picklet
   isinstancet   string_typest   opent   Truet   FalseR   t   appendt   loadt   EOFErrort   close(	   t
   fileornamet   numbert
   usecPickleR   t   fR   t   rest   it   eof(    (    s=   lib/python2.7/site-packages/astropy/io/misc/pickle_helpers.pyt
   fnunpickle   s2     		c         C` s¹   | r t  j r d d l } n d d l } | d k rB | j } n  t | t  j ƒ rx t | | rf d n d ƒ } t	 } n | } t
 } z | j |  | d | ƒWd | r´ | j ƒ  n  Xd S(   u[  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.
    usecPickle : bool
        If True (default), the :mod:`cPickle` module is to be used in place of
        :mod:`pickle` (cPickle is faster). This only applies for python 2.x.
    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).

    i    Nu   abu   wbt   protocol(   R   R   R   R   t   Nonet   HIGHEST_PROTOCOLR	   R
   R   R   R   t   dumpR   (   t   objectR   R   R   R   R   R   R   (    (    s=   lib/python2.7/site-packages/astropy/io/misc/pickle_helpers.pyt   fnpickleS   s    	N(   t   __doc__t
   __future__R    R   R   R   t   externR   t   extern.six.movesR   t   __all__R   R   R   R   R   (    (    (    s=   lib/python2.7/site-packages/astropy/io/misc/pickle_helpers.pyt   <module>   s   "B