B
    q\                 @   s   d Z dgZG dd dZdS )zj
A simple class to manage a piece of global science state.  See
:ref:`config-developer` for more details.
ScienceStatec               @   s<   e Zd ZdZdd Zedd Zedd Zedd	 Zd
S )r   ab  
    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 )Nz/This class is a singleton.  Do not instantiate.)RuntimeError)self r   2lib/python3.7/site-packages/astropy/utils/state.py__init__   s    zScienceState.__init__c             C   s   |  | jS )z6
        Get the current science state value.
        )validate_value)clsr   r   r   get#   s    zScienceState.getc             C   s.   G dd d}|| | j }| |}|| _ |S )z6
        Set the current science state value.
        c               @   s,   e Zd Zdd Zdd Zdd Zdd Zd	S )
z"ScienceState.set.<locals>._Contextc             S   s   || _ || _d S )N)r   _parent)r   parentvaluer   r   r   r   0   s    z+ScienceState.set.<locals>._Context.__init__c             S   s   d S )Nr   )r   r   r   r   	__enter__4   s    z,ScienceState.set.<locals>._Context.__enter__c             S   s   | j | j_ d S )N)r   r   )r   typer   tbr   r   r   __exit__7   s    z+ScienceState.set.<locals>._Context.__exit__c             S   s   d | jj| jjS )Nz<ScienceState {0}: {1!r}>)formatr   __name__r   )r   r   r   r   __repr__:   s    z+ScienceState.set.<locals>._Context.__repr__N)r   
__module____qualname__r   r   r   r   r   r   r   r   _Context/   s   r   )r   r   )r	   r   r   Zctxr   r   r   set*   s
    
zScienceState.setc             C   s   |S )z]
        Validate the value and convert it to its native type, if
        necessary.
        r   )r	   r   r   r   r   r   C   s    zScienceState.validateN)	r   r   r   __doc__r   classmethodr
   r   r   r   r   r   r   r   
   s
   N)r   __all__r   r   r   r   r   <module>   s   