
    gL                        d dl mZ d dlZd dlZ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  G d d	      Zd
 Z G d d      Z eeeeeee ed      eh      ZddZddZy)    )annotationsN)StringIO)Any)Callable)IO)Iteratorc                  "    e Zd ZdZdgZd Zd Zy)	_safe_keyaU  Helper function for key functions when sorting unorderable objects.

    The wrapped-object will fallback to a Py2.x style comparison for
    unorderable types (sorting first comparing the type name and then by
    the obj ids).  Does not work recursively, so dict.items() must have
    _safe_key applied to both the key and the value.

    objc                    || _         y N)r   )selfr   s     G/var/www/openai/venv/lib/python3.12/site-packages/_pytest/_io/pprint.py__init__z_safe_key.__init__)   s	        c                "   	 | j                   |j                   k  S # t        $ rj t        t        | j                               t	        | j                         ft        t        |j                               t	        |j                         fk  cY S w xY wr   )r   	TypeErrorstrtypeid)r   others     r   __lt__z_safe_key.__lt__,   sp    	88eii'' 	TXX'DHH6DO$599:  	s    A0BBN)__name__
__module____qualname____doc__	__slots__r   r    r   r   r
   r
      s     Ir   r
   c                :    t        | d         t        | d         fS )z&Helper function for comparing 2-tuplesr      )r
   )ts    r   _safe_tupler"   6   s    QqT?IadO++r   c                  b   e Zd ZU 	 	 	 d	 	 	 	 	 	 	 ddZd dZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 d!dZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 d!dZi Zded<   	 	 	 	 	 	 	 	 	 	 	 	 	 	 d!dZ	e	ee
j                  <   	 	 	 	 	 	 	 	 	 	 	 	 	 	 d!d	Zeeej                  j                  <   	 	 	 	 	 	 	 	 	 	 	 	 	 	 d!d
Zeeej                  <   	 	 	 	 	 	 	 	 	 	 	 	 	 	 d!dZeeej                  <   	 	 	 	 	 	 	 	 	 	 	 	 	 	 d!dZeeej                  <   eeej                  <   	 	 	 	 	 	 	 	 	 	 	 	 	 	 d!dZeeej                  <   	 	 	 	 	 	 	 	 	 	 	 	 	 	 d!dZeeej                  <   	 	 	 	 	 	 	 	 	 	 	 	 	 	 d!dZeeej                  <   	 	 	 	 	 	 	 	 	 	 	 	 	 	 d!dZeeej<                  j                  <   	 	 	 	 	 	 	 	 	 	 	 	 	 	 d!dZeeej@                  j                  <   	 	 	 	 	 	 	 	 	 	 	 	 	 	 d"dZ!	 	 	 	 	 	 	 	 	 	 	 	 	 	 d"dZ"	 	 	 	 	 	 	 	 	 	 	 	 	 	 d#dZ#d$dZ$	 	 	 	 	 	 	 	 	 	 	 	 	 	 d!dZ%e%eejL                  j                  <   	 	 	 	 	 	 	 	 	 	 	 	 	 	 d!dZ'e'eejP                  j                  <   	 	 	 	 	 	 	 	 	 	 	 	 	 	 d!dZ)e)eejT                  j                  <   	 	 	 	 	 	 	 	 	 	 	 	 	 	 d!dZ+e+eejX                  j                  <   	 	 	 	 	 	 	 	 	 	 	 	 	 	 d!dZ-e-eej\                  j                  <   	 	 	 	 	 	 	 	 	 	 	 	 	 	 d!dZ/e/eej`                  j                  <   	 	 	 	 	 	 	 	 	 	 	 	 	 	 d!dZ1e1eejd                  j                  <   	 	 	 	 	 	 	 	 	 	 d%dZ3y)&PrettyPrinterNc                    |dk  rt        d      ||dk  rt        d      |st        d      || _        || _        || _        y)aT  Handle pretty printing operations onto a stream using a set of
        configured parameters.

        indent
            Number of spaces to indent for each level of nesting.

        width
            Attempted maximum number of columns in the output.

        depth
            The maximum depth to print out nested structures.

        r   zindent must be >= 0Nzdepth must be > 0zwidth must be != 0)
