a
    *ñ»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   ú6E:\soccer\ml_env\Lib\site-packages\_pytest/pastebin.pyÚpytest_addoption   s    
ùr   T)Ztrylastr   )Úconfigr   c                   sR   ˆ j jdkrNˆ j d¡}|d urNt d¡ˆ jt< |jj	‰‡ ‡fdd„}||j_	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   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v 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lm} | dddœ}d	}z$||||ƒ d
¡d� ¡  	d¡}W nŒ |y¾ } zF|�& d|› �W  d  ƒ W  Y d}~S 1 s 0    Y  W Y d}~n8d}~0  t
� yì } zd|› �W  Y d}~S d}~0 0 | 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)Ú	HTTPError)Ú	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.errorr>   Úurllib.parser?   Úurllib.requestr@   r!   r5   ÚdecodeÚOSErrorÚsearchr   )
r=   rG   r>   r?   r@   ÚparamsÚurlÚresponseÚeÚmr   r   r   r9   H   s$    ÿH r9   r	   )r   r   c              	   C  sº   | j jjdkrd S d| jv r¶|  dd¡ | jd D ]‚}z|jjjd j}W n t	yf   |  
|¡}Y n0 tƒ }t| j |ƒ}| |¡ | ¡ }t|ƒs˜J ‚t|ƒ}|  |› d|› �¡ q2d S )Nr   r1   r2   éÿÿÿÿz --> )r   r)   r   Ústatsr8   ZlongreprZreprtracebackZreprentriesZreprfilelocÚAttributeErrorZ_getfailureheadliner   r   Z
toterminalÚgetvalueÚlenr9   r:   )r   ÚrepÚmsgÚfileZtwr%   r;   r   r   r   Úpytest_terminal_summarye   s     

r[   )Ú__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   r[   r   r   r   r   Ú<module>   s"   
