Ë
    tPêj("  ã                  óè   — d Z ddlmZ ddlZddlmZmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZ dd	lmZmZmZ dd
lmZ ddlmZ ddlmZ  G d„ d«      Z G d„ de«      Z G d„ d«      Z G d„ de«      Zy)z¬
Interfaces for for propagating feedback from the API to provide responsive progress indicators as
well as a progress spinner implementation for use with CLI applications.
é    )ÚannotationsN)ÚABCÚabstractmethod)ÚSequence)ÚMemoryHandler)ÚAny)Ú	StyleType)ÚConsoleÚGroupÚRenderableType)ÚLive)ÚPanel)ÚSpinnerc                  óX   — e Zd ZdZg dœd
d„Zddd„Zdd„Zdd„Zdd„Z	 	 	 	 	 	 	 	 dd	„Z	y)Ú
AuditStateaœ  
    An object that handles abstract "updates" to `pip-audit`'s state.

    Non-UI consumers of `pip-audit` (via `pip_audit`) should have no need for
    this class, and can leave it as a default construction in whatever signatures
    it appears in. Its primary use is internal and UI-specific: it exists solely
    to give the CLI enough state for a responsive progress indicator during
    user requests.
    )Úmembersc               ó   — || _         y)zG
        Create a new `AuditState` with the given member list.
        N)Ú_members)Úselfr   s     úU/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/pip_audit/_state.pyÚ__init__zAuditState.__init__    s   € ð
  ˆ�ó    Nc                óJ   — | j                   D ]  }|j                  ||«       Œ y)z¸
        Called whenever `pip_audit`'s internal state changes in a way that's meaningful to
        expose to a user.

        `message` is the message to present to the user.
        N)r   Úupdate_state)r   ÚmessageÚlogsÚmembers       r   r   zAuditState.update_state'   s'   € ð —m‘mò 	/ˆFØ×Ñ ¨Õ.ñ	/r   c                óF   — | j                   D ]  }|j                  «        Œ y)zB
        Called when `pip-audit`'s state is initializing.
        N)r   Ú
initialize©r   r   s     r   r   zAuditState.initialize2   s#   € ð
 —m‘mò 	 ˆFØ×ÑÕñ	 r   c                óF   — | j                   D ]  }|j                  «        Œ y)zE
        Called when `pip_audit`'s state is "done" changing.
        N)r   Úfinalizer    s     r   r"   zAuditState.finalize:   s!   € ð —m‘mò 	ˆFØ�O‰OÕñ	r   c                ó&   — | j                  «        | S )zb
        Create an instance of the `pip-audit` state for usage within a `with` statement.
        )r   ©r   s    r   Ú	__enter__zAuditState.__enter__A   s   € ð
 	�‰ÔØˆr   c                ó$   — | j                  «        y)z†
        Helper to ensure `finalize` gets called when the `pip-audit` state falls out of scope of a
        `with` statement.
        N)r"   )r   Ú	_exc_typeÚ
_exc_valueÚ_exc_tracebacks       r   Ú__exit__zAuditState.__exit__I   s   € ð 	�‰�r   )r   zSequence[_StateActor]©N©r   Ústrr   ú
str | NoneÚreturnÚNone©r/   r0   )r/   r   )r'   r   r(   r   r)   r   r/   r0   )
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r"   r%   r*   © r   r   r   r      sJ   „ ñð <>õ  ô	/ó óóðØðØ*-ðØ?Bðà	ôr   r   c                  óD   — e Zd Zeddd„«       Zedd„«       Zedd„«       Zy)Ú_StateActorNc                ó   — t         ‚r+   ©ÚNotImplementedError©r   r   r   s      r   r   z_StateActor.update_stateT   s   € ä!Ð!r   c                ó   — t         ‚)z½
        Called when `pip-audit`'s state is initializing. Implementors should
        override this to do nothing if their state management requires no
        initialization step.
        r:   r$   s    r   r   z_StateActor.initializeX   ó
   € ô "Ð!r   c                ó   — t         ‚)zè
        Called when the overlaying `AuditState` is "done," i.e. `pip-audit`'s
        state is done changing. Implementors should override this to do nothing
        if their state management requires no finalization step.
        r:   r$   s    r   r"   z_StateActor.finalizea   r>   r   r+   r,   r1   )r2   r3   r4   r   r   r   r"   r6   r   r   r8   r8   S   s<   „ Øó"ó ð"ð ò"ó ð"ð ò"ó ñ"r   r8   c                  ó~   — e Zd ZdZdZddddddœ	 	 	 	 	 	 	 	 	 	 	 dd	„Zedd
