
    9[g                        d Z ddlm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Z eee             ZddZ ej*                  d      dd       ZddZddZddZy)zASubmit failure or test session information to a pastebin service.    )annotations)StringION)IO)Config)create_terminal_writer)Parser)StashKey)TerminalReporterc           	     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)parsergroups     K/var/www/html/bid-api/venv/lib/python3.12/site-packages/_pytest/pastebin.pypytest_addoptionr      s>    OO01E	5!B      T)trylastc                     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kwargsconfig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_configurer5   "   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| d       y y )Nr   r    r(   =$Sending information to Paste Servicezpastebin session-log: 
)r'   r&   seekreadcloser/   r0   r3   __dict__	write_sepcreate_new_paste
write_line)r+   pastebinfile
sessionlogr4   pastebinurls        r   pytest_unconfigurerD   7   s    6<<'||$45!!&&(
LL)*!!++,>?FFOOG$
S@A&z2
.{m2>? (r   c                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| 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: zhref="/raw/(\w+)"z/show/   zbad response: invalid format ('z'))reurllib.parserF   urllib.requestrG   r%   r;   decodeOSErrorsearchr   )	contentsrP   rF   rG   paramsurlresponseexc_infoms	            r   r?   r?   H   s     &&7CF
C+Ci/66w?@EEGNNwW 	
 			&1AfQWWQZL))08;dBB  +z**+s   <B 	B BB B 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   r7   r8   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   a   s   %%..(:#)))""3(NO#))(3C@ll00<<R@LL :D'(8(?(?FBNN2Aq6M6*1-K''3%u[M(BC 4 *
 " @&::3?@s   -C88DD)r   r   returnNone)r+   r   rm   rn   )rV   zstr | bytesrm   r$   )r    r
   rm   rn   )__doc__
__future__r   ior   r1   typingr   _pytest.configr   r   _pytest.config.argparsingr   _pytest.stashr	   _pytest.terminalr
   pytestbytesr'   r   hookimplr5   rD   r?   rl    r   r   <module>r{      sr    G "    ! 1 , " -  '8BuI&( 
 % %(@"C2Dr   