ValueError_depth_indent_per_level_width)r   indentwidthdepths       r   r   zPrettyPrinter.__init__<   sT    & A:233!011122!'r   c                r    t               }| j                  ||ddt               d       |j                         S )Nr   )	_StringIO_formatsetgetvalue)r   objectsios      r   pformatzPrettyPrinter.pformatY   s-    kVS!Qq1||~r   c           
        t        |      }||v r|j                  t        |             y | j                  j	                  t        |      j                  d       }|4|j                  |        || ||||||dz          |j                  |       y t        j                  |      rt        |t
              s|j                  j                  rtt        |j                  d      r^d|j                  j                  j                   v r<|j                  |       | j#                  ||||||dz          |j                  |       y |j                  | j%                  |||             y )Nr    __wrapped____create_fn__)r   write
_recursion	_dispatchgetr   __repr__addremove_dataclassesis_dataclass
isinstance__dataclass_params__reprhasattrr6   r   _pprint_dataclass_repr)	r   r2   streamr*   	allowancecontextlevelobjidps	            r   r/   zPrettyPrinter._format^   s    6
GLLF+,NNtF|44d;=KKdFFFIw	JNN5!%%f-vt,++00 FOO]36??#>#>#K#KKKK""	7EAI NN5!LLFGU;<r   c                L   |j                   j                  }t        j                  |      D cg c]0  }|j                  r"|j
                  t        ||j
                        f2 }	}|j                  |dz          | j                  |	|||||       |j                  d       y c c}w N())		__class__r   r?   fieldsrC   namegetattrr8   _format_namespace_items)
r   r2   rG   r*   rH   rI   rJ   cls_namefitemss
             r   rE   zPrettyPrinter._pprint_dataclass   s     ##,, "((0
0vv VVWVQVV,-0 	 

 	X^$$$UFFIwPUVS
s   5B!z`dict[Callable[..., str], Callable[[PrettyPrinter, Any, IO[str], int, int, set[int], int], None]]r:   c                    |j                   } |d       t        |j                         t              }| j	                  ||||||        |d       y )N{key})r8   sortedrX   r"   _format_dict_items)	r   r2   rG   r*   rH   rI   rJ   r8   rX   s	            r   _pprint_dictzPrettyPrinter._pprint_dict   sE     c
v||~;7vvy'5Qc
r   c                    t        |      s|j                  t        |             y |j                  }|j                  |j                  dz          | j                  ||||||       |j                  d       y rN   )lenr8   rC   rQ   r   r`   )r   r2   rG   r*   rH   rI   rJ   clss           r   _pprint_ordered_dictz"PrettyPrinter._pprint_ordered_dict   sb     6{LLf&S\\C'(&&&)WeLSr   c                t    |j                  d       | j                  ||||||       |j                  d       y )N[]r8   _format_itemsr   r2   rG   r*   rH   rI   rJ   s          r   _pprint_listzPrettyPrinter._pprint_list   4     	S6669guMSr   c                t    |j                  d       | j                  ||||||       |j                  d       y rN   rh   rj   s          r   _pprint_tuplezPrettyPrinter._pprint_tuple   rl   r   c                P   t        |      s|j                  t        |             y |j                  }|t        u r|j                  d       d}n |j                  |j
                  dz          d}t        |t              }| j                  ||||||       |j                  |       y )NrZ   r]   z({z})r[   )	rb   r8   rC   rQ   r0   r   r^   r
   ri   )	r   r2   rG   r*   rH   rI   rJ   typendchars	            r   _pprint_setzPrettyPrinter._pprint_set   s     6{LLf&#:LLGLL,-GI.6669guMWr   c                   |j                   }t        |      s |t        |             y g }|j                  d      }	|dk(  r
|dz  }|dz  }| j                  |z
  x}
}t        |	      D ]  \  }}t        |      }|t        |	      dz
  k(  r|
|z  }
t        |      |
k  r|j                  |       Ht        j                  d|      }|sJ |d   rJ |j                          |}d}t        |      D ]i  \  }}||z   }|t        |      dz
  k(  r|t        |	      dz
  k(  r||z  }t        t        |            |kD  r|r|j                  t        |             |}h|}k |s|j                  t        |              t        |      dk(  r	 |       y |dk(  r |d       t        |      D ]   \  }}|dkD  r |dd	|z  z           ||       " |dk(  r	 |d
       y y )NTr    z\S*\s* rO   r   
 rP   )
