o
    h;                     @  s   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dZejddd#ddZd#ddZd$ddZd%d d!ZdS )&zASubmit failure or test session information to a pastebin service.    )annotations)StringION)IO)Config)create_terminal_writer)Parser)StashKey)TerminalReporterparserr   returnNonec              	   C  s*   |  d}|jddddd ddgdd	 d S )
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
   group r   Q/var/www/html/openai_agents/venv/lib/python3.10/site-packages/_pytest/pastebin.pypytest_addoption   s   

r   T)trylastconfigr   c                   sZ    j jdkr) jd}|d ur+td jt< |jj	 fdd}||j_	d S d S d S )Nr   terminalreporterzw+bc                   s8   | fi | t | tr| d}  jt |  d S )Nutf-8)
isinstancestrencodestashpastebinfile_keywrite)skwargsr   oldwriter   r   	tee_write.   s   

z#pytest_configure.<locals>.tee_write)
optionr   pluginmanager	getplugintempfileTemporaryFiler%   r&   _twr'   )r   trr,   r   r*   r   pytest_configure"   s   r4   c                 C  sz   t | jv r;| jt  }|d | }|  | jt = | jd}|jjd= |	dd t
|}|d| d d S d S )Nr   r    r'   =$Sending information to Paste Servicezpastebin session-log: 
)r&   r%   seekreadcloser.   r/   r2   __dict__	write_sepcreate_new_paste
write_line)r   pastebinfile
sessionlogr3   pastebinurlr   r   r   pytest_unconfigure7   s   



rB   contentsstr | bytesr#   c           
      C  s  ddl }ddlm} ddlm} ddlm} | ddd}d	}z||||d
d 	d}W nE |y_ } z#| d| W  d   W  Y d}~S 1 sPw   Y  W Y d}~nd}~w t
yu } zd| W  Y d}~S d}~ww |d|}	|	r| d|	d S d| d S )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)	HTTPError)	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.errorrE   urllib.parserF   urllib.requestrG   r$   r9   decodeOSErrorsearchr   )
rC   rP   rE   rF   rG   paramsurlresponseemr   r   r   r=   H   s,   8r=   r    r	   c              	   C  s   | j jjdkr	d S d| jv r[| dd | jd D ]C}z
|jjjd j}W n t	y3   | 
|}Y nw t }t| j |}|| | }t|sLJ t|}| | d|  qd S d S )Nr   r5   r6   z --> )r   r-   r   statsr<   longreprreprtracebackreprentriesreprfilelocAttributeError_getfailureheadliner   r   
toterminalgetvaluelenr=   r>   )r    repmsgfiletwr(   rA   r   r   r   pytest_terminal_summarye   s&   

rk   )r
   r   r   r   )r   r   r   r   )rC   rD   r   r#   )r    r	   r   r   )__doc__
__future__r   ior   r0   typingr   _pytest.configr   r   _pytest.config.argparsingr   _pytest.stashr   _pytest.terminalr	   pytestbytesr&   r   hookimplr4   rB   r=   rk   r   r   r   r   <module>   s$   



