ó
šßÈ[c           @` sÛ   d  Z  d d l m Z m Z m Z m Z d d l m Z d d l Z d d l	 Z	 d d l
 Z
 d d l m Z m Z d d l m Z d d	 l m Z d d
 l m Z d „  Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   u-   
Handles a "generic" string format for units
i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsi   (   t   sixNi   (   t   coret   utils(   t   Base(   t   classproperty(   t   did_you_meanc         C` s_  t  | t j ƒ r<g  } |  j rL | j d k rL | j d j | j ƒ ƒ n  t | j ƒ r/t	 j
 | j | j ƒ \ } } t | ƒ rž | j |  j | ƒ ƒ n" t | ƒ d k rÀ | j d ƒ n  t | ƒ r/| j d ƒ |  j | ƒ } t | ƒ d k r| j d j | ƒ ƒ q,| j d j | ƒ ƒ q/n  d j | ƒ St  | t j ƒ r[|  j | ƒ Sd  S(	   Ni   u   {0:g}i    u   1u   /u   {0}u   ({0})u    (   t
   isinstanceR   t   CompositeUnitt   _show_scalet   scalet   appendt   formatt   lent   basesR   t   get_grouped_by_powerst   powerst   _format_unit_listt   joint	   NamedUnitt   _get_unit_name(   t   clst   unitt   partst	   positivest	   negativest	   unit_list(    (    s;   lib/python2.7/site-packages/astropy/units/format/generic.pyt
   _to_string   s(    t   Genericc           B` s^  e  Z d  Z e Z d d d d d d d d d	 d
 d d f Z e d e ƒ d „  ƒ Z e d e ƒ d „  ƒ Z e d e ƒ d „  ƒ Z	 e d e ƒ d „  ƒ Z
 e d e ƒ d „  ƒ Z e d e ƒ d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e e d „ ƒ Z e e d „ ƒ Z e e d „ ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z RS(   uì   
    A "generic" format.

    The syntax of the format is based directly on the FITS standard,
    but instead of only supporting the units that FITS knows about, it
    supports any unit available in the `astropy.units` namespace.
    u   DOUBLE_STARu   STARu   PERIODu   SOLIDUSu   CARETu
   OPEN_PARENu   CLOSE_PARENu   FUNCNAMEu   UNITu   SIGNu   UINTu   UFLOATt   lazyc         C` s
   |  j  ƒ  S(   N(   t   _generate_unit_names(   R   (    (    s;   lib/python2.7/site-packages/astropy/units/format/generic.pyt
   _all_unitsP   s    c         C` s   |  j  d S(   Ni    (   R"   (   R   (    (    s;   lib/python2.7/site-packages/astropy/units/format/generic.pyt   _unitsT   s    c         C` s   |  j  d S(   Ni   (   R"   (   R   (    (    s;   lib/python2.7/site-packages/astropy/units/format/generic.pyt   _deprecated_unitsX   s    c         C` s   |  j  d S(   Ni   (   R"   (   R   (    (    s;   lib/python2.7/site-packages/astropy/units/format/generic.pyt
   _functions\   s    c         C` s
   |  j  ƒ  S(   N(   t   _make_parser(   R   (    (    s;   lib/python2.7/site-packages/astropy/units/format/generic.pyt   _parser`   s    c         C` s
   |  j  ƒ  S(   N(   t   _make_lexer(   R   (    (    s;   lib/python2.7/site-packages/astropy/units/format/generic.pyt   _lexerd   s    c      	   ` sÂ   d d l  m } ˆ  j } d } d } d } d } d } d } d	 }	 d
 „  }
 d „  } d „  } d „  } ‡  f d †  } d } d „  } | j d t d t d ƒ d t j j t ƒ d t	 j
 ƒ } | S(   Ni   (   t   lexu   \*u   \.u   /u   \*\*u   \^u   \(u   \)c         S` s}   t  j d |  j ƒ s3 d |  _ t |  j ƒ |  _ nF |  j j d ƒ rg d |  _ t |  j d  ƒ |  _ n t |  j ƒ |  _ |  S(   u$   ((\d+\.?\d*)|(\.\d+))([eE][+-]?\d+)?u   [eE\.]u   UINTu   .iÿÿÿÿ(   t   ret   searcht   valuet   typet   intt   endswitht   float(   t   t(    (    s;   lib/python2.7/site-packages/astropy/units/format/generic.pyt   t_UFLOATx   s    		c         S` s   t  |  j ƒ |  _ |  S(   u   \d+(   R/   R-   (   R2   (    (    s;   lib/python2.7/site-packages/astropy/units/format/generic.pyt   t_UINT„   s    c         S` s   t  |  j d ƒ |  _ |  S(   u
   [+-](?=\d)u   1(   R1   R-   (   R2   (    (    s;   lib/python2.7/site-packages/astropy/units/format/generic.pyt   t_SIGN‰   s    c         S` s   |  S(   u3   ((sqrt)|(ln)|(exp)|(log)|(mag)|(dB)|(dex))(?=\ *\()(    (   R2   (    (    s;   lib/python2.7/site-packages/astropy/units/format/generic.pyt
   t_FUNCNAME   s    c         ` s   ˆ  j  |  ƒ |  _ |  S(   u3   %|([YZEPTGMkhdcmunpfazy]?'((?!\d)\w)+')|((?!\d)\w)+(   t	   _get_unitR-   (   R2   (   R   (    s;   lib/python2.7/site-packages/astropy/units/format/generic.pyt   t_UNIT”   s    u    c         S` s   t  d j |  j ƒ ƒ ‚ d  S(   Nu   Invalid character at col {0}(   t
   ValueErrorR   t   lexpos(   R2   (    (    s;   lib/python2.7/site-packages/astropy/units/format/generic.pyt   t_errorœ   s    t   optimizet   lextabu   generic_lextabt	   outputdirt   reflags(   t
   extern.plyR*   t   _tokenst   Truet   strt   ost   patht   dirnamet   __file__R+   t   UNICODE(   R   R*   t   tokenst   t_STARt   t_PERIODt	   t_SOLIDUSt   t_DOUBLE_STARt   t_CARETt   t_OPEN_PARENt   t_CLOSE_PARENR3   R4   R5   R6   R8   t   t_ignoreR;   t   lexer(    (   R   s;   lib/python2.7/site-packages/astropy/units/format/generic.pyR(   h   s(    						c         ` s+  d d l  m } ˆ  j } d „  } d „  } d „  } d „  } ‡  f d †  } ‡  f d †  } ‡  f d	 †  }	 d
 „  }
 d „  } d „  } d „  } d „  } d „  } d „  } d „  } d „  } d „  } d „  } d „  } d „  } ‡  f d †  } d „  } | j d t d t d ƒ d t j j t ƒ ƒ } | S(   uô  
        The grammar here is based on the description in the `FITS
        standard
        <http://fits.gsfc.nasa.gov/standard30/fits_standard30aa.pdf>`_,
        Section 4.3, which is not terribly precise.  The exact grammar
        is here is based on the YACC grammar in the `unity library
        <https://bitbucket.org/nxg/unity/>`_.

        This same grammar is used by the `"fits"` and `"vounit"`
        formats, the only difference being the set of available unit
        strings.
        i   (   t   yaccc         S` sŸ   d d l  m } t |  ƒ d k r9 | |  d ƒ |  d <nb t |  ƒ d k rj | |  d |  d ƒ |  d <n1 t |  ƒ d k r› | |  d |  d ƒ |  d <n  d S(   u¼  
            main : product_of_units
                 | factor product_of_units
                 | factor product product_of_units
                 | division_product_of_units
                 | factor division_product_of_units
                 | factor product division_product_of_units
                 | inverse_unit
                 | factor inverse_unit
                 | factor product inverse_unit
                 | factor
            i   (   t   Uniti   i    i   i   N(   R   RT   R   (   t   pRT   (    (    s;   lib/python2.7/site-packages/astropy/units/format/generic.pyt   p_main¹   s    c         S` sS   d d l  m } t |  ƒ d k rA | |  d |  d ƒ |  d <n |  d |  d <d S(   u¢   
            division_product_of_units : division_product_of_units division product_of_units
                                      | product_of_units
            i   (   RT   i   i   i   i    N(   R   RT   R   (   RU   RT   (    (    s;   lib/python2.7/site-packages/astropy/units/format/generic.pyt   p_division_product_of_unitsÎ   s    c         S` s   |  d d |  d <d S(   uA   
            inverse_unit : division unit_expression
            i   iÿÿÿÿi    N(    (   RU   (    (    s;   lib/python2.7/site-packages/astropy/units/format/generic.pyt   p_inverse_unitÙ   s    c         S` s   |  d |  d <d S(   up   
            factor : factor_fits
                   | factor_float
                   | factor_int
            i   i    N(    (   RU   (    (    s;   lib/python2.7/site-packages/astropy/units/format/generic.pyt   p_factorß   s    c         ` s·   ˆ  j  d k r t d ƒ ‚ n  t |  ƒ d k rW |  d |  d t |  d ƒ |  d <n\ t |  ƒ d k r |  d |  d t |  d ƒ |  d <n# t |  ƒ d k r³ |  d |  d <n  d	 S(
   u®   
            factor_float : signed_float
                         | signed_float UINT signed_int
                         | signed_float UINT power numeric_power
            u   fitsu$   Numeric factor not supported by FITSi   i   i   i   i    i   N(   t   nameR9   R   R1   (   RU   (   R   (    s;   lib/python2.7/site-packages/astropy/units/format/generic.pyt   p_factor_floatç   s    ''c         ` s  ˆ  j  d k r t d ƒ ‚ n  t |  ƒ d k rA |  d |  d <nÏ t |  ƒ d k rr |  d t |  d ƒ |  d <nž t |  ƒ d k rÝ t |  d t ƒ r¾ |  d |  d t |  d ƒ |  d <q|  d t |  d ƒ |  d <n3 t |  ƒ d k r|  d |  d |  d |  d <n  d	 S(
   uë   
            factor_int : UINT
                       | UINT signed_int
                       | UINT power numeric_power
                       | UINT UINT signed_int
                       | UINT UINT power numeric_power
            u   fitsu$   Numeric factor not supported by FITSi   i   i    i   i   i   N(   RZ   R9   R   R1   R
   R/   (   RU   (   R   (    s;   lib/python2.7/site-packages/astropy/units/format/generic.pyt   p_factor_intö   s    'c         ` sÛ   |  d d k r5 ˆ  j  d k r. t d ƒ ‚ q5 d Sn  t |  ƒ d k r‰ |  d d k rl d |  d
 |  d <q× d |  d |  d
 |  d <nN t |  ƒ d k r° d |  d
 |  d <n' t |  ƒ d k r× d |  d |  d <n  d S(   uî   
            factor_fits : UINT power OPEN_PAREN signed_int CLOSE_PAREN
                        | UINT power signed_int
                        | UINT SIGN UINT
                        | UINT OPEN_PAREN signed_int CLOSE_PAREN
            i   i
   u   fitsu   Base must be 10Ni   i   u   **u   ^i   i    i   i   (   u   **u   ^(   RZ   R9   R   (   RU   (   R   (    s;   lib/python2.7/site-packages/astropy/units/format/generic.pyt   p_factor_fits  s    c         S` sh   t  |  ƒ d k r# |  d |  d <nA t  |  ƒ d k rN |  d |  d |  d <n |  d |  d |  d <d S(   uÄ   
            product_of_units : unit_expression product product_of_units
                             | unit_expression product_of_units
                             | unit_expression
            i   i   i    i   N(   R   (   RU   (    (    s;   lib/python2.7/site-packages/astropy/units/format/generic.pyt   p_product_of_units"  s
    c         S` s5   t  |  ƒ d k r# |  d |  d <n |  d |  d <d S(   u¨   
            unit_expression : function
                            | unit_with_power
                            | OPEN_PAREN product_of_units CLOSE_PAREN
            i   i   i    N(   R   (   RU   (    (    s;   lib/python2.7/site-packages/astropy/units/format/generic.pyt   p_unit_expression/  s    c         S` sh   t  |  ƒ d k r# |  d |  d <nA t  |  ƒ d k rN |  d |  d |  d <n |  d |  d |  d <d S(   u˜   
            unit_with_power : UNIT power numeric_power
                            | UNIT numeric_power
                            | UNIT
            i   i   i    i   N(   R   (   RU   (    (    s;   lib/python2.7/site-packages/astropy/units/format/generic.pyt   p_unit_with_power:  s
    c         S` sR   t  |  ƒ d k r+ |  d |  d |  d <n# t  |  ƒ d k rN |  d |  d <n  d S(   uq   
            numeric_power : sign UINT
                          | OPEN_PAREN paren_expr CLOSE_PAREN
            i   i   i   i    i   N(   R   (   RU   (    (    s;   lib/python2.7/site-packages/astropy/units/format/generic.pyt   p_numeric_powerG  s    c         S` s=   t  |  ƒ d k r+ |  d |  d |  d <n |  d |  d <d S(   ut   
            paren_expr : sign UINT
                       | signed_float
                       | frac
            i   i   i   i    N(   R   (   RU   (    (    s;   lib/python2.7/site-packages/astropy/units/format/generic.pyt   p_paren_exprQ  s    c         S` s*   |  d |  d |  d |  d |  d <d S(   u=   
            frac : sign UINT division sign UINT
            i   i   i   i   i    N(    (   RU   (    (    s;   lib/python2.7/site-packages/astropy/units/format/generic.pyt   p_frac\  s    c         S` s1   t  |  ƒ d k r# |  d |  d <n
 d |  d <d S(   u8   
            sign : SIGN
                 |
            i   i   i    g      ð?N(   R   (   RU   (    (    s;   lib/python2.7/site-packages/astropy/units/format/generic.pyt   p_signb  s    c         S` s   d S(   uE   
            product : STAR
                    | PERIOD
            N(    (   RU   (    (    s;   lib/python2.7/site-packages/astropy/units/format/generic.pyt	   p_productl  s    c         S` s   d S(   u,   
            division : SOLIDUS
            N(    (   RU   (    (    s;   lib/python2.7/site-packages/astropy/units/format/generic.pyt
   p_divisions  s    c         S` s   |  d |  d <d S(   uG   
            power : DOUBLE_STAR
                  | CARET
            i   i    N(    (   RU   (    (    s;   lib/python2.7/site-packages/astropy/units/format/generic.pyt   p_powery  s    c         S` s   |  d |  d |  d <d S(   u0   
            signed_int : SIGN UINT
            i   i   i    N(    (   RU   (    (    s;   lib/python2.7/site-packages/astropy/units/format/generic.pyt   p_signed_int€  s    c         S` s   |  d |  d |  d <d S(   uY   
            signed_float : sign UINT
                         | sign UFLOAT
            i   i   i    N(    (   RU   (    (    s;   lib/python2.7/site-packages/astropy/units/format/generic.pyt   p_signed_float†  s    c         S` s   |  d |  d <d S(   u2   
            function_name : FUNCNAME
            i   i    N(    (   RU   (    (    s;   lib/python2.7/site-packages/astropy/units/format/generic.pyt   p_function_name  s    c         ` s   |  d d k r& |  d d |  d <d S|  d d k rp ˆ  j  |  d ƒ } t | ƒ rp | |  d ƒ |  d <d Sn  t d
 j |  d ƒ ƒ ‚ d S(   uN   
            function : function_name OPEN_PAREN main CLOSE_PAREN
            i   u   sqrti   g      à?i    Nu   magu   dBu   dexu"   '{0}' is not a recognized function(   u   magu   dBu   dex(   t   _parse_unitt   callableR9   R   (   RU   t   function_unit(   R   (    s;   lib/python2.7/site-packages/astropy/units/format/generic.pyt
   p_function“  s    c         S` s   t  ƒ  ‚ d  S(   N(   R9   (   RU   (    (    s;   lib/python2.7/site-packages/astropy/units/format/generic.pyt   p_error¤  s    t   debugt	   tabmoduleu   generic_parsetabR>   (	   R@   RS   RA   t   FalseRC   RD   RE   RF   RG   (   R   RS   RI   RV   RW   RX   RY   R[   R\   R]   R^   R_   R`   Ra   Rb   Rc   Rd   Re   Rf   Rg   Rh   Ri   Rj   Rn   Ro   t   parser(    (   R   s;   lib/python2.7/site-packages/astropy/units/format/generic.pyR&   §   s6    									
			
							c         C` sR   y |  j  | j ƒ SWn7 t k
 rM } t d j | j t j | ƒ ƒ ƒ ‚ n Xd  S(   Nu   At col {0}, {1}(   Rk   R-   R9   R   R:   R   t	   text_type(   R   R2   t   e(    (    s;   lib/python2.7/site-packages/astropy/units/format/generic.pyR7   ­  s    c         C` sn   t  j ƒ  j } | d k r# | d S| | k r7 | | S| ra t d j | t | | ƒ ƒ ƒ ‚ n	 t ƒ  ‚ d  S(   Nu   %u   percentu   {0} is not a valid unit. {1}(   R   t   get_current_unit_registryt   registryR9   R   R	   (   R   t   st   detailed_exceptionRw   (    (    s;   lib/python2.7/site-packages/astropy/units/format/generic.pyRk   ¶  s    c         C` sq   t  | t j ƒ s$ | j d ƒ } n  |  j | d | ƒ} | j d ƒ d k rm t j d j | ƒ t	 j
 ƒ n  | S(   Nu   asciiRp   u   /i   uJ   '{0}' contains multiple slashes, which is discouraged by the FITS standard(   R
   R   Rt   t   decodet	   _do_parset   countt   warningst   warnR   R   t   UnitsWarning(   R   Rx   Rp   t   result(    (    s;   lib/python2.7/site-packages/astropy/units/format/generic.pyt   parseÅ  s    c         C` s”   y |  j  | d t ƒSWnv t k
 r } y# |  j j | d |  j d | ƒSWq t k
 r‹ } t j | ƒ rs ‚  qŒ t d j | ƒ ƒ ‚ q Xn Xd  S(   NRy   RR   Rp   u   Syntax error parsing unit '{0}'(	   Rk   Rr   R9   R'   R   R)   R   Rt   R   (   R   Rx   Rp   Ru   (    (    s;   lib/python2.7/site-packages/astropy/units/format/generic.pyR{   Ò  s    #c         C` s   | j  d ƒ S(   Nu   generic(   t   get_format_name(   R   R   (    (    s;   lib/python2.7/site-packages/astropy/units/format/generic.pyR   â  s    c         ` sÊ   g  } | j  d ‡  f d †  ƒ x› | D]“ \ } } | d k rW | j ˆ  j | ƒ ƒ q& t j | ƒ } d | k r— | j d j ˆ  j | ƒ | ƒ ƒ q& | j d j ˆ  j | ƒ | ƒ ƒ q& Wd j | ƒ S(   Nt   keyc         ` s   ˆ  j  |  d ƒ j ƒ  S(   Ni    (   R   t   lower(   t   x(   R   (    s;   lib/python2.7/site-packages/astropy/units/format/generic.pyt   <lambda>é  s    i   u   /u   {0}({1})u   {0}{1}u    (   t   sortR   R   R   t   format_powerR   R   (   R   t   unitst   outt   baset   power(    (   R   s;   lib/python2.7/site-packages/astropy/units/format/generic.pyR   æ  s    c         C` s   t  |  | ƒ S(   N(   R   (   R   R   (    (    s;   lib/python2.7/site-packages/astropy/units/format/generic.pyt	   to_stringø  s    (   t   __name__t
   __module__t   __doc__RB   R   RA   R   R"   R#   R$   R%   R'   R)   t   classmethodR(   R&   R7   Rk   Rr   R   R{   R   R   R   (    (    (    s;   lib/python2.7/site-packages/astropy/units/format/generic.pyR   6   sB   	?ÿ 	t   Unscaledc           B` s   e  Z d  Z e Z RS(   uÉ   
    A format that doesn't display the scale part of the unit, other
    than that, it is identical to the `Generic` format.

    This is used in some error messages where the scale is irrelevant.
    (   RŽ   R   R   Rr   R   (    (    (    s;   lib/python2.7/site-packages/astropy/units/format/generic.pyR’   ý  s   (   R   t
   __future__R    R   R   R   t   externR   RD   R+   R}   t    R   R   R‹   R   R   t
   utils.miscR	   R   R   R’   (    (    (    s;   lib/python2.7/site-packages/astropy/units/format/generic.pyt   <module>	   s   "	ÿ È