„«       Z	 	 	 	 	 	 dd„Zdd„Z	dd„Z
dd„Zy)Ú	StatusLogzì
    Displays a status indicator with an optional log panel to display logs
    for external processes.

    This code is based off of Rich's `Status` component:
        https://github.com/Textualize/rich/blob/master/rich/status.py
    é
   NÚdotszstatus.spinnerg      ð?g      )@)ÚconsoleÚspinnerÚspinner_styleÚspeedÚrefresh_per_secondc               ó    — t        ||||¬«      | _        t        d| j                  ¬«      | _        t        | j                  ||d¬«      | _        y)a  
        Construct a new `StatusLog`.

        `status` is the status message to display next to the spinner.
        `console` is the Rich console to display the log status in.
        `spinner` is the name of the spinner animation (see python -m rich.spinner). Defaults to `dots`.
        `spinner_style` is the style of the spinner. Defaults to `status.spinner`.
        `speed` is the speed factor for the spinner animation. Defaults to 1.0.
        `refresh_per_second` is the number of refreshes per second. Defaults to 12.5.
        )ÚtextÚstylerG   Ú )ÚheightT)rD   rH   Ú	transientN)r   Ú_spinnerr   ÚLOG_PANEL_HEIGHTÚ
_log_panelr   Ú
renderableÚ_live)r   ÚstatusrD   rE   rF   rG   rH   s          r   r   zStatusLog.__init__y   sG   € ô*   ¨f¸MÐQVÔWˆŒÜ ¨4×+@Ñ+@ÔAˆŒÜØ�O‰OØØ1Øô	
ˆ�
r   c                ó†   — | j                   j                  r t        | j                  | j                   «      S | j                  S )z¼
        Create a Rich renderable type for the log panel.

        If the log panel contains text, we should create a group and place the
        log panel underneath the spinner.
        )rQ   rR   r   rO   r$   s    r   rR   zStatusLog.renderable—   s0   € ð �?‰?×%Ò%Ü˜Ÿ™¨¯©Ó8Ð8Ø�}‰}Ðr   c                ó  — |€d}n-dj                  |j                  «       | j                   d «      }| j                  j	                  |¬«       || j
                  _        | j                  j	                  | j                  d¬«       y)z)
        Update status and logs.
        NrL   ú
)rJ   T)Úrefresh)ÚjoinÚ
splitlinesrP   rO   ÚupdaterQ   rR   rS   )r   rT   r   s      r   r[   zStatusLog.update¤   sr   € ð ˆ<Ø‰Dð —9‘9˜TŸ_™_Ó.°×0EÑ0EÐ/EÐ/GÐHÓIˆDØ�‰×Ñ &ÐÔ)Ø%)ˆ�‰Ô"Ø�
‰
×Ñ˜$Ÿ/™/°4ÐÕ8r   c                ó8   — | j                   j                  «        y)z-
        Start the status animation.
        N)rS   Ústartr$   s    r   r]   zStatusLog.start¶   s   € ð
 	�
‰
×ÑÕr   c                ó8   — | j                   j                  «        y)z-
        Stop the spinner animation.
        N)rS   Ústopr$   s    r   r_   zStatusLog.stop½   s   € ð
 	�
‰
�‰Õr   c                ó   — | j                   S )z4
        Convert to a Rich renderable type.
        )rR   r$   s    r   Ú__rich__zStatusLog.__rich__Ä   s   € ð
 �‰Ðr   )rT   r-   rD   zConsole | NonerE   r-   rF   r	   rG   ÚfloatrH   rb   )r/   r   )rT   r-   r   r.   r/   r0   r1   )r2   r3   r4   r5   rP   r   ÚpropertyrR   r[   r]   r_   ra   r6   r   r   rA   rA   k   s£   „ ñð Ðð #'ØØ#3ØØ$(ñ
