o
    Vh                     @  s   d dl mZ d dlZd dl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 er4d dlmZ G d	d
 d
e
ZG dd deZejG dd dZejG dd dZG dd deZdS )    )annotationsN)InitVar)CalledProcessError)TYPE_CHECKING)	CleoError)decode)IOc                   @     e Zd ZdS )PoetryConsoleErrorN__name__
__module____qualname__ r   r   m/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/poetry/console/exceptions.pyr
          r
   c                   @  r	   )GroupNotFoundErrorNr   r   r   r   r   r      r   r   c                   @  sV   e Zd ZU dZded< dZded< eddd	ZdddZdddZ		ddddZ
dS )ConsoleMessagea  
    Representation of a console message, providing utilities for formatting text
    with tags, indentation, and sections.

    The ConsoleMessage class is designed to represent text messages that might be
    displayed in a console or terminal output. It provides features for managing
    formatted text, such as stripping tags, wrapping text with specific tags,
    indenting, and creating structured message sections.
    strtextFbooldebugreturnc                 C  s   ddl m} || jS )Nr   )
strip_tags)cleo._utilsr   r   )selfr   r   r   r   stripped*   s   
zConsoleMessage.strippedtagc                 C  s    | j rd| d| j  d| _ | S )N<>z</>)r   )r   r   r   r   r   wrap0   s   zConsoleMessage.wrapindentc                 C  s6   | j rd| | j   | _ | | j  | _ | S )N
)r   join
splitlinesstrip)r   r!   r   r   r   r!   5   s   zConsoleMessage.indent titlec                 C  sP   | j s| S | j r&|rd| dgng }|| j   d| | | _ | S )Nz<b>z:</>r"   )r   extendr$   r#   r%   )r   r'   r!   sectionr   r   r   make_section;   s   zConsoleMessage.make_sectionNr   r   )r   r   r   r   )r!   r   r   r   )r&   )r'   r   r!   r   r   r   )r   r   r   __doc____annotations__r   propertyr   r    r!   r*   r   r   r   r   r      s   
 


	r   c                   @  s   e Zd ZU dZejddZded< ejddZded< ejddZ	ded< ejddZ
ded< ejddZd	ed
< ejddZded< ejddZded< dddZdS )PrettyCalledProcessErrora  
    Represents a formatted and decorated error object for a subprocess call.

    This class is used to encapsulate information about a `CalledProcessError`,
    providing additional context such as command output, errors, and helpful
    debugging messages. It is particularly useful for wrapping and decorating
    subprocess-related exceptions in a more user-friendly format.

    Attributes:
        message: A string representation of the exception.
        output: A section formatted representation of the exception stdout.
        errors: A section formatted representation of the exception stderr.
        command_message: Formatted message including a hint on retrying the original command.
        command: A `shelex` quoted string representation of the original command.
        exception: The original `CalledProcessError` instance.
        indent: Indent prefix to use for inner content per section.
    F)initr   messageoutputerrorscommand_messager   commandTzInitVar[CalledProcessError]	exceptionr&   )defaultzInitVar[str]r!   r   r   Nonec                 C  s   t t| ddd|| _t t|jddd|| _t t|jddd|| _	t
|jtr7t|jn|j| _t d| j ddd| _d S )	NTr   	ExceptionOutputErrorsz7You can test the failed command by executing:

    <c1>z</c1>F)r   r   r%   r*   r1   r   stdoutr2   stderrr3   
isinstancecmdlistshlexr#   r5   r4   )r   r6   r!   r   r   r   __post_init__g   s"   
z&PrettyCalledProcessError.__post_init__N)r6   r   r!   r   r   r8   )r   r   r   r,   dataclassesfieldr1   r-   r2   r3   r4   r5   r6   r!   rC   r   r   r   r   r/   K   s   
 r/   c                      sh   e Zd ZdZ		d&d' fddZd(ddZ	d)d*ddZd+ddZe		d,d-d d!Z	d.d$d%Z
  ZS )/PoetryRuntimeErrorzG
    Represents a runtime error in the Poetry console application.
    N   reasonr   messageslist[ConsoleMessage] | None	exit_codeintr   r8   c                   s2   t  | || _|pg | _| jdt| d S Nr   )super__init__rK   	_messagesinsertr   )r   rH   rI   rK   	__class__r   r   rO      s   
zPoetryRuntimeError.__init__ior   c                 C  s(   | j | dd }r|| dS dS )za
        Write the error text to the provided IO iff there is any text
        to write.
        F)r   r%   N)get_text
is_verbosewrite_error_line)r   rT   r   r   r   r   write   s   zPoetryRuntimeError.writeFr&   r   r   r!   r%   c                 C  s   d}d}| j D ]-}|jr|sd}q|r|jn|j}|sq|r(d| | }|| | d| d7 }q|rKt| d| d}||rG|jn|j7 }|| dS )z
        Convert the error messages to a formatted string. All empty messages
        are ignored along with debug level messages if `debug` is `False`.
        r&   FTr"   zTYou can also run your <c1>poetry</> command with <c1>-v</> to see more information.
)rP   r   r   r   r#   r$   r   rstrip)r   r   r!   r%   r   has_skipped_debugr1   message_textr   r   r   rU      s$   

zPoetryRuntimeError.get_textc                 C  s   | j d j S rM   )rP   r   r%   )r   r   r   r   __str__   s   zPoetryRuntimeError.__str__r6   %CalledProcessError | Exception | Noneinfolist[str] | str | Nonec                 C  s   t |tr|g}td|pg dddg}t |tr9t|dd}|jd|jd|j	dg||j
}n|durSt |trS|d	tt|d
djddd | ||S )a  
        Create an instance of this class using the provided reason. If
        an exception is provided, this is also injected as a debug
        `ConsoleMessage`.

        There is specific handling for known exception types. For example,
        if exception is of type `subprocess.CalledProcessError`, the following
        sections are additionally added when available - stdout, stderr and
        command for testing.
        r"   Fr9   r^   z    | )r!   warningNr   Tr:   )r?   r   r   r#   r    r   r/   r1   r2   r3   r4   r:   rQ   r*   )clsrH   r6   r^   rI   errorr   r   r   create   s4   





zPoetryRuntimeError.creater1   str | ConsoleMessagec                 C  s"   t |tr	t|}| j| | S )N)r?   r   r   rP   append)r   r1   r   r   r   re      s   
zPoetryRuntimeError.append)NrG   )rH   r   rI   rJ   rK   rL   r   r8   )rT   r   r   r8   )Fr&   F)r   r   r!   r   r%   r   r   r   r+   )NN)rH   r   r6   r]   r^   r_   r   rF   )r1   rd   r   rF   )r   r   r   r,   rO   rX   rU   r\   classmethodrc   re   __classcell__r   r   rR   r   rF   |   s    
	
 -rF   )
__future__r   rD   rB   r   
subprocessr   typingr   cleo.exceptionsr   poetry.utils._compatr   
cleo.io.ior   r
   r   	dataclassr   r/   rF   r   r   r   r   <module>   s"    /0