ó
…¾^Yc           @` s‰   d  Z  d d l m Z m Z m Z d d l Z d d l Z d d l Z d „  Z e j	 d e
 ƒ d „  ƒ Z d „  Z d „  Z d	 „  Z d S(
   sC    submit failure or test session information to a pastebin service. i    (   t   absolute_importt   divisiont   print_functionNc         C` sJ   |  j  d ƒ } | j d d d d d d d d	 d  d
 d d g d d ƒd  S(   Ns   terminal reportings
   --pastebint   metavart   modet   actiont   storet   destt   pastebint   defaultt   choicest   failedt   allt   helps4   send failed|all info to bpaste.net pastebin service.(   t   getgroupt
   _addoptiont   None(   t   parsert   group(    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pastebin.pyt   pytest_addoption	   s
    t   trylastc         ` s…   d d  l  ‰ ˆ  j j d k r ˆ  j j d ƒ } | d  k	 r t j d ƒ ˆ  _ | j	 j
 ‰ ‡  ‡ ‡ f d †  } | | j	 _
 q n  d  S(   Ni    R   t   terminalreporters   w+bc         ` sE   ˆ |  |  ˆ j  j |  ƒ r1 |  j d ƒ }  n  ˆ  j j |  ƒ d  S(   Ns   utf-8(   t   builtint   _istextt   encodet   _pastebinfilet   write(   t   st   kwargs(   t   configt   oldwritet   py(    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pastebin.pyt	   tee_write   s    (   R   t   optionR   t   pluginmanagert	   getpluginR   t   tempfilet   TemporaryFileR   t   _twR   (   R   t   trR    (    (   R   R   R   s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pastebin.pyt   pytest_configure   s    c         C` s”   t  |  d ƒ r |  j j d ƒ |  j j ƒ  } |  j j ƒ  |  ` |  j j d ƒ } | j j d =| j	 d d ƒ t
 | ƒ } | j d | ƒ n  d  S(   NR   i    R   R   t   =s$   Sending information to Paste Services   pastebin session-log: %s
(   t   hasattrR   t   seekt   readt   closeR"   R#   R&   t   __dict__t	   write_sept   create_new_pastet
   write_line(   R   t
   sessionlogR'   t   pastebinurl(    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pastebin.pyt   pytest_unconfigure'   s    c         C` sù   d d l  } t j d k  r4 d d l m } m } n  d d l m } d d l m } i |  d 6t j d d k rw d n d	 d
 6d d 6} d } | | d | | ƒ j d ƒ ƒj	 ƒ  } | j
 d | j d ƒ ƒ } | rí d | | j d ƒ f Sd | Sd S(   s–   
    Creates a new paste using bpaste.net service.

    :contents: paste contents as utf-8 encoded bytes
    :returns: url to the pasted contents
    i    Ni   (   t   urlopent	   urlencode(   R5   (   R6   t   codet   python3t   pythont   lexert   1weekt   expirys   https://bpaste.nett   datat   asciis   href="/raw/(\w+)"s   utf-8s
   %s/show/%si   s   bad response: (   i   i    (   t   ret   syst   version_infot   urllibR5   R6   t   urllib.requestt   urllib.parseR   R,   t   searcht   decodeR   (   t   contentsR?   R5   R6   t   paramst   urlt   responset   m(    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pastebin.pyR0   7   s     
'c         C` s  d d  l  } |  j j j d k r% d  S|  } d | j k r|  j d d ƒ xÆ |  j j d ƒ D]¯ } y | j j j	 d j
 } Wn  t k
 rŸ | j | ƒ } n X| j j |  j d t ƒ} | j | ƒ | j j ƒ  } t | ƒ sé t ‚ t | ƒ } | j d | | f ƒ q] Wn  d  S(   Ni    R   R)   s$   Sending information to Paste Serviceiÿÿÿÿt   stringios	   %s --> %s(   t   _pytest.configR   R!   R   t   statsR/   t   gett   longreprt   reprtracebackt   reprentriest   reprfileloct   AttributeErrort   _getfailureheadlinet   create_terminal_writert   Truet
   toterminalRL   t   getvaluet   lent   AssertionErrorR0   R1   (   R   t   _pytestR'   t   rept   msgt   twR   R3   (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pastebin.pyt   pytest_terminal_summaryS   s"    (   t   __doc__t
   __future__R    R   R   t   pytestR@   R$   R   t   hookimplRW   R(   R4   R0   R`   (    (    (    s0   /tmp/pip-build-hU8Cw8/pytest/_pytest/pastebin.pyt   <module>   s   			