ó
ßČ[c           @   sŘ   d  d l  Z  d  d l Z d  d l m Z d d l m Z d d d g Z d e f d	     YZ d
 e	 f d     YZ
 d   Z d d  Z d   Z d   Z d   Z d   Z d   Z d e f d     YZ d   Z d S(   i˙˙˙˙N(   t   OrderedDicti   (   t   sixt   get_header_from_yamlt   get_yaml_from_headert   get_yaml_from_tablet   ColumnOrderListc           B   s   e  Z d  Z d   Z RS(   sq   
    List of tuples that sorts in a specific order that makes sense for
    astropy table column attributes.
    c         O   sÂ   t  t |   j   d d d d d d g } t |   } g  } x4 | D], } | | k rD | j | | | f  qD qD Wx6 |  D]. \ } } | | k r{ | j | | f  q{ q{ W|  2|  j |  d  S(   Nt   namet   unitt   datatypet   formatt   descriptiont   meta(   t   superR   t   sortt   dictt   appendt   extend(   t   selft   argst   kwargst   column_keyst   in_dictt   out_listt   keyt   val(    (    s1   lib/python2.7/site-packages/astropy/table/meta.pyR      s    (   t   __name__t
   __module__t   __doc__R   (    (    (    s1   lib/python2.7/site-packages/astropy/table/meta.pyR   
   s   t
   ColumnDictc           B   s   e  Z d  Z d   Z RS(   sÎ   
    Specialized dict subclass to represent attributes of a Column
    and return items() in a preferred order.  This is only for use
    in generating a YAML map representation that has a fixed order.
    c         C   s   t  t t |   j    S(   st   
        Return items as a ColumnOrderList, which sorts in the preferred
        way for column attributes.
        (   R   R   R   t   items(   R   (    (    s1   lib/python2.7/site-packages/astropy/table/meta.pyR   +   s    (   R   R   R   R   (    (    (    s1   lib/python2.7/site-packages/astropy/table/meta.pyR   $   s   c   	      c   s<  d d l  } t   } | Vt | | j  s\ | j j d | j d j | j  | j   n  xŮ | j	 D]Î } t | | j
  sŽ | j j d | j d j | j  | j   n  t | j	  d k rů | j j d | j d j t | j	   | j   n  | j	 d \ } } |  j |  } |  j |  } | | | <qf Wd S(	   sÔ  
    Construct OrderedDict from !!omap in yaml safe load.

    Source: https://gist.github.com/weaver/317164
    License: Unspecified

    This is the same as SafeConstructor.construct_yaml_omap(),
    except the data type is changed to OrderedDict() and setitem is
    used instead of append in the loop

    Examples
    --------
    ::

      >>> yaml.load('''  # doctest: +SKIP
      ... !!omap
      ... - foo: bar
      ... - mumble: quux
      ... - baz: gorp
      ... ''')
      OrderedDict([('foo', 'bar'), ('mumble', 'quux'), ('baz', 'gorp')])

      >>> yaml.load('''!!omap [ foo: bar, mumble: quux, baz : gorp ]''')  # doctest: +SKIP
      OrderedDict([('foo', 'bar'), ('mumble', 'quux'), ('baz', 'gorp')])
    i˙˙˙˙Ns!   while constructing an ordered maps!   expected a sequence, but found {}s,   expected a mapping of length 1, but found {}i   s2   expected a single mapping item, but found {} itemsi    (   t   yamlR    t
   isinstancet   SequenceNodet   constructort   ConstructorErrort
   start_markR	   t   idt   valuet   MappingNodet   lent   construct_object(	   t   loadt   nodeR   t   omapt   subnodet   key_nodet
   value_nodeR   R%   (    (    s1   lib/python2.7/site-packages/astropy/table/meta.pyt   _construct_odict3   s,    							c         C   së   d d l  } g  } | j | | d | } |  j d k	 rL | |  j |  j <n  t } x\ | D]T \ } }	 |  j i |	 | 6 }
 t |
 | j  o |
 j	 s  t
 } n  | j |
  qY W| d k rç |  j d k	 rŰ |  j | _ qç | | _ n  | S(   sú   
    This is the same code as BaseRepresenter.represent_sequence(),
    but the value passed to dump.represent_data() in the loop is a
    dictionary instead of a tuple.

    Source: https://gist.github.com/weaver/317164
    License: Unspecified
    i˙˙˙˙Nt
   flow_style(   R   R    t	   alias_keyt   Nonet   represented_objectst   Truet   represent_dataR   t
   ScalarNodet   stylet   FalseR   t   default_flow_styleR0   (   t   dumpt   tagt   sequenceR0   R   R%   R*   t
   best_styleR   R   t   item(    (    s1   lib/python2.7/site-packages/astropy/table/meta.pyt   _repr_pairsi   s     		c         C   s   t  |  d t j |   S(   sž  
    Represent OrderedDict in yaml dump.

    Source: https://gist.github.com/weaver/317164
    License: Unspecified

    >>> data = OrderedDict([('foo', 'bar'), ('mumble', 'quux'), ('baz', 'gorp')])
    >>> yaml.dump(data, default_flow_style=False)  # doctest: +SKIP
    '!!omap\n- foo: bar\n- mumble: quux\n- baz: gorp\n'
    >>> yaml.dump(data, default_flow_style=True)  # doctest: +SKIP
    '!!omap [foo: bar, mumble: quux, baz: gorp]\n'
    u   tag:yaml.org,2002:omap(   R?   R   t	   iteritems(   t   dumpert   data(    (    s1   lib/python2.7/site-packages/astropy/table/meta.pyt   _repr_odict   s    c         C   s   |  j  d |  S(   sż   
    Represent ColumnDict in yaml dump.

    This is the same as an ordinary mapping except that the keys
    are written in a fixed order that makes sense for astropy table
    columns.
    u   tag:yaml.org,2002:map(   t   represent_mapping(   RA   RB   (    (    s1   lib/python2.7/site-packages/astropy/table/meta.pyt   _repr_column_dict   s    c         C   s
  t    } |  j j | d <|  j j j j } t j rM | j d  rM d } n  | j	 d  ri | d  } n  | | d <x d d	   t
 f d
 d   d f d d   d f d d   d f f D]L \ } } } t |  j |  } | |  rś | rő | |  n | | | <qś qś W| S(   sw   
    Extract information from a column (apart from the values) that is required
    to fully serialize the column.
    R   t   bytest   strt   stringt   _i˙˙˙˙R   R   c         S   s
   |  d  k	 S(   N(   R2   (   t   x(    (    s1   lib/python2.7/site-packages/astropy/table/meta.pyt   <lambda>ą   s    R	   c         S   s
   |  d  k	 S(   N(   R2   (   RJ   (    (    s1   lib/python2.7/site-packages/astropy/table/meta.pyRK   ˛   s    R
   c         S   s
   |  d  k	 S(   N(   R2   (   RJ   (    (    s1   lib/python2.7/site-packages/astropy/table/meta.pyRK   ł   s    R   c         S   s   |  S(   N(    (   RJ   (    (    s1   lib/python2.7/site-packages/astropy/table/meta.pyRK   ´   s    (   RF   RG   N(   R   t   infoR   t   dtypet   typeR   R   t   PY2t
   startswitht   endswithRG   R2   t   getattr(   t   colt   attrst	   type_namet   attrt
   nontrivialt   xformt   col_attr(    (    s1   lib/python2.7/site-packages/astropy/table/meta.pyt   _get_col_attributesĄ   s     		
"#c         C   sB   i t  t j |  j   d 6} |  j r8 |  j | d <n  t |  S(   s/  
    Return lines with a YAML representation of header content from the ``table``.

    Parameters
    ----------
    table : `~astropy.table.Table` object
        Table for which header content is output

    Returns
    -------
    lines : list
        List of text lines with YAML header content
    t   colsR   (   t   listR   t
   itervaluest   columnsR   R   (   t   tablet   header(    (    s1   lib/python2.7/site-packages/astropy/table/meta.pyR   ź   s    	c            sŘ   y d d l    Wn t k
 r/ t d   n Xd d l m } d | f   f d     Y} | j t t  | j t t  t	 j	 |   }  g  |  d D] } t
 |  ^ q |  d	 <|  d =  j |  d
 | j   } | S(   sů  
    Return lines with a YAML representation of header content from a Table.

    The ``header`` dict must contain these keys:

    - 'cols' : list of table column objects (required)
    - 'meta' : table 'meta' attribute (optional)

    Other keys included in ``header`` will be serialized in the output YAML
    representation.

    Parameters
    ----------
    header : dict
        Table header content

    Returns
    -------
    lines : list
        List of text lines with YAML header content
    i˙˙˙˙Ns@   `import yaml` failed, PyYAML package is required for ECSV formati   (   t   AstropyDumpert   TableDumperc              s    e  Z d  Z d   f d  Z RS(   sP   
        Custom Dumper that represents OrderedDict as an !!omap object.
        c            s|  g  }   j  | | d | } |  j d k	 r@ | |  j |  j <n  t } t | d  r° | j   } t | d  r} | j   q° t |  } y t	 |  } Wq° t
 k
 rŹ q° Xn  x | D] \ } } |  j |  }	 |  j |  }
 t |	   j  oú |	 j st } n  t |
   j  o|
 j s+t } n  | j |	 |
 f  qˇ W| d k rx|  j d k	 rl|  j | _ qx| | _ n  | S(   s|  
            This is a combination of the Python 2 and 3 versions of this method
            in the PyYAML library to allow the required key ordering via the
            ColumnOrderList object.  The Python 3 version insists on turning the
            items() mapping into a list object and sorting, which results in
            alphabetical order for the column keys.
            R0   R   R   N(   R&   R1   R2   R3   R4   t   hasattrR   R   R\   t   sortedt	   TypeErrorR5   R   R6   R7   R8   R   R9   R0   (   R   R;   t   mappingR0   R%   R*   R=   t   item_keyt
   item_valuet   node_keyt
   node_value(   R   (    s1   lib/python2.7/site-packages/astropy/table/meta.pyRD   ô   s6    		N(   R   R   R   R2   RD   (    (   R   (    s1   lib/python2.7/site-packages/astropy/table/meta.pyRb   ď   s   R[   R   t   Dumper(   R   t   ImportErrort   io.misc.yamlRa   t   add_representerR    RC   R   RE   t   copyRZ   R:   t
   splitlines(   R`   Ra   Rb   RS   t   lines(    (   R   s1   lib/python2.7/site-packages/astropy/table/meta.pyR   Ň   s    ,'t   YamlParseErrorc           B   s   e  Z RS(    (   R   R   (    (    (    s1   lib/python2.7/site-packages/astropy/table/meta.pyRr   &  s   c         C   sĂ   y d d l  } Wn t k
 r/ t d   n Xd d l m } d | f d     Y} | j d t  t j d	 j |    } y | j	 | d
 | } Wn% t
 k
 rž } t t |    n X| S(   sn  
    Get a header dict from input ``lines`` which should be valid YAML in the
    ECSV meta format.  This input will typically be created by
    get_yaml_from_header.  The output is a dictionary which describes all the
    table and column meta.

    The get_cols() method in the io/ascii/ecsv.py file should be used as a
    guide to using the information when constructing a table using this
    header dict information.

    Parameters
    ----------
    lines : list
        List of text lines with YAML header content

    Returns
    -------
    header : dict
        Dictionary describing table and column meta
    i˙˙˙˙Ns@   `import yaml` failed, PyYAML package is required for ECSV formati   (   t   AstropyLoadert   TableLoaderc           B   s   e  Z d  Z RS(   sľ   
        Custom Loader that constructs OrderedDict from an !!omap object.
        This does nothing but provide a namespace for adding the
        custom odict constructor.
        (   R   R   R   (    (    (    s1   lib/python2.7/site-packages/astropy/table/meta.pyRt   G  s   u   tag:yaml.org,2002:omaps   
t   Loader(   R   Rl   Rm   Rs   t   add_constructorR/   t   textwrapt   dedentt   joinR)   t	   ExceptionRr   RG   (   Rq   R   Rs   Rt   t   header_yamlR`   t   err(    (    s1   lib/python2.7/site-packages/astropy/table/meta.pyR   *  s    (   Rw   Ro   t   collectionsR    t   externR   t   __all__R\   R   R   R   R/   R2   R?   RC   RE   RZ   R   R   Rz   Rr   R   (    (    (    s1   lib/python2.7/site-packages/astropy/table/meta.pyt   <module>   s   	6					T