r8   rb   rC   
splitlinesr)   	enumerateappendrefindallpop)r   r2   rG   r*   rH   rI   rJ   r8   chunkslines
max_width1	max_widthilinerepparts
max_width2currentjpart	candidates                        r   _pprint_strzPrettyPrinter._pprint_str   s    6{$v,!!$'A:aKFNI!%v!55
Y 'GAtt*CCJN"i'
3x:%c" 

9d3u 9$}		&
(/GAt '$ICJN*qCJN/B"i/
4	?+j8""MM$w-8"&"+  0 MM$w-03 (4 v;!#JA:#J'FAs1udS6\)*#J ( A:#J r   c                   |j                   }t        |      dk  r |t        |             y |dk(  }|r|dz  }|dz  } |d       d}	t        || j                  |z
  |      D ]  }
 ||	        ||
       |	rdd|z  z   }	 |r	 |d       y y )N   r    rO   ru   rv   rw   rP   )r8   rb   rC   _wrap_bytes_reprr)   )r   r2   rG   r*   rH   rI   rJ   r8   parensdelimr   s              r   _pprint_byteszPrettyPrinter._pprint_bytes1  s     v;!$v,!aKFNI#J#FDKK&,@)LC%L#JsV|+	 M
 #J r   c           	         |j                   } |d       | j                  t        |      ||dz   |dz   ||dz           |d       y )Nz
bytearray(
   r    rP   )r8   r   bytes)r   r2   rG   r*   rH   rI   rJ   r8   s           r   _pprint_bytearrayzPrettyPrinter._pprint_bytearrayN  sJ     l&M66B;	AwPQ		
 	c