àð
ð  ð	
ð
 ð
ð !ð
ð ð
ð "ó
ð< ò
ó ð
ð9àð9ð ð9ð 
ó	9ó$óôr   rA   c                  ó4   — e Zd ZdZddd„Zd	d
d„Zdd„Zdd„Zy)ÚAuditSpinnerzg
    A progress spinner for `pip-audit`, using `rich.status`'s spinner support
    under the hood.
    c                ó°   — t        «       | _        t        || j                  dd¬«      | _        t	        dt
        j                  dd¬«      | _        g | _        y)z0
        Initialize the `AuditSpinner`.
        Úlineé   )rD   rE   rH   r   NF)Ú
flushLevelÚtargetÚflushOnClose)	r
   Ú_consolerA   rO   r   ÚloggingÚERRORÚlog_handlerÚprev_handlers)r   r   s     r   r   zAuditSpinner.__init__Ò   sL   € ô
  ›	ˆŒä!Ø˜TŸ]™]°FÈrô
ˆŒô )Øœ'Ÿ-™-°À5ô
ˆÔð 57ˆÕr   Nc                ó<   — | j                   j                  ||«       y)z-
        Update the spinner's state.
        N)rO   r[   r<   s      r   r   zAuditSpinner.update_stateä   s   € ð
 	�‰×Ñ˜W dÕ+r   c                ó*  — t         j                  }|j                  D ]  }| j                  j	                  |«       Œ | j                  D ]  }|j                  |«       Œ |j                  | j                  «       | j                  j                  «        y)z
        Redirect logging to an in-memory log handler so that it doesn't get mixed in with the
        spinner output.
        N)
rm   ÚrootÚhandlersrp   ÚappendÚremoveHandlerÚ
addHandlerro   rO   r]   )r   Úroot_loggerÚhandlers      r   r   zAuditSpinner.initializeë   s   € ô —l‘lˆØ"×+Ñ+ò 	/ˆGØ×Ñ×%Ñ% gÕ.ð	/à×)Ñ)ò 	/ˆGØ×%Ñ% gÕ.ð	/ð 	×Ñ˜t×/Ñ/Ô0à�‰×ÑÕr   c                óÈ  — | j                   j                  «        t        j                  }t        j                  «       }|j                  t        j                  t        j                  «      «       | j                  j                  |«       | j                  j                  «        |j                  | j                  «       | j                  D ]  }|j                  |«       Œ y)z³
        Cleanup the spinner output so it doesn't get combined with subsequent `stderr` output and
        flush any logs that were recorded while the spinner was active.
        N)rO   r_   rm   rs   ÚStreamHandlerÚsetFormatterÚ	FormatterÚBASIC_FORMATro   Ú	setTargetÚflushrv   rp   rw   )r   rx   Ústream_handlerry   s       r   r"   zAuditSpinner.finalize   s«   € ð 	�‰×ÑÔô —l‘lˆÜ ×.Ñ.Ó0ˆØ×#Ñ#¤G×$5Ñ$5´g×6JÑ6JÓ$KÔLØ×Ñ×"Ñ" >Ô2Ø×Ñ×ÑÔ ð 	×!Ñ! $×"2Ñ"2Ô3Ø×)Ñ)ò 	,ˆGØ×"Ñ" 7Õ+ñ	,r   )rL   )r   r-   r/   r0   r+   r,   r1   )r2   r3   r4   r5   r   r   r   r"   r6   r   r   re   re   Ì   s   „ ñô
7ô$,óô*,r   re   )r5   Ú
__future__r   rm   Úabcr   r   Úcollections.abcr   Úlogging.handlersr   Útypingr   Ú
rich.alignr	   Úrich.consoler
   r   r   Ú	rich.liver   Ú
rich.panelr   Úrich.statusr   r   r8   rA   re   r6   r   r   ú<module>rŒ      sb   ðñõ
 #ã ß #Ý $Ý *Ý å  ß 7Ñ 7Ý Ý Ý ÷;ñ ;ô|"�#ô "÷0^ñ ^ôBF,�;õ F,r   