ó
šßÈ[c           @` s  d  Z  d d l m Z m Z m Z d d l Z d d l m Z d d l m	 Z	 d e j
 f d	 „  ƒ  YZ d
 e j f d „  ƒ  YZ d e j f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e j f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d  e f d! „  ƒ  YZ d" e j f d# „  ƒ  YZ d$ e f d% „  ƒ  YZ d& e f d' „  ƒ  YZ d( e f d) „  ƒ  YZ d* e f d+ „  ƒ  YZ d, e f d- „  ƒ  YZ  d. e f d/ „  ƒ  YZ! d S(0   s+  An extensible ASCII table reader and writer.

basic.py:
  Basic table read / write functionality for simple character
  delimited files with various options for column header definition.

:Copyright: Smithsonian Astrophysical Observatory (2011)
:Author: Tom Aldcroft (aldcroft@head.cfa.harvard.edu)
i    (   t   absolute_importt   divisiont   print_functionNi   (   t   corei   (   t   zipt   BasicHeaderc           B` s    e  Z d  Z d Z d Z d Z RS(   s¤   
    Basic table Header Reader

    Set a few defaults for common ascii table formats
    (start at line 0, comments begin with ``#`` and possibly white space)
    i    s   \s*#s   # (   t   __name__t
   __module__t   __doc__t
   start_linet   commentt   write_comment(    (    (    s5   lib/python2.7/site-packages/astropy/io/ascii/basic.pyR      s   t	   BasicDatac           B` s    e  Z d  Z d Z d Z d Z RS(   s¢   
    Basic table Data Reader

    Set a few defaults for common ascii table formats
    (start at line 1, comments begin with ``#`` and possibly white space)
    i   s   \s*#s   # (   R   R   R   R	   R
   R   (    (    (    s5   lib/python2.7/site-packages/astropy/io/ascii/basic.pyR       s   t   Basicc           B` s&   e  Z d  Z d Z d Z e Z e Z RS(   s8  
    Read a character-delimited table with a single header line at the top
    followed by data lines to the end of the table.  Lines beginning with # as
    the first non-whitespace character are comments.  This reader is highly
    configurable.
    ::

        rdr = ascii.get_reader(Reader=ascii.Basic)
        rdr.header.splitter.delimiter = ' '
        rdr.data.splitter.delimiter = ' '
        rdr.header.start_line = 0
        rdr.data.start_line = 1
        rdr.data.end_line = None
        rdr.header.comment = r'\s*#'
        rdr.data.comment = r'\s*#'

    Example table::

      # Column definition is the first uncommented line
      # Default delimiter is the space character.
      apples oranges pears

      # Data starts after the header column definition, blank lines ignored
      1 2 3
      4 5 6
    t   basics"   Basic table with custom delimiters(	   R   R   R   t   _format_namet   _descriptionR   t   header_classR   t
   data_class(    (    (    s5   lib/python2.7/site-packages/astropy/io/ascii/basic.pyR   ,   s
   t   NoHeaderHeaderc           B` s   e  Z d  Z d Z RS(   s    
    Reader for table header without a header

    Set the start of header line number to `None`, which tells the basic
    reader there is no header line.
    N(   R   R   R   t   NoneR	   (    (    (    s5   lib/python2.7/site-packages/astropy/io/ascii/basic.pyR   N   s   t   NoHeaderDatac           B` s   e  Z d  Z d Z RS(   sz   
    Reader for table data without a header

    Data starts at first uncommented line since there is no header line.
    i    (   R   R   R   R	   (    (    (    s5   lib/python2.7/site-packages/astropy/io/ascii/basic.pyR   X   s   t   NoHeaderc           B` s&   e  Z d  Z d Z d Z e Z e Z RS(   s  
    Read a table with no header line.  Columns are autonamed using
    header.auto_format which defaults to "col%d".  Otherwise this reader
    the same as the :class:`Basic` class from which it is derived.  Example::

      # Table data
      1 2 "hello there"
      3 4 world
    t	   no_headers   Basic table with no headers(	   R   R   R   R   R   R   R   R   R   (    (    (    s5   lib/python2.7/site-packages/astropy/io/ascii/basic.pyR   a   s
   	t   CommentedHeaderHeaderc           B` s    e  Z d  Z d „  Z d „  Z RS(   s›   
    Header class for which the column definition line starts with the
    comment character.  See the :class:`CommentedHeader` class  for an example.
    c         c` sN   t  j |  j ƒ } x5 | D]- } | j | ƒ } | r | | j ƒ  Vq q Wd S(   sƒ   
        Return only lines that start with the comment regexp.  For these
        lines strip out the matching characters.
        N(   t   ret   compileR
   t   matcht   end(   t   selft   linest
   re_commentt   lineR   (    (    s5   lib/python2.7/site-packages/astropy/io/ascii/basic.pyt   process_linesw   s
    c         C` s'   | j  |  j |  j j |  j ƒ ƒ d  S(   N(   t   appendR   t   splittert   joint   colnames(   R   R   (    (    s5   lib/python2.7/site-packages/astropy/io/ascii/basic.pyt   write‚   s    (   R   R   R   R!   R&   (    (    (    s5   lib/python2.7/site-packages/astropy/io/ascii/basic.pyR   q   s   	t   CommentedHeaderc           B` s8   e  Z d  Z d Z d Z e Z e Z d „  Z	 d „  Z
 RS(   sŒ  
    Read a file where the column names are given in a line that begins with
    the header comment character. ``header_start`` can be used to specify the
    line index of column names, and it can be a negative index (for example -1
    for the last commented line).  The default delimiter is the <space>
    character.::

      # col1 col2 col3
      # Comment line
      1 2 3
      4 5 6
    t   commented_headers    Column names in a commented linec         C` s¥   t  t |  ƒ j | ƒ } d | j k r¡ |  j j } | d k  rY t | j d ƒ | } n  | j d |  | j d | d | j d <| j d s¡ | j d =q¡ n  | S(   s   
        Read input data (file-like object, filename, list of strings, or
        single string) into a Table and return the result.
        t   commentsi    i   (   t   superR'   t   readt   metat   headerR	   t   len(   R   t   tablet   outt   idx(    (    s5   lib/python2.7/site-packages/astropy/io/ascii/basic.pyR+   ™   s    +c         C` s'   |  j  j | ƒ |  j  j | | ƒ d S(   sL   
        Write comment lines after, rather than before, the header.
        N(   R-   R&   t   write_comments(   R   R   R,   (    (    s5   lib/python2.7/site-packages/astropy/io/ascii/basic.pyt   write_header¬   s    (   R   R   R   R   R   R   R   R   R   R+   R3   (    (    (    s5   lib/python2.7/site-packages/astropy/io/ascii/basic.pyR'   †   s   	t   TabHeaderSplitterc           B` s   e  Z d  Z d Z d Z RS(   s/   Split lines on tab and do not remove whitespaces   	N(   R   R   R   t	   delimiterR   t   process_line(    (    (    s5   lib/python2.7/site-packages/astropy/io/ascii/basic.pyR4   ´   s   t   TabDataSplitterc           B` s   e  Z d  Z d Z e Z RS(   sS   
    Don't strip data value whitespace since that is significant in TSV tables
    N(   R   R   R   R   t   process_valt   Falset   skipinitialspace(    (    (    s5   lib/python2.7/site-packages/astropy/io/ascii/basic.pyR7   º   s   t	   TabHeaderc           B` s   e  Z d  Z e Z RS(   s?   
    Reader for header of tables with tab separated header
    (   R   R   R   R4   t   splitter_class(    (    (    s5   lib/python2.7/site-packages/astropy/io/ascii/basic.pyR;   Â   s   t   TabDatac           B` s   e  Z d  Z e Z RS(   s;   
    Reader for data of tables with tab separated data
    (   R   R   R   R7   R<   (    (    (    s5   lib/python2.7/site-packages/astropy/io/ascii/basic.pyR=   É   s   t   Tabc           B` s&   e  Z d  Z d Z d Z e Z e Z RS(   s  
    Read a tab-separated file.  Unlike the :class:`Basic` reader, whitespace is
    not stripped from the beginning and end of either lines or individual column
    values.

    Example::

      col1 <tab> col2 <tab> col3
      # Comment line
      1 <tab> 2 <tab> 5
    t   tabs%   Basic table with tab-separated values(	   R   R   R   R   R   R;   R   R=   R   (    (    (    s5   lib/python2.7/site-packages/astropy/io/ascii/basic.pyR>   Ð   s
   t   CsvSplitterc           B` s   e  Z d  Z d Z RS(   s?   
    Split on comma for CSV (comma-separated-value) tables
    t   ,(   R   R   R   R5   (    (    (    s5   lib/python2.7/site-packages/astropy/io/ascii/basic.pyR@   â   s   t	   CsvHeaderc           B` s    e  Z d  Z e Z d Z d Z RS(   sJ   
    Header that uses the :class:`astropy.io.ascii.basic.CsvSplitter`
    N(   R   R   R   R@   R<   R   R
   R   (    (    (    s5   lib/python2.7/site-packages/astropy/io/ascii/basic.pyRB   é   s   t   CsvDatac           B` s2   e  Z d  Z e Z e j d f g Z d Z	 d Z
 RS(   sH   
    Data that uses the :class:`astropy.io.ascii.basic.CsvSplitter`
    t    N(   R   R   R   R@   R<   R   t   maskedt   fill_valuesR   R
   R   (    (    (    s5   lib/python2.7/site-packages/astropy/io/ascii/basic.pyRC   ò   s
   t   Csvc           B` s5   e  Z d  Z d Z e Z d Z e Z e	 Z
 d „  Z RS(   sV  
    Read a CSV (comma-separated-values) file.

    Example::

      num,ra,dec,radius,mag
      1,32.23222,10.1211,0.8,18.1
      2,38.12321,-88.1321,2.2,17.0

    Plain csv (comma separated value) files typically contain as many entries
    as there are columns on each line. In contrast, common spreadsheet editors
    stop writing if all remaining cells on a line are empty, which can lead to
    lines where the rightmost entries are missing. This Reader can deal with
    such files.
    Masked values (indicated by an empty '' field value when reading) are
    written out in the same way with an empty ('') field.  This is different
    from the typical default for `astropy.io.ascii` in which missing values are
    indicated by ``--``.

    Example::

      num,ra,dec,radius,mag
      1,32.23222,10.1211
      2,38.12321,-88.1321,2.2,17.0
    t   csvs   Comma-separated-valuesc         C` s7   t  | ƒ | k  r3 | j | t  | ƒ d g ƒ n  | S(   sQ  
        Adjust row if it is too short.

        If a data row is shorter than the header, add empty values to make it the
        right length.
        Note that this will *not* be called if the row already matches the header.

        Parameters
        ----------
        str_vals : list
            A list of value strings from the current row of the table.
        ncols : int
            The expected number of entries from the table header.

        Returns
        -------
        str_vals : list
            List of strings to be parsed into data entries in the output table.
        RD   (   R.   t   extend(   R   t   str_valst   ncols(    (    s5   lib/python2.7/site-packages/astropy/io/ascii/basic.pyt   inconsistent_handler  s    !(   R   R   R   R   t   Truet   _io_registry_can_writeR   RB   R   RC   R   RL   (    (    (    s5   lib/python2.7/site-packages/astropy/io/ascii/basic.pyRG   ü   s   t	   RdbHeaderc           B` sC   e  Z d  Z i e j d 6e j d 6Z d „  Z d „  Z d „  Z	 RS(   s   
    Header for RDB tables
    t   nt   sc         C` s   | j  d S(   Niÿÿÿÿ(   t   raw_type(   R   t   col(    (    s5   lib/python2.7/site-packages/astropy/io/ascii/basic.pyt   get_type_map_key>  s    c   	      C` s  |  j  | ƒ } g  t t d ƒ |  j | ƒ ƒ D] \ } } | ^ q. } t | ƒ d k rg t d ƒ ‚ n  | \ |  _ } t |  j ƒ t | ƒ k r  t d ƒ ‚ n  t d „  | Dƒ ƒ rÎ t d j | ƒ ƒ ‚ n  |  j	 ƒ  x; t |  j
 | ƒ D]' \ } } | | _ |  j | ƒ | _ që Wd S(   sw  
        Initialize the header Column objects from the table ``lines``.

        This is a specialized get_cols for the RDB type:
        Line 0: RDB col names
        Line 1: RDB col definitions
        Line 2+: RDB data rows


        Parameters
        ----------
        lines : list
            List of table lines

        Returns
        -------
        None

        i   s   RDB header requires 2 linessC   RDB header mismatch between number of column names and column typesc         s` s(   |  ] } t  j d  | t  j ƒ Vq d S(   s	   \d*(N|S)$N(   R   R   t
   IGNORECASE(   t   .0t   x(    (    s5   lib/python2.7/site-packages/astropy/io/ascii/basic.pys	   <genexpr>^  s    s5   RDB types definitions do not all match [num](N|S): {}N(   R!   R   t   rangeR#   R.   t
   ValueErrort   namest   anyt   formatt   _set_cols_from_namest   colsRR   t   get_col_typet   type(	   R   R   t   header_linest   _t   hlt   header_vals_listt	   raw_typesRS   RR   (    (    s5   lib/python2.7/site-packages/astropy/io/ascii/basic.pyt   get_colsA  s    7
	c         C` s   | j  |  j j |  j ƒ ƒ g  } x? |  j D]4 } | j j j d k rM d n d } | j  | ƒ q, W| j  |  j j | ƒ ƒ d  S(   Nt   St   Ut   N(   Rg   Rh   (   R"   R#   R$   R%   R^   t   infot   dtypet   kind(   R   R   t	   rdb_typesRS   t   rdb_type(    (    s5   lib/python2.7/site-packages/astropy/io/ascii/basic.pyR&   f  s    !(
   R   R   R   R   t   NumTypet   StrTypet   col_type_mapRT   Rf   R&   (    (    (    s5   lib/python2.7/site-packages/astropy/io/ascii/basic.pyRO   7  s   		%t   RdbDatac           B` s   e  Z d  Z d Z RS(   s=   
    Data reader for RDB data. Starts reading at line 2.
    i   (   R   R   R   R	   (    (    (    s5   lib/python2.7/site-packages/astropy/io/ascii/basic.pyRr   q  s   t   Rdbc           B` s5   e  Z d  Z d Z d g Z d Z d Z e Z e	 Z
 RS(   s  
    Read a tab-separated file with an extra line after the column definition
    line.  The RDB format meets this definition.  Example::

      col1 <tab> col2 <tab> col3
      N <tab> S <tab> N
      1 <tab> 2 <tab> 5

    In this reader the second line is just ignored.
    t   rdbs   .rdbs0   Tab-separated with a type definition header line(   R   R   R   R   t   _io_registry_format_aliasest   _io_registry_suffixR   RO   R   Rr   R   (    (    (    s5   lib/python2.7/site-packages/astropy/io/ascii/basic.pyRs   x  s   
	("   R   t
   __future__R    R   R   R   RD   R   t   extern.six.movesR   t
   BaseHeaderR   t   BaseDataR   t
   BaseReaderR   R   R   R   R   R'   t   DefaultSplitterR4   R7   R;   R=   R>   R@   RB   RC   RG   RO   Rr   Rs   (    (    (    s5   lib/python2.7/site-packages/astropy/io/ascii/basic.pyt   <module>
   s0   "
	.	
;: