ó
šßÈ[c           @   sY  d  d l  Z  d  d l Z d  d l Z d d l m Z m Z m Z m Z m	 Z	 d d l
 m Z m Z m Z m Z d d l m Z d d l m Z m Z m Z m Z d d l m Z d	 d
 g Z e d d ƒ Z e d d ƒ Z d Z d e Z d Z d Z d Z d
 e  f d „  ƒ  YZ! e! ƒ  Z" d	 e f d „  ƒ  YZ# d „  Z$ d „  Z% d „  Z& d „  Z' d S(   iÿÿÿÿNi   (   t   _str_to_numt   _is_intt	   maketranst	   translatet   _words_group(   t   _Verifyt   _ErrListt   VerifyErrort   VerifyWarning(   t   confi   (   t   string_typest   integer_typest	   text_typet   binary_type(   t   AstropyUserWarningt   Cardt	   Undefinedt   det   DEt   dDt   eEiP   t    i   s   = t   =c           B   s   e  Z d  Z d „  Z RS(   s   Undefined value.c         C   s   d  S(   N(    (   t   self(    (    s3   lib/python2.7/site-packages/astropy/io/fits/card.pyt   __init__"   s    (   t   __name__t
   __module__t   __doc__R   (    (    (    s3   lib/python2.7/site-packages/astropy/io/fits/card.pyR      s   c           B   sv  e  Z e Z e j d  e ƒ Z e j d e j ƒ Z	 d Z
 d Z d e
 Z d e Z e j d j e
 ƒ ƒ Z e j d j e ƒ ƒ Z e j d ƒ Z e j d	 e d
 e d e d ƒ Z e j d e d
 e d e d ƒ Z d Z e d Z d j e e ƒ Z d j e e ƒ Z d j e ƒ Z d j e ƒ Z e j e d ƒ Z e j d j e e ƒ ƒ Z e j e ƒ Z e d d d d g ƒ Z e Z  dC dC dC d „ Z" d „  Z# d „  Z$ d „  Z% d „  Z& e' d  „  ƒ Z( e( j) d! „  ƒ Z( e' d" „  ƒ Z* e* j) d# „  ƒ Z* e* j+ d$ „  ƒ Z* e' d% „  ƒ Z, e' d& „  ƒ Z- e' d' „  ƒ Z. e. j) d( „  ƒ Z. e. j+ d) „  ƒ Z. e' d* „  ƒ Z/ e/ j) d+ „  ƒ Z/ e/ j+ d, „  ƒ Z/ e' d- „  ƒ Z0 e' d. „  ƒ Z1 e2 d/ „  ƒ Z3 e2 d0 „  ƒ Z4 d1 „  Z5 d2 „  Z6 d3 „  Z7 d4 „  Z8 d5 „  Z9 d6 „  Z: d7 „  Z; d8 „  Z< d9 „  Z= d: „  Z> d; „  Z? d< „  Z@ d= „  ZA d> „  ZB d? „  ZC d@ dA „ ZD dB „  ZE RS(D   s   ^[A-Z0-9_-]{0,%d}$s"   ^(?:HIERARCH +)?(?:^[ -<>-~]+ ?)+$s"   (\.\d+|\d+(\.\d*)?)([DE][+-]?\d+)?s*   (\.\d+|\d+(\.\d*)?) *([deDE] *[+-]? *\d+)?s   [+-]?s   [+-]? *s   (?P<sign>[+-])?0*?(?P<digt>{})s    (?P<sign>[+-])? *0*?(?P<digt>{})s   [ -~]*\Zs\   (?P<valu_field> *(?P<valu>\'(?P<strg>([ -~]+?|\'\'|)) *?\'(?=$|/| )|(?P<bool>[FT])|(?P<numr>s   )|(?P<cplx>\( *(?P<real>s   ) *, *(?P<imag>s@   ) *\)))? *)(?P<comm_field>(?P<sepr>/ *)(?P<comm>[!-~][ -~]*)?)?$s\   (?P<valu_field> *(?P<valu>\'(?P<strg>([ -~]+?|\'\'|) *?)\'(?=$|/| )|(?P<bool>[FT])|(?P<numr>s;   ) *\)))? *)(?P<comm_field>(?P<sepr>/ *)(?P<comm>(.|\n)*))?$s   [a-zA-Z_]\w*s   (\.\d+)?s	   {}(\.{})*s   (?P<keyword>{}): (?P<val>{})s   \'(?P<rawval>{})\'s    *{} *(/ *(?P<comm>[ -~]*))?$t   $s)   (?P<keyword>{})\.(?P<field_specifier>{})$t    t   COMMENTt   HISTORYt   ENDc         K   s  | d  k r% d | k r% | d } n  d  |  _ d  |  _ d  |  _ d  |  _ t |  _ t |  _ t |  _	 d  |  _
 d  |  _ d  |  _ | d  k	 o¦ | d  k	 o¦ |  j | | ƒ sÜ | d  k	 rÁ | |  _ n  | d  k	 rÜ | |  _ qÜ n  | d  k	 rô | |  _ n  t |  _ d  |  _ t |  _ d  S(   Nt   key(   t   Nonet   _keywordt   _valuet   _commentt   _imaget   Truet	   _verifiedt   Falset	   _hierarcht   _invalidt   _field_specifiert   _rawkeywordt	   _rawvaluet   _check_if_rvkct   keywordt   valuet   commentt	   _modifiedt   _valuestringt   _valuemodified(   R   R0   R1   R2   t   kwargs(    (    s3   lib/python2.7/site-packages/astropy/io/fits/card.pyR   ›   s.    												c         C   s   t  |  j |  j |  j f ƒ S(   N(   t   reprR0   R1   R2   (   R   (    (    s3   lib/python2.7/site-packages/astropy/io/fits/card.pyt   __repr__É   s    c         C   s   |  j  S(   N(   t   image(   R   (    (    s3   lib/python2.7/site-packages/astropy/io/fits/card.pyt   __str__Ì   s    c         C   s   d S(   Ni   (    (   R   (    (    s3   lib/python2.7/site-packages/astropy/io/fits/card.pyt   __len__Ï   s    c         C   s   |  j  |  j |  j f | S(   N(   R0   R1   R2   (   R   t   index(    (    s3   lib/python2.7/site-packages/astropy/io/fits/card.pyt   __getitem__Ò   s    c         C   sF   |  j  d k	 r |  j  S|  j r5 |  j ƒ  |  _  |  j  Sd |  _ d Sd S(   s4   Returns the keyword name parsed from the card image.R   N(   R#   R"   R&   t   _parse_keywordR0   (   R   (    (    s3   lib/python2.7/site-packages/astropy/io/fits/card.pyR0   Õ   s    		c         C   s3  |  j  d	 k	 r t d ƒ ‚ nt | t ƒ r| j ƒ  } | j ƒ  } t | ƒ t k r |  j	 j
 | ƒ r | d k r„ t d ƒ ‚ n  | } nx |  j j
 | ƒ rð t |  _ t |  _ | d  d k rÔ | d j ƒ  } qt j d j | ƒ t ƒ n t d j | ƒ ƒ ‚ | |  _  t |  _ n t d j | ƒ ƒ ‚ d	 S(
   s6   Set the key attribute; once set it cannot be modified.s.   Once set, the Card keyword may not be modifiedR    s   Keyword 'END' not allowed.i	   s	   HIERARCH sˆ   Keyword name {!r} is greater than 8 characters or contains characters not allowed by the FITS standard; a HIERARCH card will be created.s   Illegal keyword name: {!r}.s"   Keyword name {!r} is not a string.N(   R#   R"   t   AttributeErrort
   isinstanceR
   t   rstript   uppert   lent   KEYWORD_LENGTHt   _keywd_FSC_REt   matcht
   ValueErrort   _keywd_hierarch_RER'   R*   t   HIERARCH_VALUE_INDICATORt   _value_indicatort   stript   warningst   warnt   formatR   R3   (   R   R0   t   keyword_upper(    (    s3   lib/python2.7/site-packages/astropy/io/fits/card.pyR0   á   s.    					c         C   sœ   |  j  r t |  j ƒ S|  j d k	 r1 |  j } n@ |  j d k	 sI |  j rd |  j ƒ  |  _ |  j } n d |  _ } t j r˜ t	 | t
 ƒ r˜ | j ƒ  } n  | S(   s:   The value associated with the keyword stored in this card.R   N(   t   field_specifiert   floatR$   R"   R4   R&   t   _parse_valueR	   t   strip_header_whitespaceR@   R
   RA   (   R   R1   (    (    s3   lib/python2.7/site-packages/astropy/io/fits/card.pyR1     s    	c         C   sà  |  j  r t d ƒ ‚ n  | d  k r- d } n  |  j } | d  k rK d } n  t | t t t t t	 t
 t j t j t j t j f ƒ sž t d j | ƒ ƒ ‚ n  t | t ƒ rã t j | ƒ sË t j | ƒ rã t d j | ƒ ƒ ‚ nä t | t ƒ r%|  j j | ƒ } | sÇt d j | ƒ ƒ ‚ qÇn¢ t | t ƒ r¦t } y | j d ƒ } Wn t k
 rft } n X|  j j | ƒ } | d  k	 } | sÇt d j | ƒ ƒ ‚ qÇn! t | t j ƒ rÇt	 | ƒ } n  t j r	t | t ƒ r	t | t ƒ r	| j ƒ  | j ƒ  k } nO t | t	 ƒ s't | t	 ƒ r6| | k	 } n" | | k pUt | t | ƒ ƒ } | rÜ| |  _ d  |  _ t |  _  d  |  _! t |  _" |  j# rÜy t$ |  j ƒ |  _ WqÙt k
 rÕt d j |  j ƒ ƒ ‚ qÙXqÜn  d  S(	   Nsj   The value of invalid/unparseable cards cannot set.  Either delete this card from the header or replace it.R   s   Illegal value: {!r}.s;   Floating point {!r} values are not allowed in FITS headers.s•   FITS header values must contain standard printable ASCII characters; {!r} contains characters not representable in ASCII or non-printable characters.t   asciis˜   FITS header values must contain standard printable ASCII characters; {!r} contains characters/bytes that do not represent printable characters in ASCII.s   value {} is not a float(%   R+   RG   R"   R$   R@   R
   R   RQ   t   complext   boolR   t   npt   floatingt   integert   complexfloatingt   bool_RN   t   isnant   isinfR   t   _ascii_text_reRF   R   R'   t   decodet   UnicodeDecodeErrorR)   R	   RS   RA   t   typeR.   R3   R4   R5   RP   t   _int_or_float(   R   R1   t   oldvaluet   mt   validt
   text_valuet	   different(    (    s3   lib/python2.7/site-packages/astropy/io/fits/card.pyR1   '  sn    				-	
								c         C   s=   |  j  r t d ƒ ‚ n  |  j s- d |  _ n t d ƒ ‚ d  S(   Nsn   The value of invalid/unparseable cards cannot deleted.  Either delete this card from the header or replace it.R   s9   Values cannot be deleted from record-valued keyword cards(   R+   RG   RP   R1   R?   (   R   (    (    s3   lib/python2.7/site-packages/astropy/io/fits/card.pyR1   t  s    		c         C   sS   |  j  d k	 r |  j  S|  j d k	 rH |  j j d d ƒ d |  _  |  j  S|  j Sd S(   s½   On record-valued keyword cards this is the name of the standard <= 8
        character FITS keyword that this RVKC is stored in.  Otherwise it is
        the card's normal keyword.
        t   .i   i    N(   R-   R"   RP   R0   t   split(   R   (    (    s3   lib/python2.7/site-packages/astropy/io/fits/card.pyt
   rawkeyword  s    c         C   sR   |  j  d k	 r |  j  S|  j d k	 rG d j |  j |  j ƒ |  _  |  j  S|  j Sd S(   sÜ   On record-valued keyword cards this is the raw string value in
        the ``<field-specifier>: <value>`` format stored in the card in order
        to represent a RVKC.  Otherwise it is the card's normal value.
        s   {}: {}N(   R.   R"   RP   RN   R1   (   R   (    (    s3   lib/python2.7/site-packages/astropy/io/fits/card.pyt   rawvalue  s    c         C   sF   |  j  d k	 r |  j  S|  j r5 |  j ƒ  |  _  |  j  Sd |  _ d Sd S(   sA   Get the comment attribute from the card image if not already set.R   N(   R%   R"   R&   t   _parse_commentR2   (   R   (    (    s3   lib/python2.7/site-packages/astropy/io/fits/card.pyR2   Ÿ  s    		c         C   s²   |  j  r t d ƒ ‚ n  | d  k r- d } n  t | t ƒ ro |  j j | ƒ } | so t d j | ƒ ƒ ‚ qo n  |  j } | d  k r d } n  | | k r® | |  _ t	 |  _
 n  d  S(   Nsl   The comment of invalid/unparseable cards cannot set.  Either delete this card from the header or replace it.R   s—   FITS header comments must contain standard printable ASCII characters; {!r} contains characters not representable in ASCII or non-printable characters.(   R+   RG   R"   R@   R   R^   RF   RN   R%   R'   R3   (   R   R2   Rd   t
   oldcomment(    (    s3   lib/python2.7/site-packages/astropy/io/fits/card.pyR2   ¬  s"    					c         C   s%   |  j  r t d ƒ ‚ n  d |  _ d  S(   Nsp   The comment of invalid/unparseable cards cannot deleted.  Either delete this card from the header or replace it.R   (   R+   RG   R2   (   R   (    (    s3   lib/python2.7/site-packages/astropy/io/fits/card.pyR2   Æ  s    	c         C   s   |  j  r |  j Sd Sd S(   sl   
        The field-specifier of record-valued keyword cards; always `None` on
        normal cards.
        N(   R0   R,   R"   (   R   (    (    s3   lib/python2.7/site-packages/astropy/io/fits/card.pyRP   Ï  s    		c         C   s†   | s t  d ƒ ‚ nm |  j s- t d ƒ ‚ nU | |  j k r‚ | |  _ |  j j d d ƒ d } d j | | g ƒ |  _ t |  _ n  d  S(   NsD   The field-specifier may not be blank in record-valued keyword cards.s^   Cannot coerce cards to be record-valued keyword cards by setting the field_specifier attributeRh   i   i    (	   RG   RP   R?   R,   R#   Ri   t   joinR'   R3   (   R   RP   R0   (    (    s3   lib/python2.7/site-packages/astropy/io/fits/card.pyRP   Ý  s    		c         C   s   t  d ƒ ‚ d  S(   NsR   The field_specifier attribute may not be deleted from record-valued keyword cards.(   R?   (   R   (    (    s3   lib/python2.7/site-packages/astropy/io/fits/card.pyRP   í  s    c         C   sT   |  j  r# |  j r# |  j d ƒ n  |  j  d k s; |  j rM |  j ƒ  |  _  n  |  j  S(   s…   
        The card "image", that is, the 80 byte character string that represents
        this card in an actual FITS header.
        s   fix+warnN(   R&   R(   t   verifyR"   R3   t   _format_image(   R   (    (    s3   lib/python2.7/site-packages/astropy/io/fits/card.pyR9   ò  s
    c         C   sD   |  j  s |  j t k S|  j oC t |  j t ƒ oC |  j oC |  j S(   s¼   
        `True` if the card is completely blank--that is, it has no keyword,
        value, or comment.  It appears in the header as 80 spaces.

        Returns `False` otherwise.
        (   R(   R&   t
   BLANK_CARDR0   R@   R1   R
   R2   (   R   (    (    s3   lib/python2.7/site-packages/astropy/io/fits/card.pyt   is_blankÿ  s
    		
c         C   s%   |  ƒ  } t  | ƒ | _ t | _ | S(   sü   
        Construct a `Card` object from a (raw) string. It will pad the string
        if it is not the length of a card image (80 columns).  If the card
        image is longer than 80 columns, assume it contains ``CONTINUE``
        card(s).
        (   t   _padR&   R)   R(   (   t   clsR9   t   card(    (    s3   lib/python2.7/site-packages/astropy/io/fits/card.pyt
   fromstring  s    			c         C   sÁ   t  | ƒ t k r( |  j j | ƒ r( | S|  j j | ƒ } | rq d j | j d ƒ j ƒ  j ƒ  | j d ƒ f ƒ St  | ƒ d k r­ | d  j ƒ  d k r­ | d j ƒ  j ƒ  S| j ƒ  j ƒ  Sd S(   s_  
        `classmethod` to convert a keyword value that may contain a
        field-specifier to uppercase.  The effect is to raise the key to
        uppercase and leave the field specifier in its original case.

        Parameters
        ----------
        keyword : or str
            A keyword value or a ``keyword.field-specifier`` value
        Rh   R0   RP   i	   s	   HIERARCH N(	   RC   RD   RE   RF   t   _rvkc_keyword_name_RERn   t   groupRK   RB   (   Rt   R0   RF   (    (    s3   lib/python2.7/site-packages/astropy/io/fits/card.pyt   normalize_keyword"  s    (c         G   sP  t  j s t St | ƒ d k r/ |  j | Œ  nt | ƒ d k rL| \ } } t | t ƒ s` t S| |  j k rs t S|  j j	 | ƒ } | rÌ t | t
 t f ƒ rÌ |  j | j d ƒ | j d ƒ d | ƒ t St | t ƒ rL| j d ƒ d k rL|  j j	 | ƒ } | rI|  j j	 | ƒ rI|  j | | j d ƒ | | j d ƒ ƒ t SqLn  d S(	   s!  
        Determine whether or not the card is a record-valued keyword card.

        If one argument is given, that argument is treated as a full card image
        and parsed as such.  If two arguments are given, the first is treated
        as the card keyword (including the field-specifier if the card is
        intended as a RVKC), and the second as the card value OR the first value
        can be the base keyword, and the second value the 'field-specifier:
        value' string.

        If the check passes the ._keyword, ._value, and .field_specifier
        keywords are set.

        Examples
        --------

        ::

            self._check_if_rvkc('DP1', 'AXIS.1: 2')
            self._check_if_rvkc('DP1.AXIS.1', 2)
            self._check_if_rvkc('DP1     = AXIS.1: 2')
        i   i   R0   RP   s   : i    t   valN(   R	   t"   enable_record_valued_keyword_cardsR)   RC   t   _check_if_rvkc_imageR@   R
   t   _commentary_keywordsRw   RF   t   intRQ   t
   _init_rvkcRx   R"   R'   t   findt   _rvkc_field_specifier_val_RERE   (   R   t   argsR0   R1   RF   (    (    s3   lib/python2.7/site-packages/astropy/io/fits/card.pyR/   D  s*    	$c         G   s  t  | ƒ d k rh | d } | j t ƒ } | d k  sC | d k rG t S| |  } | | t  t ƒ } n | \ } } | j ƒ  } | s¬ | d d k s¬ | j d ƒ d k  r° t S|  j j | ƒ } | rý |  j | | j d ƒ | j d ƒ | j d	 ƒ ƒ t	 Sd
 S(   s(  
        Implements `Card._check_if_rvkc` for the case of an unparsed card
        image.  If given one argument this is the full intact image.  If given
        two arguments the card has already been split between keyword and
        value+comment at the standard value indicator '= '.
        i   i    i	   t   's   : i   R0   t   rawvalRz   N(
   RC   R€   t   VALUE_INDICATORR)   t   lstript   _rvkc_keyword_val_comm_RERF   R   Rx   R'   (   R   R‚   R9   t   eq_idxR0   t   restRF   (    (    s3   lib/python2.7/site-packages/astropy/io/fits/card.pyR|   v  s     

,c         C   sR   | j  ƒ  } d j | | f ƒ |  _ | |  _ | |  _ t | ƒ |  _ | |  _ d S(   s   
        Sort of addendum to Card.__init__ to set the appropriate internal
        attributes if the card was determined to be a RVKC.
        Rh   N(   RB   Rn   R#   R-   R,   Rb   R$   R.   (   R   R0   RP   t   fieldR1   RO   (    (    s3   lib/python2.7/site-packages/astropy/io/fits/card.pyR   —  s    		c         C   sY  |  j  t  j ƒ  } | j ƒ  } |  j  j t ƒ } |  j } d | k oQ t k n sn | | k sn | d k rÅ | d k rÁ | |  } |  j  | t t ƒ } |  j | | ƒ r´ |  j	 S| |  } n  | S| d k r,|  j  d d k r,t
 |  j  k r,t |  _ t
 |  _ |  j  j t
 d ƒ d d } | j ƒ  St j d j |  j  ƒ t ƒ t |  _ | Sd  S(	   Ni    t   CONTINUEt   HIERARCHi   R   i   i	   s^   The following header keyword is invalid or follows an unrecognized non-standard convention:
{}(   R&   RD   RK   RB   R€   R…   R}   RC   R|   R#   RI   R'   R*   RJ   Ri   RL   RM   RN   R   R+   (   R   R0   RO   t   val_ind_idxt   specialR‰   (    (    s3   lib/python2.7/site-packages/astropy/io/fits/card.pyR>   ¤  s.    	(
		
	c         C   sF  |  j  j ƒ  |  j k s! |  j r2 |  j t j ƒ  S|  j |  j ƒ rK |  j St	 |  j ƒ |  j
 k rç g  } x_ |  j ƒ  D]Q } | j j ƒ  j d d ƒ } | rº | d d k rº | d  } n  | j | ƒ qv Wd j | ƒ } | |  _ | S|  j j |  j ƒ  d ƒ } | d k r*t d j |  j  ƒ ƒ ‚ n  | j d ƒ d k	 rW| j d ƒ d	 k } nÍ| j d
 ƒ d k	 rt j d d | j d
 ƒ ƒ } n—| j d ƒ d k	 r|  j j | j d ƒ ƒ } t | j d ƒ t d ƒ } | j d ƒ d k röd } n | j d ƒ } t | | ƒ } n| j d ƒ d k	 r|  j j | j d ƒ ƒ } t | j d ƒ t d ƒ }	 | j d ƒ d k rd }
 n | j d ƒ }
 t |
 |	 ƒ } |  j j | j d ƒ ƒ } t | j d ƒ t d ƒ } | j d ƒ d k rôd } n | j d ƒ } | t | | ƒ d 7} n t } |  j sB| j d ƒ |  _ n  | S(   s.   Extract the keyword value from the card image.s   ''Rƒ   iÿÿÿÿt   &R   i   s7   Unparsable card ({}), fix it first with .verify('fix').RV   t   Tt   strgt   numrt   digtR   t   signt   cplxt   realt   imagy              ð?t   valuN(   R0   RB   R}   R+   R&   RD   RA   R/   R$   RC   t   lengtht   _itersubcardsR1   t   replacet   appendRn   R4   t   _value_NFSC_RERF   t   _splitR"   R   RN   Rx   t   ret   subt   _number_NFSC_RER   t   FIX_FP_TABLE2R    t	   UNDEFINED(   R   t   valuesRu   R1   Rd   R’   R“   R”   R–   t   rdigtt   rsignR—   t   idigtt   isign(    (    s3   lib/python2.7/site-packages/astropy/io/fits/card.pyRR   Ì  s\    !		!				c         C   sì   |  j  t j k s |  j r d St |  j ƒ |  j k rž g  } x0 |  j ƒ  D]" } | j rJ | j	 | j ƒ qJ qJ Wd d j
 | ƒ j ƒ  } |  j j | ƒ } n |  j j |  j ƒ  d ƒ } | d k	 rè | j d ƒ } | rè | j ƒ  Sn  d S(   s.   Extract the keyword value from the card image.R   s   / R   i   t   commN(   R0   R   R}   R+   RC   R&   R™   Rš   R2   Rœ   Rn   RA   R   RF   Rž   R"   Rx   (   R   t   commentsRu   R2   Rd   (    (    s3   lib/python2.7/site-packages/astropy/io/fits/card.pyRl     s    	c         C   s  |  j  d k	 r |  j  } n	 |  j } |  j |  j j d g ƒ k r] | j d d ƒ \ } } n¡ y | j |  j ƒ } Wn t	 k
 rŒ d } n X| d k r° | t
  } | t
 } nN | d k rã | d  d k rã | d  } | d } n | j |  j d ƒ \ } } | j ƒ  | j ƒ  f S(	   sT   
        Split the card image between the keyword and the rest of the card.
        R‹   R   i   i
   i	   s	   HIERARCH i   N(   R&   R"   R9   R0   R}   t   unionRi   R<   RJ   RG   RD   RK   (   R   R9   R0   t   valuecommentt   delim_index(    (    s3   lib/python2.7/site-packages/astropy/io/fits/card.pyRž   '  s"    	


c         C   sd   |  j  rE |  j j d d ƒ \ } } d j | j ƒ  | g ƒ |  _ n |  j j ƒ  |  _ t |  _ d  S(   NRh   i   (   RP   R#   Ri   Rn   RB   R'   R3   (   R   R0   RP   (    (    s3   lib/python2.7/site-packages/astropy/io/fits/card.pyt   _fix_keywordG  s
    	!c         C   s  d } |  j ƒ  \ } } |  j j | ƒ } | d k r£ y: | j d d ƒ \ } } | j ƒ  |  _ | j ƒ  |  _ Wn  t t	 f k
 r’ | |  _ n X|  j
 |  _ d S| j d ƒ d k	 r|  j j | j d ƒ ƒ } t | j d ƒ t d ƒ } | j d ƒ d k	 r| j d ƒ | } qnì | j d ƒ d k	 r|  j j | j d	 ƒ ƒ } t | j d ƒ t d ƒ } | j d ƒ d k	 r’| j d ƒ | } n  |  j j | j d
 ƒ ƒ }	 t |	 j d ƒ t d ƒ }
 |	 j d ƒ d k	 ró|	 j d ƒ |
 }
 n  d j | |
 ƒ } n  | |  _ t |  _ d S(   s7   Fix the card image for fixable non-standard compliance.t   /i   NR’   R“   R   R”   R•   R–   R—   s   ({}, {})(   R"   Rž   R   RF   Ri   RK   R1   R2   RG   t
   IndexErrorR$   R4   Rx   R¡   R   t   FIX_FP_TABLERN   R'   R3   (   R   R1   R0   R¬   Rd   R2   R’   R–   R¥   R—   R§   (    (    s3   lib/python2.7/site-packages/astropy/io/fits/card.pyt
   _fix_valueO  s:    	c         C   sv   |  j  rj |  j r8 d j |  j  j d d ƒ d d t ƒS|  j rQ d j |  j  ƒ Sd j |  j  d t ƒSn d t Sd  S(   Ns   {:{len}}Rh   i   i    RC   s   HIERARCH {} R   (   R0   RP   RN   Ri   RD   R*   (   R   (    (    s3   lib/python2.7/site-packages/astropy/io/fits/card.pyt   _format_keywordw  s    			c         C   sù   t  t j t t j f } |  j } |  j } |  j |  j k rK t	 | ƒ } n| |  j
 r… |  j r… t |  j | ƒ r… d j |  j
 ƒ } nB |  j r» t |  j ƒ j ƒ  } d j |  j | ƒ } n t | ƒ } |  j rõ t |  j ƒ t k rõ | j ƒ  } n  | S(   Ns   {:>20}s   '{}: {}'(   RQ   RW   RX   RU   RZ   R1   R$   R0   R}   t   strR4   R5   R@   RN   RP   t   _format_valueRK   RC   RD   (   R   t   float_typesR1   (    (    s3   lib/python2.7/site-packages/astropy/io/fits/card.pyRµ   ƒ  s    			c         C   s!   |  j  s d Sd j |  j ƒ Sd  S(   NR   s    / {}(   R2   RN   R%   (   R   (    (    s3   lib/python2.7/site-packages/astropy/io/fits/card.pyt   _format_comment¡  s    	c         C   s˜  |  j  ƒ  } |  j ƒ  } | j ƒ  |  j k } | r< d } n |  j ƒ  } t } | r] d } n  d j | | | | g ƒ } t | ƒ t | ƒ t | ƒ } | |  j k r| j	 d ƒ r| |  j d k rû | d d k rû d j | d  | | | g ƒ } qt
 d j |  j ƒ ƒ ‚ n  t | ƒ |  j k r=d j | ƒ } nW t |  j t ƒ rwt | ƒ |  j d k rw|  j ƒ  } n t j d	 t ƒ | t j  } | S(
   NR   RŒ   i   iÿÿÿÿR   s2   The header keyword {!r} with its value is too longs   {:80}i
   s,   Card is too long, comment will be truncated.(   R³   Rµ   RK   R}   R·   R…   Rn   RC   R™   t
   startswithRG   RN   R0   R@   R1   R
   t   _format_long_imageRL   RM   R   R   (   R   R0   R1   t   is_commentaryR2   t	   delimitert   outputt   keywordvalue_length(    (    s3   lib/python2.7/site-packages/astropy/io/fits/card.pyRp   §  s4    		 #"		c         C   s  |  j  t j k r |  j ƒ  Sd } d } g  } |  j j d d ƒ } t | | ƒ } xŸ t | ƒ D]‘ \ } } | d k r’ d j |  j  d t	 ƒ} n d } |  j
 rÁ | t | ƒ d	 k rÁ d
 }	 n d }	 |	 j | ƒ } | j d j | | ƒ ƒ q_ Wd }
 |  j
 rƒt |  j
 | ƒ } xk t | ƒ D]Z \ } } | t | ƒ d	 k rMd } n d } | |
 j | ƒ } | j d j | ƒ ƒ q"Wn  d j | ƒ S(   s5  
        Break up long string value/comment into ``CONTINUE`` cards.
        This is a primitive implementation: it will put the value
        string in one block and the comment string in another.  Also,
        it does not break at the blank space between words.  So it may
        not look pretty.
        iC   i@   Rƒ   s   ''i    s
   {:{len}}= RC   s
   CONTINUE  i   s   '{}'s   '{}&'s   {:80}s   {}s   CONTINUE  '' / s   CONTINUE  '&' / R   (   R0   R   R}   t   _format_long_commentary_imageR$   R›   R   t	   enumerateRN   RD   R2   RC   Rœ   Rn   (   R   t   value_lengtht   comment_lengthR¼   R1   t   wordst   idxt   wordt   headstrt   value_formatt   comment_formatR2   (    (    s3   lib/python2.7/site-packages/astropy/io/fits/card.pyR¹   Ø  s4    	
 			c         C   s   t  j t } |  j ƒ  } g  } d } xJ | t | ƒ k  rq | j t t  |  j | | | | !ƒ ƒ ƒ | | 7} q( Wd j | ƒ S(   s·   
        If a commentary card's value is too long to fit on a single card, this
        will render the card as multiple consecutive commentary card of the
        same type.
        i    R   (	   R   R™   RD   Rµ   RC   Rœ   R´   R0   Rn   (   R   t   maxlenR1   R¼   RÃ   (    (    s3   lib/python2.7/site-packages/astropy/io/fits/card.pyR¾     s    *RM   c      	   C   s÷  t  |  _ t g  ƒ } d j |  j ƒ } |  j r4 | S|  j |  j k rº |  j rº |  j d  j ƒ  d k rº |  j j	 d ƒ d k rº | j
 |  j | d d j |  j ƒ d | d	 |  j ƒƒ n  |  j rÜ |  j d  j ƒ  d
 k s¸|  j rè nÐ |  j rM|  j ƒ  d } | | j ƒ  k rM| j
 |  j | d d j | ƒ d | d	 |  j ƒƒ qMn  |  j } |  j rx| j d d ƒ d } n  |  j j | ƒ s¸| j
 |  j | d d j | ƒ d t ƒƒ n  |  j ƒ  \ } } |  j |  j k r|  j j | ƒ st| j
 |  j | d d j | ƒ d t ƒƒ qtnU |  j j | ƒ } | st| j
 |  j | d d j |  j | ƒ d | d	 |  j ƒƒ n  |  j j | ƒ } | d  k	 ró| j d ƒ } | d  k	 ró|  j j | ƒ sð| j
 |  j | d d j | ƒ d t ƒƒ qðqón  | S(   Ns*   Fixed {!r} card to meet the FITS standard.i	   s	   HIERARCH R   i   t   err_texts<   Card {!r} is not FITS standard (equal sign not at column 8).t   fix_textt   fixRŒ   i    s$   Card keyword {!r} is not upper case.Rh   i   s   Illegal keyword name {!r}t   fixablesU   Unprintable string {!r}; commentary cards may only contain printable ASCII characterss<   Card {!r} is not FITS standard (invalid value string: {!r}).R©   sT   Unprintable string {!r}; header comments may only contain printable ASCII characters(   R'   R(   R   RN   R0   R+   R}   R&   RB   R€   Rœ   t
   run_optionR²   R*   Rž   R®   RP   Ri   RE   RF   R)   R^   t   _value_FSC_RER   R"   Rx   (   R   t   optiont   errsRÊ   R0   R¬   Rd   R2   (    (    s3   lib/python2.7/site-packages/astropy/io/fits/card.pyt   _verify  s|    		""							c         c   s·   t  |  j ƒ t j } xš t d t j | t j ƒ D]| } t j |  j | | t j !ƒ } | d k r‰ | j j ƒ  d k r‰ t d ƒ ‚ n  t	 | j
 t ƒ sª t d ƒ ‚ n  | Vq3 Wd S(   sÞ   
        If the card image is greater than 80 characters, it should consist of a
        normal card followed by one or more CONTINUE card.  This method returns
        the subcards that make up this logical card.
        i    R‹   s?   Long card images must have CONTINUE cards after the first card.s'   CONTINUE cards must have string values.N(   RC   R&   R   R™   t   rangeRv   R0   RB   R   R@   R1   R´   (   R   t   ncardsRÃ   Ru   (    (    s3   lib/python2.7/site-packages/astropy/io/fits/card.pyRš   v  s    # !N(F   R   R   t   CARD_LENGTHR™   RŸ   t   compileRD   RE   t   IRH   t   _digits_FSCt   _digits_NFSCt	   _numr_FSCt
   _numr_NFSCRN   t   _number_FSC_RER¡   R^   RÎ   R   t   _rvkc_identifiert   _rvkc_fieldt   _rvkc_field_specifier_st   _rvkc_field_specifier_valt   _rvkc_keyword_valt   _rvkc_keyword_val_commR   Rw   R‡   t   setR}   R…   RJ   R"   R   R8   R:   R;   R=   t   propertyR0   t   setterR1   t   deleterRj   Rk   R2   RP   R9   Rr   t   classmethodRv   Ry   R/   R|   R   R>   RR   Rl   Rž   R®   R²   R³   Rµ   R·   Rp   R¹   R¾   RÑ   Rš   (    (    (    s3   lib/python2.7/site-packages/astropy/io/fits/card.pyR   *   sŒ   	

	!!
	.				2M	"	2	!		(	C		 		(				1	4	Zc         C   s{   t  |  t ƒ r |  Sy t |  ƒ SWnS t t f k
 rv y t |  ƒ SWqw t t f k
 rr } t t | ƒ ƒ ‚ qw Xn Xd S(   s   
    Converts an a string to an int if possible, or to a float.

    If the string is neither a string or a float a value error is raised.
    N(   R@   RQ   R~   RG   t	   TypeErrorR´   (   t   st   e(    (    s3   lib/python2.7/site-packages/astropy/io/fits/card.pyRb   Œ  s    c         C   s'  t  |  t ƒ rP |  d k r d S|  j d d ƒ } d j | ƒ } d j | ƒ SnÓ t  |  t t j f ƒ r d j t |  ƒ d ƒ St |  ƒ r˜ d j |  ƒ St  |  t	 t j
 f ƒ rÃ d j t |  ƒ ƒ St  |  t t j f ƒ rd	 j t |  j ƒ t |  j ƒ ƒ } d j | ƒ St  |  t ƒ rd Sd Sd
 S(   sk   
    Converts a card value to its appropriate string representation as
    defined by the FITS format.
    R   s   ''Rƒ   s   '{:8}'s   {:20}s   {:>20}i    s   {:>20d}s   ({}, {})N(   R@   R
   R›   RN   RV   RW   R[   R7   R   RQ   RX   t   _format_floatRU   RZ   R–   R—   R   (   R1   t   exp_val_strt   val_str(    (    s3   lib/python2.7/site-packages/astropy/io/fits/card.pyRµ      s&    c         C   s  d j  |  ƒ } d | k r4 d | k r4 | d 7} nl d | k r  | j d ƒ \ } } | d d k r| | d } | d } n d	 } d
 j  | | t | ƒ ƒ } n  t | ƒ } | d k rý | j d ƒ } | d k  rà | d  } qý | d | |  | | } n  | S(   s@   Format a floating number to make sure it gets the decimal point.s   {:.16G}Rh   t   Es   .0i    t   +t   -i   R   s   {}E{}{:02d}i   (   Rî   Rï   (   RN   Ri   R~   RC   R€   (   R1   t	   value_strt   significandt   exponentR”   t   str_lenRÃ   (    (    s3   lib/python2.7/site-packages/astropy/io/fits/card.pyRê   Å  s"    
c         C   s…   t  |  ƒ } | t j k r |  S| t j k ra | t j } | d k rK |  S|  d t j | Sn  | t j } |  d t j | Sd S(   s9   Pad blank space to the input string to be multiple of 80.i    R   N(   RC   R   R™   (   t   inputt   _lent   strlen(    (    s3   lib/python2.7/site-packages/astropy/io/fits/card.pyRs   å  s    ((   RŸ   RL   t   numpyRW   t   utilR    R   R   R   R   Ro   R   R   R   R   R   R	   t
   extern.sixR
   R   R   R   t   utils.exceptionsR   t   __all__R±   R¢   RÔ   Rq   RD   R…   RI   t   objectR   R£   R   Rb   Rµ   Rê   Rs   (    (    (    s3   lib/python2.7/site-packages/astropy/io/fits/card.pyt   <module>   s4   (""
	ÿ ÿ ÿ ÿ f		%	 