o
    #if                     @   s   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dZejdddeddfddZdeddfddZdeeef defddZdeddfddZdS )zASubmit failure or test session information to a pastebin service.    )StringION)IO)Union)Config)create_terminal_writer)Parser)StashKey)TerminalReporterparserreturnc              	   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   I/var/www/html/corbot_env/lib/python3.10/site-packages/_pytest/pastebin.pypytest_addoption   s   

r   T)trylastconfigc                    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   r3   c                 C   sv   t | jv r9| jt  }|d | }|  | jt = | jd}|jjd= |	dd t
|}|d|  d S d S )Nr   r   r&   =$Sending information to Paste Servicezpastebin session-log: %s
)r%   r$   seekreadcloser-   r.   r1   __dict__	write_sepcreate_new_paste
write_line)r   pastebinfile
sessionlogr2   pastebinurlr   r   r   pytest_unconfigure6   s   



r@   contentsc           	   
   C   s   ddl }ddlm} ddlm} | ddd}d}z||||d	d
 d}W n ty@ } z
d| W  Y d}~S d}~ww |	d|}|rS| 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)	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.parserB   urllib.requestrC   r#   r7   decodeOSErrorsearchr   )	rA   rL   rB   rC   paramsurlresponseexc_infomr   r   r   r;   G   s    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   r4   r5   z --> )r   r,   r   statsr:   longreprreprtracebackreprentriesreprfilelocAttributeError_getfailureheadliner   r   
toterminalgetvaluelenr;   r<   )r   repmsgfiletwr'   r?   r   r   r   pytest_terminal_summary`   s&   

rf   )__doc__ior   r/   typingr   r   _pytest.configr   r   _pytest.config.argparsingr   _pytest.stashr   _pytest.terminalr	   pytestbytesr%   r   hookimplr3   r@   r"   r;   rf   r   r   r   r   <module>   s$   
