o
    Ú­jm  ã                   @   sô   d Z ddlZddlm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 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.é    N)ÚStringIO)Ú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   úM/var/www/html/CropPilot/venv/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_unconfigure4   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 )z›Create a new paste using the bpaste.net service.

    :contents: Paste contents string.
    :returns: URL to the pasted contents, or an error message.
    r   N)Úurlopen)Ú	urlencodeÚ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.requestrB   Úurllib.parserC   r#   r7   ÚdecodeÚOSErrorÚsearchr   )	rA   rL   rB   rC   ÚparamsÚurlÚresponseÚexc_infoÚmr   r   r   r;   E   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__r/   Úior   Útypingr   r   ÚpytestÚ_pytest.configr   r   Ú_pytest.config.argparsingr   Ú_pytest.stashr   Ú_pytest.terminalr	   Úbytesr%   r   Úhookimplr3   r@   r"   r;   rf   r   r   r   r   Ú<module>   s$    