r   c                    |j                  d       | j                  |j                         |||||       |j                  d       y )Nzmappingproxy(rP   )r8   r/   copyrj   s          r   _pprint_mappingproxyz"PrettyPrinter._pprint_mappingproxy`  s8     	_%V[[]FFIwNSr   c                   t        |      t        j                  u rd}n|j                  j                  }|j
                  j                         }|j                  |dz          | j                  ||||||       |j                  d       y )N	namespacerO   rP   )	r   _typesSimpleNamespacerQ   r   __dict__rX   r8   rU   )	r   r2   rG   r*   rH   rI   rJ   rV   rX   s	            r   _pprint_simplenamespacez%PrettyPrinter._pprint_simplenamespaceo  su     <6111 #H''00H%%'X^$$$UFFIwPUVSr   c           	        |sy |j                   }|| j                  z   }dd|z  z   }	|D ]L  \  }
} ||	        || j                  |
||              |d       | j                  |||d||        |d       N  |dd|z  z          y )Nrv   rw   : r    ,)r8   r(   rF   r/   r   rX   rG   r*   rH   rI   rJ   r8   item_indentdelimnlr\   ents               r   r_   z PrettyPrinter._format_dict_items  s     t555{**HC'N$**S'512$KLLfk1guE#J  	dS6\!"r   c           	     6   |sy |j                   }|| j                  z   }dd|z  z   }	|D ]`  \  }
} ||	        ||
        |d       t        |      |v r	 |d       n%| j                  |||t	        |
      z   dz   d||        |d       b  |dd|z  z          y )Nrv   rw   =...r    r   )r8   r(   r   r/   rb   r   s               r   rU   z%PrettyPrinter._format_namespace_items  s     t555{**HC'N#J#J#w'! e#c(*Q. #J% ( 	dS6\!"r   c           	         |sy |j                   }|| j                  z   }dd|z  z   }	|D ](  }
 ||	       | j                  |
||d||        |d       *  |dd|z  z          y )Nrv   rw   r    r   )r8   r(   r/   )r   rX   rG   r*   rH   rI   rJ   r8   r   r   items              r   ri   zPrettyPrinter._format_items  ss     t555{**D'NLLv{AwF#J 
 	dS6\!"r   c                Z    | j                  ||j                         | j                  |      S r   )
_safe_reprr   r'   )r   r2   rI   rJ   s       r   rF   zPrettyPrinter._repr  s!    vw||~t{{EJJr   c                    | j                  |j                  ||      }|j                  |j                  j                   d| d       | j                  ||||||       |j                  d       y )NrO   , rP   )rF   default_factoryr8   rQ   r   r`   )r   r2   rG   r*   rH   rI   rJ   rdfs           r   _pprint_default_dictz"PrettyPrinter._pprint_default_dict  sf     jj//%@((112!C5;<&&&)WeLSr   c                
   |j                  |j                  j                  dz          |rH|j                  d       |j                         }| j	                  ||||||       |j                  d       |j                  d       y )NrO   rZ   r]   rP   )r8   rQ   r   most_commonr_   )r   r2   rG   r*   rH   rI   rJ   rX   s           r   _pprint_counterzPrettyPrinter._pprint_counter  sn     	V%%..45LL&&(E##E669guULLSr   c                v   t        |j                        r0t        |j                        dk(  r3t        |j                  d         s|j                  t        |             y |j                  |j                  j
                  dz          | j                  |j                  |||||       |j                  d       y )Nr    r   rO   rP   )rb   mapsr8   rC   rQ   r   ri   rj   s          r   _pprint_chain_mapzPrettyPrinter._pprint_chain_map  s     6;;C$4$9#fkkRSnBULLf&V%%..456;;	7ERSr   c                   |j                  |j                  j                  dz          |j                  |j                  d|j                  z         |j                  d       | j	                  ||||dz   ||       |j                  d       y )NrO   zmaxlen=%d, rf   r    z]))r8   rQ   r   maxlenri   rj   s          r   _pprint_dequezPrettyPrinter._pprint_deque  st     	V%%..45==$LL67S6669q='5QTr   c           	     J    | j                  |j                  |||||dz
         y Nr    r/   datarj   s          r   _pprint_user_dictzPrettyPrinter._pprint_user_dict'  "     	V[[&&)WeaiPr   c           	     J    | j                  |j                  |||||dz
         y r   r   rj   s          r   _pprint_user_listzPrettyPrinter._pprint_user_list4  r   r   c           	     J    | j                  |j                  |||||dz
         y r   r   rj   s          r   _pprint_user_stringz!PrettyPrinter._pprint_user_stringA  r   r   c                b   t        |      }|t        v rt        |      S t        |dd       }t	        |t
              r|t
        j                  u r|syt        |      }|r||k\  ry||v rt        |      S |j                  |       g }|j                  }	|dz  }t        |j                         t              D ]:  \  }
}| j                  |
|||      }| j                  ||||      } |	| d|        < |j                  |       dj!                  dj#                  |            S t	        |t$              r|t$        j                  u s"t	        |t&              r|t&        j                  u rt	        |t$              r|sy	d
}nt)        |      dk(  rd}n|syd}t        |      }|r
||k\  r|dz  S ||v rt        |      S |j                  |       g }|j                  }	|dz  }|D ]  }| j                  ||||      } |	|         |j                  |       |dj#                  |      z  S t        |      S )Nr<   z{}z{...}r    r[   r   z{{{}}}r   z[]z[%s]z(%s,)z()z(%s)r   )r   _builtin_scalarsrC   rT   
issubclassdictr<   r   r9   r=   rz   r^   rX   r"   r   r>   formatjoinlisttuplerb   )r   r2   rI   	maxlevelsrJ   rp   rrK   
componentsrz   kvkreprvreprr   ooreprs                    r   r   zPrettyPrinter._safe_reprN  s    6l""<CT*c4 Q$--%7vJEUi/!&))KK$&J&&FQJEv||~;?17IuE7IuE%5'*+ @ NN5!??499Z#899sD!a4==&8sE"qENN':#t$V! vJEUi/~%!&))KKJ&&FQJE7IuEu  NN5!DIIj111F|r   )r   P   N)r*   intr+   r   r,   
int | NonereturnNoner2   r   r   r   )r2   r   rG   IO[str]r*   r   rH   r   rI   set[int]rJ   r   r   r   )rX   zlist[tuple[Any, Any]]rG   r   r*   r   rH   r   rI   r   rJ   r   r   r   )rX   z	list[Any]rG   r   r*   r   rH   r   rI   r   rJ   r   r   r   )r2   r   rI   r   rJ   r   r   r   )
r2   r   rI   r   r   r   rJ   r   r   r   )4r   r   r   r   r4   r/   rE   r:   __annotations__r`   r   r<   rd   _collectionsOrderedDictrk   r   rn   r   rr   r0   	frozensetr   r   r   r   r   	bytearrayr   r   MappingProxyTyper   r   r_   rU   ri   rF   r   defaultdictr   Counterr   ChainMapr   dequer   UserDictr   UserListr   
UserStringr   r   r   r   r$   r$   ;   s_     	  	
 
:
"="= "= 	"=
 "= "= "= 
"=H  	
    
, 	   
  	
    
  ,Idmm  	
    
" 4HIl&&//0  	
    
  ,Idmm  	
    
 !.Ienn  	
    
. *Icll$/Ii  !77 7 	7
 7 7 7 
7r *Icll  	
    
6 !.Ienn  	
    
  %6Ii  !  	
    
 3GIf%%../  	
    
( 2IIf$$--.#$# # 	#
 # # # 
#0##$## ## 	##
 ## ## ## 
##J## # 	#
 # # # 
#.K  	
    
 4HIl&&//0  	
    
& 0?Il""++,  	
    
" 1BIl##,,-  	
    
" .;Il  ))*	Q	Q 	Q 		Q
 	Q 	Q 	Q 
	Q 1BIl##,,-	Q	Q 	Q 		Q
 	Q 	Q 	Q 
	Q 1BIl##,,-	Q	Q 	Q 		Q
 	Q 	Q 	Q 
	Q 3FIl%%../88$,89C8LO8	8r   r$   c                L    dt        |       j                   dt        |        dS )Nz<Recursion on z	 with id=>)r   r   r   )r2   s    r   r9   r9     s&    DL112)BvJ<qIIr   c              #    K   d}t        |       dz  dz  }t        dt        |       d      D ]D  }| ||dz    }||z   }||k(  r||z  }t        t        |            |kD  r|rt        |       |}C|}F |rt        |       y y w)Nr   r   r   )rb   rangerC   )r2   r+   rH   r   lastr   r   r   s           r   r   r     s     Gv;!aD1c&k1%a!a% dN	9YEtI%'7m#GG & 7m s   BBr   )r2   r   r+   r   rH   r   r   zIterator[str]) 
__future__r   collectionsr   dataclassesr?   ior   r.   r{   typesr   typingr   r   r   r   r
   r"   r$   r   r   r   r   floatcomplexboolr   r   r   r9   r   r   r   r   <module>r      sq     # " " $ 	      2,
K	 K	\ %E7D$t*cB 
Jr   