U
    `»{jŠ  ã                   @  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œdd„Zejdd�dddœdd„ƒZdddœdd„Zdddœdd„Zdd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)ÚTerminalReporterr   ÚNone)Ú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)ZgetgroupZ
_addoption)r   Úgroup© r   úO/var/www/html/bwave/python/venv/lib/python3.8/site-packages/_pytest/pastebin.pyÚpytest_addoption   s    
ùr   T)Ztrylastr   )Úconfigr   c                   sR   ˆ j jdkrNˆ j d¡}|d k	rNt d¡ˆ jt< |jj	‰‡ ‡fdd„}||j_	d S )Nr   Úterminalreporterzw+bc                   s4   ˆ| f|Ž t | tƒr |  d¡} ˆ jt  | ¡ d S )Núutf-8)Ú
isinstanceÚstrÚencodeÚstashÚpastebinfile_keyÚwrite)ÚsÚkwargs©r   Z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    r0   c                 C  sv   t | jkrr| jt  }| d¡ | ¡ }| ¡  | jt = | j d¡}|jjd= | 	dd¡ t
|ƒ}| d|› d�¡ d S )Nr   r   r$   ú=ú$Sending information to Paste Servicezpastebin session-log: Ú
)r#   r"   ÚseekÚreadÚcloser*   r+   r.   Ú__dict__Ú	write_sepÚcreate_new_pasteÚ
write_line)r   ZpastebinfileZ
sessionlogr/   Úpastebinurlr   r   r   Úpytest_unconfigure7   s    



r<   zstr | bytesr    )Úcontentsr   c           	   
   C  sº   ddl }ddlm} ddlm} | dddœ}d}z$||||ƒ d	¡d
� ¡  d¡}W n0 tk
r„ } zd|› � W Y ¢S d}~X Y nX | 	d|¡}|rª|› d| 
d¡› �S d| d S 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)Ú	urlencode)ÚurlopenÚtextZ1week)ÚcodeÚlexerZexpiryzhttps://bpa.stÚascii)Údatar   zbad response: zhref="/raw/(\w+)"z/show/é   zbad response: invalid format ('z'))ÚreÚurllib.parser>   Úurllib.requestr?   r!   r5   ÚdecodeÚOSErrorÚsearchr   )	r=   rF   r>   r?   ÚparamsÚurlÚresponseÚexc_infoÚmr   r   r   r9   H   s    ÿ r9   r	   )r   r   c              	   C  s¼   | j jjdkrd S d| jkr¸|  dd¡ | jd D ]„}z|jjjd j}W n t	k
rh   |  
|¡}Y nX tƒ }t| j |ƒ}| |¡ | ¡ }t|ƒsšt‚t|ƒ}|  |› d|› �¡ q2d S )Nr   r1   r2   éÿÿÿÿz --> )r   r)   r   Ústatsr8   ZlongreprZreprtracebackZreprentriesZreprfilelocÚAttributeErrorZ_getfailureheadliner   r   Z
toterminalÚgetvalueÚlenÚAssertionErrorr9   r:   )r   ÚrepÚmsgÚfileZtwr%   r;   r   r   r   Úpytest_terminal_summarya   s     

rZ   )Ú__doc__Ú
__future__r   Úior   r,   Útypingr   Z_pytest.configr   r   Z_pytest.config.argparsingr   Z_pytest.stashr   Z_pytest.terminalr	   ZpytestÚbytesr#   r   Zhookimplr0   r<   r9   rZ   r   r   r   r   Ú<module>   s"   
