o
    tBhT                     @   s~   d dl mZmZ d dlmZ g dZdee dee fddZdedefd	d
Z	dede
fddZddede
defddZdS )    )
CollectionList)maxsize)dedent_block_string_linesis_printable_as_block_stringprint_block_stringlinesreturnc                    s   t  d}d}t| D ]\}}t|}|t|krq
|du r|}|}|r)| k r)| q
|du r0d} fddt| D ||d  S )aA  Produce the value of a block string from its parsed raw value.

    This function works similar to CoffeeScript's block string,
    Python's docstring trim or Ruby's strip_heredoc.

    It implements the GraphQL spec's BlockStringValue() static algorithm.

    Note that this is very similar to Python's inspect.cleandoc() function.
    The difference is that the latter also expands tabs to spaces and
    removes whitespace at the beginning of the first line. Python also has
    textwrap.dedent() which uses a completely different algorithm.

    For internal use only.
    Nr   c                    s$   g | ]\}}|r| d  n|qS )N ).0ilinecommon_indentr   t/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/graphql/language/block_string.py
<listcomp>.   s    z-dedent_block_string_lines.<locals>.<listcomp>   )r   	enumerateleading_white_spacelen)r   first_non_empty_linelast_non_empty_liner   r   indentr   r   r   r      s(   

r   sc                 C   s*   d}| D ]}|dvr|  S |d7 }q|S )Nr    	r   r   )r   r   cr   r   r   r   5   s   
r   valuec                 C   s   t | ts	t| } | sdS d}d}d}d}| D ]*}|dkr+|r$|s$ dS d}d}d}q|dv r4|p2|}q|dkr; dS |o>|}d}q|rFdS |rL|rLdS dS )z_Check whether the given string is printable as a block string.

    For internal use only.
    TF
r   )
isinstancestr)r   is_empty_line
has_indenthas_common_indentseen_non_empty_liner   r   r   r   r   >   s4   

r   Fminimizec                 C   s   t | ts	t| } | dd}| pdg}t|}|dk}|dko.tdd |dd D }|d}| do;| }| d	}	|pD|	}
| oV| pVt| d
kpV|
pV|pV|}|o`| o`| d dv }|re|rg|ridnd}|so|
rqdnd}d| | | dS )a=  Print a block string in the indented block form.

    Prints a block string in the indented block form by adding a leading and
    trailing blank line. However, if a block string starts with whitespace and
    is a single-line, adding a leading blank line would strip that whitespace.

    For internal use only.
    z"""z\""" r   c                 s   s"    | ]}| p|d  dv V  qdS )r   r   Nr   )r   r   r   r   r   	<genexpr>{   s    
z%print_block_string.<locals>.<genexpr>N"\F   r   r   r   )r    r!   replace
splitlinesr   allendswith)r   r&   escaped_valuer   	num_linesis_single_lineforce_leading_new_linehas_trailing_triple_quoteshas_trailing_quotehas_trailing_slashforce_trailing_new_lineprint_as_multiple_linesskip_leading_new_linebeforeafterr   r   r   r   f   sD   
	




r   N)F)typingr   r   sysr   __all__r!   r   intr   boolr   r   r   r   r   r   <module>   s    *	(