σ
ίΘ[c           @   s)   d  Z  d g Z d e f d     YZ d S(   sj   
A simple class to manage a piece of global science state.  See
:ref:`config-developer` for more details.
t   ScienceStatec           B   sD   e  Z d  Z d   Z e d    Z e d    Z e d    Z RS(   sb  
    Science state subclasses are used to manage global items that can
    affect science results.  Subclasses will generally override
    `validate` to convert from any of the acceptable inputs (such as
    strings) to the appropriate internal objects, and set an initial
    value to the ``_value`` member so it has a default.

    Examples
    --------

    ::

        class MyState(ScienceState):
            @classmethod
            def validate(cls, value):
                if value not in ('A', 'B', 'C'):
                    raise ValueError("Must be one of A, B, C")
                return value
    c         C   s   t  d   d  S(   Ns/   This class is a singleton.  Do not instantiate.(   t   RuntimeError(   t   self(    (    s2   lib/python2.7/site-packages/astropy/utils/state.pyt   __init__   s    c         C   s   |  j  |  j  S(   s6   
        Get the current science state value.
        (   t   validatet   _value(   t   cls(    (    s2   lib/python2.7/site-packages/astropy/utils/state.pyt   get#   s    c         C   sD   d t  f d     Y} | |  |  j  } |  j |  } | |  _ | S(   s6   
        Set the current science state value.
        t   _Contextc           B   s,   e  Z d    Z d   Z d   Z d   Z RS(   c         S   s   | |  _  | |  _ d  S(   N(   R   t   _parent(   R   t   parentt   value(    (    s2   lib/python2.7/site-packages/astropy/utils/state.pyR   0   s    	c         S   s   d  S(   N(    (   R   (    (    s2   lib/python2.7/site-packages/astropy/utils/state.pyt	   __enter__4   s    c         S   s   |  j  |  j _  d  S(   N(   R   R	   (   R   t   typeR   t   tb(    (    s2   lib/python2.7/site-packages/astropy/utils/state.pyt   __exit__7   s    c         S   s   d j  |  j j |  j j  S(   Ns   <ScienceState {0}: {1!r}>(   t   formatR	   t   __name__R   (   R   (    (    s2   lib/python2.7/site-packages/astropy/utils/state.pyt   __repr__:   s    (   R   t
   __module__R   R   R   R   (    (    (    s2   lib/python2.7/site-packages/astropy/utils/state.pyR   /   s   			(   t   objectR   R   (   R   R   R   t   ctx(    (    s2   lib/python2.7/site-packages/astropy/utils/state.pyt   set*   s
    	c         C   s   | S(   s]   
        Validate the value and convert it to its native type, if
        necessary.
        (    (   R   R   (    (    s2   lib/python2.7/site-packages/astropy/utils/state.pyR   C   s    (   R   R   t   __doc__R   t   classmethodR   R   R   (    (    (    s2   lib/python2.7/site-packages/astropy/utils/state.pyR    
   s
   	N(   R   t   __all__R   R    (    (    (    s2   lib/python2.7/site-packages/astropy/utils/state.pyt   <module>   s   	