
    [Fi                        d Z ddlm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 dd	lmZ dd
lmZ ddlZ eee             ZdeddfdZ ej(                  d      deddfd       ZdeddfdZdeeef   defdZdeddfdZy)zASubmit failure or test session information to a pastebin service.    )StringION)IO)Union)Config)create_terminal_writer)Parser)StashKey)TerminalReporterparserreturnc           	      Z    | j                  d      }|j                  ddddd ddgd	       y )
Nzterminal reportingz
--pastebinmodestorepastebinfailedallz3Send failed|all info to bpaste.net pastebin service)metavaractiondestdefaultchoiceshelp)getgroup
_addoption)r   groups     b/var/www/html/BankruptcyAI-uat/bankruptcy-ai/venv/lib/python3.12/site-packages/_pytest/pastebin.pypytest_addoptionr      s>    OO01E	5!B      T)trylastconfigc                      j                   j                  dk(  rr j                  j                  d      }|Tt	        j
                  d       j                  t        <   |j                  j                   fd}||j                  _	        y y y )Nr   terminalreporterzw+bc                      | fi | t        | t              r| j                  d      } j                  t           j                  |        y )Nutf-8)
isinstancestrencodestashpastebinfile_keywrite)skwargsr    oldwrites     r   	tee_writez#pytest_configure.<locals>.tee_write-   s@    %f%a%)A-.44Q7r   )
optionr   pluginmanager	getplugintempfileTemporaryFiler(   r)   _twr*   )r    trr.   r-   s   `  @r   pytest_configurer6   !   sv    }}&!!++,>? >-5-C-CE-JFLL)*vv||H8 %BFFL  'r   c                    t         | j                  v r| j                  t            }|j                  d       |j                         }|j	                          | j                  t         = | j
                  j                  d      }|j                  j                  d= |j                  dd       t        |      }|j                  d|z         y y )Nr   r"   r*   =$Sending information to Paste Servicezpastebin session-log: %s
)r)   r(   seekreadcloser0   r1   r4   __dict__	write_sepcreate_new_paste
write_line)r    pastebinfile
sessionlogr5   pastebinurls        r   pytest_unconfigurerD   6   s    6<<'||$45!!&&(
LL)*!!++,>?FFOOG$
S@A&z2
2[@A (r   contentsc                 F   ddl }ddlm} ddlm} | ddd}d}	  || ||      j                  d	      
      j                         j                  d      }|j                  d|      }|r| d|j                  d       S d|z   dz   S # t        $ r}d|z  cY d}~S d}~ww xY w)zCreate a new paste using the bpaste.net service.

    :contents: Paste contents string.
    :returns: URL to the pasted contents, or an error message.
    r   N)	urlencode)urlopentext1week)codelexerexpiryzhttps://bpa.stascii)datar$   zbad response: %szhref="/raw/(\w+)"z/show/   zbad response: invalid format ('z'))reurllib.parserG   urllib.requestrH   r'   r;   decodeOSErrorsearchr   )	rE   rQ   rG   rH   paramsurlresponseexc_infoms	            r   r?   r?   G   s     &&7CF
C-Ci/66w?@EEGNNwW 	
 			&1AfQWWQZL))08;dBB  -!H,,-s   <B 	B BB B r"   c                 0   | j                   j                  j                  dk7  ry d| j                  v r| j	                  dd       | j                  d   D ]  }	 |j
                  j                  j                  d   j                  }t               }t        | j                   |      }|j                  |       |j                         }t        |      sJ t!        |      }| j#                  | d|         y y # t        $ r | j                  |      }Y w xY w)Nr   r8   r9   z --> )r    r/   r   statsr>   longreprreprtracebackreprentriesreprfilelocAttributeError_getfailureheadliner   r   
toterminalgetvaluelenr?   r@   )r"   repmsgfiletwr+   rC   s          r   pytest_terminal_summaryrl   `   s
   %%..(:#)))""3(NO#))(3 	DC@ll00<<R@LL :D'(8(?(?FBNN2Aq6M6*1-K''3%u[M(BC	D *
 " @&::3?@s   -C88DD)__doc__ior   r2   typingr   r   _pytest.configr   r   _pytest.config.argparsingr   _pytest.stashr	   _pytest.terminalr
   pytestbytesr)   r   hookimplr6   rD   r&   r?   rl    r   r   <module>rx      s    G     ! 1 , " -  '8BuI&( 
V 
 
 %V % % %(Bv B$ B"CuS%Z0 CS C2D.> D4 Dr   