
    ]g                         S r SSKJr  SSKJr  SSKJr  SSKJrJ	r	  SSK
Jr  SSKJr  \ " S S	5      5       r\" S
5      rS rS rS r\SS j5       rSS jrg)z
NOTE: All classes and functions in this module are considered private and are
subject to abrupt breaking changes. Please do not use them directly.
    )contextmanager)
ContextVar)deepcopy)	dataclassfieldwraps)Setc                   6    \ rS rSr% Sr\" \S9r\\	   \
S'   Srg)ClientContext   z
Encapsulation of objects tracked within the ``_context`` context variable.

``features`` is a set responsible for storing features used during
preparation of an AWS request. ``botocore.useragent.register_feature_id``
is used to add to this set.
)default_factoryfeatures N)__name__
__module____qualname____firstlineno____doc__r   setr   r
   str__annotations____static_attributes__r       2/usr/lib/python3/dist-packages/botocore/context.pyr   r      s     s3Hc#h3r   r   _contextc                  ,    [         R                  S5      $ )z@Get the current ``_context`` context variable if set, else None.N)r   getr   r   r   get_contextr   *   s    <<r   c                 0    [         R                  U 5      nU$ )a  Set the current ``_context`` context variable.

:type ctx: ClientContext
:param ctx: Client context object to set as the current context variable.

:rtype: contextvars.Token
:returns: Token object used to revert the context variable to what it was
    before the corresponding set.
)r   r   )ctxtokens     r   set_contextr#   /   s     LLELr   c                 .    [         R                  U 5        g)zReset the current ``_context`` context variable.

:type token: contextvars.Token
:param token: Token object to reset the context variable.
N)r   reset)r"   s    r   reset_contextr&   =   s     NN5r   Nc              #      #    U =(       d
    [        5       nUc  [        5       nO[        U5      n[        U5      n Sv   [	        U5        g! [	        U5        f = f7f)aO  
Context manager that copies the passed or current context object and sets
it as the current context variable. If no context is found, a new
``ClientContext`` object is created. It mainly ensures the context variable
is reset to the previous value once the executed code returns.

Example usage:

    def my_feature():
        with start_as_current_context():
            register_feature_id('MY_FEATURE')
            pass

:type ctx: ClientContext
:param ctx: The client context object to set as the new context variable.
    If not provided, the current or a new context variable is used.
N)r   r   r   r#   r&   )r!   currentnewr"   s       r   start_as_current_contextr*   F   sK     & "[]GowEees   8AA AAAc                    ^  U 4S jnU$ )a  
Decorator that wraps ``start_as_current_context`` and optionally invokes a
hook within the newly-set context. This is just syntactic sugar to avoid
indenting existing code under the context manager.

Example usage:

    @with_current_context(partial(register_feature_id, 'MY_FEATURE'))
    def my_feature():
        pass

:type hook: callable
:param hook: A callable that will be invoked within the scope of the
    ``start_as_current_context`` context manager.
c                 4   >^  [        T 5      U U4S j5       nU$ )Nc                  z   > [        5          T(       a  T" 5         T" U 0 UD6sS S S 5        $ ! , (       d  f       g = fN)r*   )argskwargsfunchooks     r   wrapper8with_current_context.<locals>.decorator.<locals>.wrapperw   s*    )+FT,V, ,++s   ,
:r   )r1   r3   r2   s   ` r   	decorator'with_current_context.<locals>.decoratorv   s     	t	- 
	- r   r   )r2   r5   s   ` r   with_current_contextr7   e   s    " r   r.   )r   
contextlibr   contextvarsr   copyr   dataclassesr   r   	functoolsr	   typingr
   r   r   r   r#   r&   r*   r7   r   r   r   <module>r>      sk   
 & "  (   	4 	4 	4 j!
  <r   