HOME


Mini Shell 1.0
DIR: /snap/core20/current/usr/share/subiquity/subiquitycore/__pycache__/
Upload File :
Current File : //snap/core20/current/usr/share/subiquity/subiquitycore/__pycache__/context.cpython-38.pyc
U

K��^>�@sNddlZddlZddlZddlZGdd�dej�ZGdd�d�Zd	dd�ZdS)
�Nc@s$eZdZe��Ze��Ze��ZdS)�StatusN)�__name__�
__module__�__qualname__�enum�auto�SUCCESS�FAILZWARN�r
r
�-/usr/share/subiquity/subiquitycore/context.pyrsrc@steZdZdZddd�Zedd��Zddd	�Zd
d�Zddd
�Z	de
jfdd�Zdd�Z
dd�Zdd�Zddd�ZdS)�Contexta�Class to report when things start and finish.

    The expected way to use this is something like:

    with somecontext.child("operation"):
        await long_running_operation()

    but you can also call .enter() and .exit() if use as a context
    manager isn't possible.

    start and finish events are reported via the report_start_event and
    report_finish_event methods on app.

    You can override the message shown on exit by passing it to the .exit
    method or by assigning to description:

    with somecontext.child("operation") as context:
        result = await long_running_operation()
        context.description = "result was {}".format(result)
    NcCs:||_||_||_||_||_|dkr*|}||_i|_dS�N)�app�name�description�parent�level�
childlevel�data)�selfrrrrrrr
r
r�__init__1szContext.__init__cCs|||jddd�S)N��INFO)Zproject)�clsrr
r
r�new<szContext.newrcCs&|dkr|j}t|�|j|||||�Sr
)r�typer)rrrrrr
r
r�child@sz
Context.childcCs2|}g}|dk	r$|�|j�|j}qd�t|��S)N�/)�appendrr�join�reversed)r�c�namesr
r
r�	full_nameEszContext.full_namecCs |dkr|j}|j�||�dSr
)rrZreport_start_event)rrr
r
r�enterMsz
Context.entercCs"|dkr|j}|j�|||�dSr
)rrZreport_finish_event)rr�resultr
r
r�exitRszContext.exitcCs|��|Sr
)r$)rr
r
r�	__enter__WszContext.__enter__cCsD|dk	r*tj}t|tj�r d}q4t|�}n
tj}d}|�||�dS)NZ	cancelled)rr	�
isinstance�asyncioZCancelledError�strrr&)r�exc�value�tbr%rr
r
r�__exit__[s
zContext.__exit__cCs||j|<dSr
)r)r�keyr,r
r
r�setgszContext.setcCs,|}|dk	r(||jkr |j|S|j}q|Sr
)rr)rr/�defaultr!r
r
r�getjs

zContext.get)N)rNN)N)N)rrr�__doc__r�classmethodrrr#r$rrr&r'r.r0r2r
r
r
rrs



rrcs���fdd�}|S)Ncsd�dkr�j����fdd��t�����fdd��}t�����fdd��}t���r\|S|SdS)NcsF|�d�}|dkr|j}|jf�jf|��jf|�d����|d<|S)N�context)rr)r2r5r�format)r�kwr5��
context_kwrrr
r�convargsys


��
z0with_context.<locals>.decorate.<locals>.convargsc
s6�||�}|d��|f|�W5QR�SQRXdS�Nr5r
�rr7�r:�methr
r�decorated_sync�s

z6with_context.<locals>.decorate.<locals>.decorated_syncc
�s<�||�}|d� �|f|�IdHW5QR�SQRXdSr;r
r<r=r
r�decorated_async�s

z7with_context.<locals>.decorate.<locals>.decorated_async)r�	functools�wraps�inspectZiscoroutinefunction)r>r?r@r8r=r�decoratets

zwith_context.<locals>.decorater
)rrr9rDr
r8r�with_contextssrE)Nr)r)rrArC�EnumrrrEr
r
r
r�<module>sX